phpyii2craftcms

craft cms command line update to version 3.5.12.1 or greater fails


I am running the following command to update craft cms:

php craft update craft

However upgrading to version 3.5.12.1 or greater fails with the following error:

Performing update with Composer ... done
Applying new migrations ... error: The command "'/var/www/craft' 'migrate/all' '--no-content'" failed.

Exit Code: 1(General error)

Working directory: /var/www

Output:
================


Error Output:
================
Error: array_merge(): Expected parameter 2 to be an array, null given


Output:

The current version of craft that I am running is 3.3.19, and it's running in a docker, using the following composer.json:

. . .
 "require": {
    "aelvan/craft-cp-element-count": "^v1.0.1",
    "aelvan/imager": "v2.3.0",
    "aelvan/inlin": "^2.1",
    "aelvan/preparse-field": "v1.1.0",
    "am-impact/amcommand": "^3.1.4",
    "angellco/portal": "1.1.3",
    "angellco/spoon": "3.3.7",
    "charliedev/element-map": "^1.2",
    "charliedev/section-field": "^1.1.0",
    "craftcms/aws-s3": "1.2.5",
    "craftcms/cms": "3.3.19",
    "craftcms/feed-me": "4.1.2",
    "craftcms/redactor": "2.4.0",
    "doublesecretagency/craft-inventory": "2.0.3",
    "doublesecretagency/craft-siteswitcher": "2.1.0",
    "ether/logs": "^3.0.3",
    "ether/sidebarentrytypes": "^1.0",
    "fruitstudios/linkit": "1.1.11",
    "hashtagerrors/user-initials-photo": "1.1.1",
    "lukeyouell/craft-queue-manager": "^1.1.0",
    "marionnewlevant/snitch": "3.0.0",
    "misterbk/mix": "^1.5",
    "mmikkel/child-me": "1.0.6",
    "mmikkel/cp-field-inspect": "1.0.7",
    "mmikkel/incognito-field": "1.1.1.1",
    "monachilada/craft-matrixtoolbar": "^1.0.6",
    "nfourtythree/entriessubset": "1.2.2",
    "nystudio107/craft-cookies": "^1.1",
    "nystudio107/craft-emptycoalesce": "1.0.6",
    "nystudio107/craft-imageoptimize": "1.6.4",
    "nystudio107/craft-minify": "^1.2.9",
    "nystudio107/craft-retour": "3.1.27",
    "nystudio107/craft-scripts": "^1.2.4",
    "nystudio107/craft-seomatic": "3.2.32",
    "nystudio107/craft-typogrify": "1.1.18",
    "nystudio107/craft-webperf": "1.0.14",
    "ostark/craft-async-queue": "2.0.0",
    "page-8/craft-manytomany": "1.0.2.2",
    "putyourlightson/craft-blitz": "2.3.4",
    "rias/craft-position-fieldtype": "^1.0.13",
    "rias/craft-width-fieldtype": "^1.0",
    "spicyweb/craft-embedded-assets": "2.1.1.1",
    "spicyweb/craft-fieldlabels": "1.1.7",
    "spicyweb/craft-neo": "2.5.7",
    "superbig/craft-entry-instructions": "1.0.6",
    "topshelfcraft/environment-label": "^3.1.5",
    "verbb/cp-nav": "^2.0.9",
    "verbb/default-dashboard": "^1.0",
    "verbb/expanded-singles": "^1.0.4",
    "verbb/field-manager": "2.1.0",
    "verbb/icon-picker": "1.0.10",
    "verbb/image-resizer": "2.0.6",
    "verbb/super-table": "2.3.0",
    "vlucas/phpdotenv": "^2.4.0",
    "wbrowar/craft-communicator": "^1.0",
    "wbrowar/guide": "2.1.2",
    "yiisoft/yii2-redis": "^2.0"
  },
  "repositories": {
    "element-map": {
      "type": "path",
      "url": "./plugins/element-map"
    }
  },
  "autoload": {
    "psr-4": {
      "modules\\utilitiesmodule\\": "modules/utilitiesmodule/src/",
      "putyourlightson\\blitz\\drivers\\storage\\": "plugins/blitz-override"
    }
  },
  "config": {
    "optimize-autoloader": true,
    "config": {
      "process-timeout": 0
    },
    "platform": {
      "php": "7.2.5"
    },
    "sort-packages": true
  },
  "scripts": {
    "post-update-cmd": [
      "./craft migrate/all",
      "./craft clear-caches/all"
    ],
    "post-install-cmd": [
      "./craft migrate/all",
      "./craft clear-caches/all"
    ]
  }
}

