XF 2.2 Job/Batch Update in Setup.php

mjda

Well-known member
I have an add-on with two different tables (Entities). One is for xf_addon_data and one for xf_addon_data_archive. I'm wanting to move all the records from xf_addon_data_archive to the xf_addon_data table in the Setup.php when I upgrade the add-on. However, I worry about doing a simple foreach because, in my case, there are well over 25,000 records in the archive and I'm worried it could time-out.

I know how to create a Job for that, and I could run it from the Tools->Rebuild caches page, but that doesn't seem like the right way to do it. I think it makes much more sense to do what I'm wanting to do during the upgrade so there isn't an additional step that must be done after the upgrade.

My question is, is there a way to run the Job from Setup.php, or is there a different/better way to do these in batches to prevent it from timing out?
 

Lukas W.

Well-known member
You can queue the job in the postUpgrade method of your add-on and flag it as manual, that way it'll be run as part of the upgrade.

You can also look into a repeatable upgrade step if this is a one-time endeavor. All upgrade steps receive a $stepData object which you can return with information on how far your step has progressed and the installer will repeat running it until completed. The core software uses that to convert table columns from serialized to json.
 

mjda

Well-known member
You can queue the job in the postUpgrade method of your add-on and flag it as manual, that way it'll be run as part of the upgrade.

You can also look into a repeatable upgrade step if this is a one-time endeavor. All upgrade steps receive a $stepData object which you can return with information on how far your step has progressed and the installer will repeat running it until completed. The core software uses that to convert table columns from serialized to json.

Thank you. I'll look into that and see what I can come up with.
 
Top