XF 2.0 "The site is currently being upgraded. Please check back later." when upgrading legacy add-on

Jake B.

Well-known member
When trying to upgrade a legacy add-on to an XF2 version of that add-on I get the following message:

"The site is currently being upgraded. Please check back later."

Which no longer shows up if I navigate to any other page, but attempting to resume my upgrade shows that message again. Nothing too crazy going on in my upgrade script, the only slightly different thing that could possibly cause the issue that I can think of is:

Code:
public function upgrade2000000Step5(array $stepParams)
{
    $stepParams = array_replace([
        'position' => 0,
    ], $stepParams);

    $perPage = 1;
    $db = $this->db();
    $startTime = microtime(true);
    $maxRunTime = $this->app->config('jobMaxRunTime');

    $donationIds = $db->fetchAllColumn($db->limit('
        SELECT donation_id FROM addm_donation
        WHERE donation_id > ?
        ORDER BY donation_id
        ', $perPage), $stepParams['position']);

    if (!$donationIds) {
        return true;
    }

    foreach ($donationIds as $donationId) {
        $stepParams['position'] = $donationId;

        if ($maxRunTime && microtime(true) - $startTime > $maxRunTime) {
            break;
        }

        $legacyDonation = $db->fetchRow('
            SELECT *
            FROM addm_donation
            WHERE donation_id = ?
            ', $donationId);
        if (!$legacyDonation) {
            continue;
        }

        $donation = \XF::em()->create('ThemeHouse\Donate:Donation');
        $donation->forceSet('donation_id', $legacyDonation['donation_id']);
        $donation->bulkSet([
            'user_id' => $legacyDonation['user_id'],
            'donation_date' => $legacyDonation['dateline'],
            'amount' => $legacyDonation['amount'],
            'message' => $legacyDonation['note'],
        ]);
        $donation->save();
    }

    return $stepParams;
}
 
PHP:
$donation->forceSet('donation_id', $legacyDonation['donation_id']);
Have you added this method to your Entity class? That's not a built in method.

You can confirm the last pending action by looking in the xf_addon table in the last_pending_action field.

upgrade:<version>:<step>
 
Have you added this method to your Entity class? That's not a built in method.

No, didn't get an error from that running either, but I did get an error before saying that campaign_id (on a previous step) was read-only and had to be set with forceSet (don't recall the exact error, but something along those lines). Will have to give it another try in a bit when I get to my macbook
 
That error means:
Code:
$donation->set('donation_id', $legacyDonation['donation_id'], ['forceSet' => true]);
However in the code you pasted above, I'm not certain it would be required there.

It would only needed if you need to set a value on an entity after preSave() has already been called.
 
That error means:
Code:
$donation->set('donation_id', $legacyDonation['donation_id'], ['forceSet' => true]);
However in the code you pasted above, I'm not certain it would be required there.

It would only needed if you need to set a value on an entity after preSave() has already been called.

Ah, that's probably the issue then. Didn't get anything in my error log so wasn't entirely sure what was causing it. Will give that a try, thanks!
 
Reverted that forceSet back into the bulkSet and this was the error that I got:

Code:
InvalidArgumentException: Column 'campaign_id' is read only, can only be set with forceSet in src/XF/Mvc/Entity/Entity.php at line 547

[LIST=1]
[*]XF\Mvc\Entity\Entity->set() in src/XF/Mvc/Entity/Entity.php at line 671
[*]XF\Mvc\Entity\Entity->bulkSet() in src/addons/ThemeHouse/Donate/Setup.php at line 127
[*]ThemeHouse\Donate\Setup->upgrade2000000Step4() in src/XF/AddOn/StepRunnerUpgradeTrait.php at line 117
[*]ThemeHouse\Donate\Setup->upgradeStepRunner() in src/XF/AddOn/StepRunnerUpgradeTrait.php at line 74
[*]ThemeHouse\Donate\Setup->upgrade() in src/XF/Admin/Controller/AddOn.php at line 427
[*]XF\Admin\Controller\AddOn->actionUpgrade() in src/XF/Mvc/Dispatcher.php at line 249
[*]XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 88
[*]XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 41
[*]XF\Mvc\Dispatcher->run() in src/XF/App.php at line 1831
[*]XF\App->run() in src/XF.php at line 328
[*]XF::runApp() in admin.php at line 13
[/LIST]

This is the relevant block of code:

PHP:
public function upgrade2000000Step4()
{
    $db = $this->db();
    $campaigns = $db->fetchAll('SELECT * FROM addm_campaign');

    foreach ($campaigns as $legacyCampaign) {
        $campaign = \XF::em()->create('ThemeHouse\Donate:Campaign');
        $campaign->bulkSet([
            'campaign_id' => $legacyCampaign['campaign_id'],
            'title' => $legacyCampaign['title'],
            'description' => $legacyCampaign['description'],
            'display_order' => $legacyCampaign['display_order'],
            'milestone_id' => $legacyCampaign['milestone_id'],
            'active' => 0,
            'currency' => 'usd',
            'goal' => $legacyCampaign['goal'],
            'min_donation' => $legacyCampaign['min_donation'],
            'start_date' => $legacyCampaign['start_date'],
            'end_date' => $legacyCampaign['end_date'],
            'total_progress' => $legacyCampaign['total_progress'],
        ]);
        $campaign->save();
    }
}

preSave hasn't been called here. There is a previous step that works fine which is nearly identical as well for upgrading milestones
 
Auto-increment columns are considered read only through entities as you should very rarely be setting them directly. This would be one instance where you do need it and thus forceSet should be used.
 
I'm assuming the campaign_id is auto increment? That's the same as readOnly in entities.

You'll want to use $campaign->set($col, $value, ['forceSet' => true]).

Liam
 
Top Bottom