I have tried disabling plugins but that seems to make no difference. Also, I am not sure where the "'/var/www/craft' 'migrate/all' '--no-content'" command is even coming from since that seems to be slightly different command than what is in the composer.json.

When I try to run just the migration:

./craft migrate/all

I get the following stack trace:

PHP Warning 'yii\base\ErrorException' with message 'array_merge(): Expected parameter 2 to be an array, null given'

in /var/www/vendor/yiisoft/yii2/web/UrlManager.php:222
Stack trace:
#0 [internal function]: yii\base\ErrorHandler->handleError()
#1 /var/www/vendor/yiisoft/yii2/web/UrlManager.php(222): array_merge()
#2 /var/www/vendor/yiisoft/yii2-debug/src/Module.php(290): yii\web\UrlManager->addRules()
#3 /var/www/vendor/yiisoft/yii2/base/Application.php(333): yii\debug\Module->bootstrap()
#4 /var/www/vendor/craftcms/cms/src/console/Application.php(61): yii\base\Application->bootstrap()
#5 /var/www/vendor/yiisoft/yii2/base/Application.php(279): craft\console\Application->bootstrap()
#6 /var/www/vendor/yiisoft/yii2/console/Application.php(125): yii\base\Application->init()
#7 /var/www/vendor/craftcms/cms/src/console/Application.php(47): yii\console\Application->init()
#8 /var/www/vendor/yiisoft/yii2/base/BaseObject.php(109): craft\console\Application->init()
#9 /var/www/vendor/yiisoft/yii2/base/Application.php(212): yii\base\BaseObject->__construct()
#10 /var/www/vendor/yiisoft/yii2/console/Application.php(90): yii\base\Application->__construct()
#11 [internal function]: yii\console\Application->__construct()
#12 /var/www/vendor/yiisoft/yii2/di/Container.php(420): ReflectionClass->newInstanceArgs()
#13 /var/www/vendor/yiisoft/yii2/di/Container.php(171): yii\di\Container->build()
#14 /var/www/vendor/yiisoft/yii2/BaseYii.php(365): yii\di\Container->get()
#15 /var/www/vendor/craftcms/cms/bootstrap/bootstrap.php(246): yii\BaseYii::createObject()
#16 /var/www/vendor/craftcms/cms/bootstrap/console.php(51): require('/var/www/vendor...')
#17 /var/www/craft(21): require('/var/www/vendor...')
#18 {main}

It appears to be a bug in craft related to the UrlManager code, but if this is the case, I don't know why others have not seemed to experience it (I couldn't find anything about it in my searches)? Does anyone have any suggestions as to what could be wrong?


Solution

  • So I was able to figure out the issue. I had inherited the project and someone had added 'bootstrap' => ['debug'] to the config/php.app file, to enable the Yii debug toolbar. This debug module is calling addRules() on the UrlManager object, and craft code had set the rules field of this object to null instead of [ ]. When addRules() was called, array_merge() threw an exception on the null value (as it was expecting [ ] instead). This code path can be avoided entirely by removing the debug module.

    TLDR; remove 'debug' module from config/php.app if you get an array_merge() exception in UrlManager.php when updating to craft 3.5.12.1 or greater.