1.4.3 upgrade conflict with XenForo_Model_UserUpgrade

Andy.N

Well-known member
I got this error after upgrading to 1.4.3 this morning
ErrorException: Declaration of ExtendUserUpgrade_UserUpgradeModel::downgradeUserUpgrades() should be compatible with XenForo_Model_UserUpgrade::downgradeUserUpgrades(array $upgrades, $sendAlert = true) -library/ExtendUserUpgrade/UserUpgradeModel.php:0

I posted this on @Jake Bunce addon page
Run query on user upgrade (code example)

But pending his reply, this has affected my paying customers so I'm trying to see if I can do anything in the meantime. It looks like in version 1.4.3 there is some syntax change

Here is my library/ExtendUserUpgrade/UserUpgradeModel.php
Code:
<?php

class ExtendUserUpgrade_UserUpgradeModel extends XFCP_ExtendUserUpgrade_UserUpgradeModel
{
        public function upgradeUser($userId, array $upgrade, $allowInsertUnpurchasable = false, $endDate = null)
        {
                $retval = parent::upgradeUser($userId, $upgrade, $allowInsertUnpurchasable, $endDate);

                $db = XenForo_Application::get('db');

        if ($upgrade['user_upgrade_id'] == 2)
        {
        $db->query("
        INSERT INTO xf_qntta_relation (ta_user_id, student_user_id)
        VALUES (2486, " . $userId . ")
                 ");
        }
        else if ($upgrade['user_upgrade_id'] == 3)
        {
        $startDate = $db->fetchOne("
        SELECT FROM_UNIXTIME(min(start_date),'%c/%e/%Y')
        FROM xf_user_upgrade_active
        WHERE user_id = " . $userId . "
        ");

        $db->query("
        UPDATE xf_qntta_relation
        SET note = concat('Extension. Original start date is ','" . $startDate . "','\n', note)
       WHERE student_user_id = " . $userId . "
                   ");

        $db->query("
        UPDATE xf_user_upgrade_active
        SET start_date = start_date + 28*86400
        WHERE user_id = " . $userId . "
        AND user_upgrade_id = 2
           ");

        }

                return $retval;
   }

public function downgradeUserUpgrades(array $upgrades)
     {
              parent::downgradeUserUpgrades($upgrades);
              $db = XenForo_Application::get('db');
              if (!$upgrades)
              {
                        return;
                }
        foreach ($upgrades as $id)
    {
               if ($id['user_upgrade_id'] == 2)
              {
                      $db->query("
                      DELETE FROM xf_qntta_relation
                      WHERE ta_user_id = 2486
 AND student_user_id = $id[user_id]
                       ");
                 }
     }
}


}

Really appreciate any help.
 
I changed the signature of the function from
Code:
public function downgradeUserUpgrades(array $upgrades)
{
parent::downgradeUserUpgrades($upgrades);
to
Code:
public function downgradeUserUpgrades(array $upgrades, $sendAlert = true)
{
parent::downgradeUserUpgrades($upgrades, $sendAlert = true);

Not sure if this is the correct way to fix it.
 
  • Like
Reactions: LPH
Well yes this is actually the correct way to do this. Since the function definition changed in XF 1.4.3, you will be required to change the definition of the overriding function so the proxy class can call them properly.
 
Top Bottom