Fixed Add-on upgrade process "Undefined index: version_id"

Xon

Well-known member
Affected version
2.0.1
If you are editing Setup.php, it is possible to completely confuse the StepRunnerUpgradeTrait

The error you get is:
Code:
  [ErrorException]
  [E_NOTICE] Undefined index: version_id

PHP:
foreach ($versions AS $i => $versionId)
{
   if ($versionId >= $stepParams['version_id']) <--- this line.
   {
      $versionSteps = $stepsGrouped[$versionId];
      if (isset($versionSteps[$runStep]))
      {
....
      }

      // if we hit here, then the step couldn't be found, so move onto the next upgrade
      $runStep = 1;
      $stepParams = [];
   }
}


Setting $stepParams to an empty array causes the process to be completely confused.
 
I think this might do the job:
Diff:
Index: src/XF/AddOn/StepRunnerUpgradeTrait.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/XF/AddOn/StepRunnerUpgradeTrait.php    (revision 324b54fd5922fcf3b04388a77d41d179adf72497)
+++ src/XF/AddOn/StepRunnerUpgradeTrait.php    (date 1517400040000)
@@ -14,10 +14,7 @@
      */
     public function upgrade(array $stepParams = [])
     {
-        $stepParams = array_replace([
-            'version_id' => 0,
-            'step' => 0
-        ], $stepParams);
+        $stepParams = $this->getStepParams($stepParams);
 
         $versions = [];
         $stepsGrouped = [];
@@ -76,7 +73,7 @@
 
                 // if we hit here, then the step couldn't be found, so move onto the next upgrade
                 $runStep = 1;
-                $stepParams = [];
+                $stepParams = $this->getStepParams();
             }
         }
 
@@ -84,6 +81,14 @@
         return null;
     }
 
+    protected function getStepParams(array $stepParams = [])
+    {
+        return array_replace([
+            'version_id' => 0,
+            'step' => 0
+        ], $stepParams);
+    }
+
     private function getUpgradeResumeStep()
     {
         $installedAddOn = $this->addOn->getInstalledAddOn();
 
Applied, I'll test that out soon as I've got a couple XF1 => XF2 add-ons which complex installers which need more debugging.
 
Hoping to get 2.0.2 out soon, so if you wouldn't mind running your tests on that ASAP... :)
 
Top Bottom