• May
  • 27th
  • 2008

WP-o-Matic : Cron job done! but no campaigns processed

Posted by MaEl in: Bits-and-Bytes Comments (37)


After struggling to make cron job work properly, now it doesn’t process the campaigns. It processes the campaigns only if the campaign is new. For the 2nd time, it doesn’t worked. the campaigns status in dashboard still showing next! even if I manually access the secret WP-o-Matic cron url. Browsing the source code and I found out that there are several bugs in the wpomatic.php. The process stucked at getCampaigns function.


function getCampaigns($args = '')
{
global $wpdb;
extract(WPOTools::getQueryArgs($args, array('fields' => '*',
'search' => '',
'orderby' => 'created_on',
'ordertype' => 'DESC',
'where' => '',
'unparsed' => false,
'limit' => null)));
if(! empty($search))
$where .= " AND title LIKE '%{$search}%' ";
if($unparsed)
$where .= " AND active = 1 AND (frequency + lastactive) < ". current_time('timestamp', true) . " ";
$sql = "SELECT $fields FROM `{$this->db['campaign']}` WHERE 1 = 1 $where "
. "ORDER BY $orderby $ordertype $limit";
return $wpdb->get_results($sql);
}

And that tell me why it does work for the first time only. The data for ‘lastactive’ is in ’2008-05-27 01:00:00′ format while the ‘frequency’ is in second. We need to use UNIX_TIMESTAMP to convert the ‘lastactive’ to second. So, that the math can work.

Now that the cron work but it always processed the campaign.. like avoiding the ‘frequency’ value. Again, I checked the data in ‘lastactive’ and I found out that it was the GMT time. Subtract the GMT value should do it.

Here’s the final codes

replace
if($unparsed)
$where .= " AND active = 1 AND (frequency + lastactive) < ". current_time('timestamp', true) . " ";

with

if($unparsed)
$where .= " AND active = 1 AND (frequency + UNIX_TIMESTAMP(lastactive)) < ". (current_time('timestamp',1) - ($gmt ? 0 : (get_option('gmt_offset') * 3600))) . " ";

Now, Cron work nicely!


Updated June 02, 2008
This is unofficial fix!! modify at your own risk
please visit http://devthought.com/wp-o-matic-the-wordpress-rss-agreggator/ or http://wpomatic.lighthouseapp.com

« Clarkconnect DynDNS,EveryDNS updater | WP-Geo resetting image stylesheet »


