1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Cron times for addon overwritten on upgrades

Discussion in 'XenForo Development Discussions' started by SneakyDave, Feb 3, 2016.

Tags:
  1. SneakyDave

    SneakyDave Well-Known Member

    I have a forum backup addon that backs up the database and code base at different times set (loosely) by the time that the cron task runs via deferred.php

    Users of the addon set the time the crons should run based on what their forum requires, but on every upgrade of the addon, the cron times get recent to the default.

    Is the best way to fix this to use an installation/upgrade scrip to save the run_rules from the xf_cron_entry table cron times for the addon's tasks, and restore them, somehow?

    Or is that not possible, or is there a better way?
     
  2. batpool52!

    batpool52! Well-Known Member

    Manually create cron entry on add-on installation?
     
  3. SneakyDave

    SneakyDave Well-Known Member

    The cron entries are created as part of the addon, but when the addon is upgraded later, the times that the crons run are reset to their initial default values. That's the issue here.

    I suppose I could add options to the addon itself for what times to run the cron tasks, rather than rely on the user to update the cron tasks themselves, but that would still require updating the run_rules when the addon was upgraded via the code. That seems like a messy solution.
     
  4. batpool52!

    batpool52! Well-Known Member

    They won't be reset if you manually create a cron entry without any add-on id.
     
    SneakyDave likes this.
  5. SneakyDave

    SneakyDave Well-Known Member

    Yeah, I guess that is an option, but most users of this addon probably wouldn't want to do that (enable debug mode(?), create new cron tasks for the backups).

    It could be an solution, but I wouldn't want to implement it in future versions of the addon, because the existing cron tasks assigned to the addon would be removed.
     
  6. Chris D

    Chris D XenForo Developer Staff Member

    I think what batpool means is you could insert the cron entry for them via the database, instead of via the XML file in your installer. As long as it isn't assigned to an add-on, it can't be affected by upgrades. Do make sure it is part of your uninstall routine to remove it, though.
     
    batpool52! and SneakyDave like this.
  7. SneakyDave

    SneakyDave Well-Known Member

    Ah, ok, yes, that would work, thanks for the clarification. So, in the future version of the addon, remove the existing cron tasks assigned to the addon, and create the same ones in the xf_cron_entry table without an addon_id. And add the removal of those cron entries when the addon is uninstalled.

    Thanks guys.
     
  8. SneakyDave

    SneakyDave Well-Known Member

    So back to this, after doing some investigation, this isn't too difficult, but the only thing I'll have to do is when I insert the new cron entries (midnight being strtotime("0:00",time()); I think), I'll have to compute the next_run time to insert into the table.

    I assume that next_run time is normally updated when cron tasks are created, and after they run?
     

Share This Page