Cron times for addon overwritten on upgrades

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?
 
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.
 
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.
They won't be reset if you manually create a cron entry without any add-on id.
 
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.
 
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.
 
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.
 
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?
 
Back
Top Bottom