37 Responses to “WP-o-Matic : Cron job done! but no campaigns processed”

  1. Wi3 Web Resource » Blog Archive » wordpress wp-o-matic feeds not fetching Says:

    [...] error I looked to wpomatic code but never came to conclusion. and search google accordingly, found pixca.net post describing it in detail and sorting the [...]

  2. Rahul Says:

    Great Post Problem Solve nice work men

    thx

  3. TOCS Says:

    thanks I’m having the same problem I’ll give this a try :)

  4. karenm Says:

    Users should know this then causes process frequency to be delayed by the offset.

  5. MaEl Says:

    frequency delayed by the offset?? I’ve verified the mysql data for my WP-o-Matic installation (WordPress 2.5.1 & WP-o-Matic 1.0RC3-7) and the date is in GMT value. Try check the mysql data

  6. Anonymous Says:

    Thanks for the code. I had the same problem as you, works fine now!!! Excellent job. Thank you

  7. Eric S. Says:

    Thank you, this is what I was looking for!

  8. Jenna Says:

    A glorious patch – thank you so much!!!

  9. Aski Says:

    Hi,
    Is the patch the same for every timezone? Or should it be adapted if your in GMT +2 hours?

  10. jason Says:

    IT WORKED!!!!!

  11. jason Says:

    oh and if you are having problems with wpomatic and firefox 3… and adding campaigns..
    usually it will say cannot parse rss feed..
    what i had to do is clear my cache after adding a each new rss feed, copy the rss url and then wait a minute. then save the campaign. dont know why but that works. took me 5 hours to find that out on my own lol

  12. Sherwin Says:

    Thanks for the fix. Meanwhile, for those in Dreamhost: have you gotten image-caching to work? Thought I’d ask just in case someone is w/ them as well.

  13. Bart Schipper Says:

    To fix the time that is displayed in the Dashboard for the Next Campaigns to process, change lines 164-165 in wpomatic.php from:

    $cl = $this->getCampaignRemaining($campaign);

    to:

    $cl = $this->getCampaignRemaining($campaign, get_option('gmt_offset'));

    This calculated time is not actually used by the code that processes the campaigns.

    To correctly display the crontab code, change line 34 in inc/admin/home.php from:

    # Cron command / url
    $this->cron_command = attribute_escape('*/20 * * * * '. $this->getCommand() . ' ' . dirname(__FILE__) . '/cron.php?code=' . get_option('wpo_croncode'));

    to:

    # Cron command / url
    $this->cron_command = attribute_escape('*/20 * * * * '. $this->getCommand() . ' ' . $this->pluginpath . '/cron.php?code=' . get_option('wpo_croncode'));

  14. Jason Says:

    Thanks so much for the fix! The cron job not working was driving me crazy.

  15. Michael Says:

    Didn’t work here. I mean, there’s the server time, the time configured on wp, the local time, the local settings (for non English) time format… it’s a pain in the ass.

    Can you please tell me all your date formats and settings?!

    Thanks

  16. Michael Says:

    Why not just forget this time calculations, GMT and offsets nightmares and just fetch the damn feeds everytime the cron is called?!

  17. Michael Says:

    Any clue on where should I look next in order to try to fix it?

    Strange thing is that althought I put 0 d 0 h 10 min frequency, I always get a 7h waiting time to process the campain. Something is very wrong with my time settings.

    Could it be the non english version of wp?!

  18. Michael Says:

    I know what my problem is. My server is in USA and I’m in Europe. There’s a huge 7 hours gap between what current_time wp function gives for current time and my actual current time!

  19. Michael Says:

    There’s only one way I could put it to work:

    Instead of:

    - ($gmt ? 0 : (get_option(‘gmt_offset’) * 3600))

    I used:

    + (7 * 3600)

  20. TJ Says:

    For those confused by the instructions given by Bart Schipper above, he made a typo error.

    “To fix the time that is displayed in the Dashboard for the Next Campaigns to process, change lines 164-165 in wpomatic.php”

    should be “change line 34 in inc/admin/home.php”

    And …

    “To correctly display the crontab code, change line 34 in inc/admin/home.php from:”

    should be “change lines 164-165 in wpomatic.php”

    I also found that the crontab code in my wp-o-matic 1.0RC3-7 wpomatic.php was already amended to include Bart’s changes above.

  21. Hal Says:

    That’s funny- I had to modiy two instances of 1.0RC3-7 as above to make them work. However, an instance of 1.0RC4-6 which came modified almost identically does NOT work!- same problem- CRON apparently runs but nothing processed.
    Any ideas??

  22. Problemas con el plugin wp-o-matic | Ivan Gadea punto com Says:

    [...] del módulo wpomatic.php, se genera una llamada a SQL que es incorrecta según varios programadores (lo [...]

  23. Gary Says:

    Will give it a try. Thanks for the code!

  24. vertito Says:

    it worked like a charm!

  25. Panwar Says:

    Your patch is nice, Thanks
    I am newbie with cone jobs and i want that cron run everyday 12:00 pm daily, plz give an exaple command so i understand what to put in cpanel cron jobs commands, bcoz i dont understand wp-o-matic given command .

  26. MaEl Says:

    Haven’t using cpanel for a while now. Put this code in your cron (maybe in advance mode)


    0 12 * * * /usr/bin/curl http://YOUR_DOMAIN_NAME.com/wp-content/plugins/wp-o-matic/cron.php?code=xxxxx

    run at 12.00PM daily
    xxxxx is the secret code that wp-o-matic gave you. Hope that helps

  27. ThEmAsTeR Says:

    In wpomatic.php I changed line 447

    $campaigns = $this->getCampaigns(‘unparsed=1′);

    to this

    $campaigns = $this->getCampaigns();

    Cronjob work fine now.

  28. WP-o-Matic Upgrade Fix | kieran barnes | kieranbarnes Says:

    [...] MaEl reports that the lastactive columb is in timestamp format, whilst the frequency column is in seconds, you need to convert the lastactive date to be UNIX_TIMESTAMP to get the maths to work correctly. What, didn’t you spot that yourself? [...]

  29. olimpiyatreklam Says:

    thanks…

  30. serigrafi Says:

    thanks…

  31. aimar Says:

    problems wordpress 2.6.5 / wp-o-matic 1.0RC4-6 no procesa campañas help

  32. SlackeR Says:

    I have the same problem with aimar. the cron runs fine in RC4.6 but does not process any posts

    I did this solution

    In wpomatic.php I changed line 447

    $campaigns = $this->getCampaigns(’unparsed=1′);

    to this

    $campaigns = $this->getCampaigns();

    Cronjob work fine now.

    but it slows down my website to a halt

  33. Damon Says:

    Friends
    I’m have the same problem of the original poster. I’m running
    WordPress 2.7 and 1.0RC4-6 and I tried to use the fix posted but no luck with the automatic fetching and when i try a manual fetch that doesn’t work. any have any suggestions?

  34. Estevao Says:

    i have the same problem. i checked the file and it was ok like you sugest to change… any suggestions? how can i check if the cron job is done or working?

  35. Brent Kerlin Says:

    WP-o-Matic is AWESOME for syndication! Glad you invest your time in it!

    I’m running WordPress 2.7 and 1.0RC4-6. I have tried every fix I can find and the cron job won’t work. Doing a manual fetch works fine however.

  36. Miksa Says:

    I was checking today the new version with this update included, but cron is still not working.
    Which is the best time settings to do each cron job?

  37. Fight Music Says:

    I’m having some issues with this plugin. I have some 100 campaigns set up, and the cron job added, but only 80 campaigns seem to be processed…. Any idea why?

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>