verbb / cp-nav

Control Panel Nav is a Craft CMS plugin to help manage your Control Panel navigation.
MIT License
130 stars 11 forks source link

m220409_000000_craft_4 migration fails when allowAdminChanges is false #109

Closed FlorisDerks closed 2 years ago

FlorisDerks commented 2 years ago

Describe the bug

I've prepared an upgrade from Craft v3 to v4 on my local environment, and now try to upgrade my production site which has allowAdminChanges set to FALSE. This causes the following error message when running all migrations, because the migration is trying to write to the project config when it's not allowed (and the project-config files are already upgraded):

*** applying m220409_000000_craft_4
    > rename column order in table {{%cpnav_navigation}} to sortOrder ... done (time: 0.009s)
    > add column prevLevel smallint AFTER `sortOrder` to table {{%cpnav_navigation}} ... done (time: 0.203s)
    > add column level smallint DEFAULT 1 AFTER `prevLevel` to table {{%cpnav_navigation}} ... done (time: 0.160s)
    > add column prevParentId integer AFTER `level` to table {{%cpnav_navigation}} ... done (time: 0.138s)
    > add column parentId integer AFTER `prevParentId` to table {{%cpnav_navigation}} ... done (time: 0.147s)
    > add column subnavBehaviour string AFTER `newWindow` to table {{%cpnav_navigation}} ... done (time: 0.164s)
    > update in {{%cpnav_navigation}} ... done (time: 0.011s)
    > dropping {{%cpnav_pending_navigations}} if it exists ... done (time: 0.092s)
    > update in {{%cpnav_navigation}} ... done (time: 0.004s)
Exception: Changes to the project config are not possible while in read-only mode. (/var/www/html/vendor/craftcms/cms/src/services/ProjectConfig.php:503)
#0 /var/www/html/vendor/craftcms/cms/src/services/ProjectConfig.php(475): craft\services\ProjectConfig->_setInternal()
#1 /var/www/html/vendor/verbb/cp-nav/src/services/Navigations.php(101): craft\services\ProjectConfig->set()
#2 /var/www/html/vendor/verbb/cp-nav/src/migrations/m220409_000000_craft_4.php(125): verbb\cpnav\services\Navigations->saveNavigation()
#3 /var/www/html/vendor/craftcms/cms/src/db/Migration.php(49): verbb\cpnav\migrations\m220409_000000_craft_4->safeUp()
#4 /var/www/html/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(758): craft\db\Migration->up()
#5 /var/www/html/vendor/craftcms/cms/src/console/controllers/MigrateController.php(360): yii\console\controllers\BaseMigrateController->migrateUp()
#6 [internal function]: craft\console\controllers\MigrateController->actionAll()
#7 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array()
#8 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams()
#9 /var/www/html/vendor/yiisoft/yii2/console/Controller.php(182): yii\base\Controller->runAction()
#10 /var/www/html/vendor/yiisoft/yii2/base/Module.php(552): yii\console\Controller->runAction()
#11 /var/www/html/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction()
#12 /var/www/html/vendor/craftcms/cms/src/console/Application.php(90): yii\console\Application->runAction()
#13 /var/www/html/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction()
#14 /var/www/html/vendor/craftcms/cms/src/console/Application.php(121): yii\console\Application->handleRequest()
#15 /var/www/html/vendor/yiisoft/yii2/base/Application.php(384): craft\console\Application->handleRequest()
#16 /var/www/html/craft(22): yii\base\Application->run()
#17 {main}
*** failed to apply m220409_000000_craft_4 (time: 1.263s)

Steps to reproduce

  1. Prepare a upgrade from Craft CMS v3 to v4 locally with allowAdminChanges set to TRUE
  2. Commit all changes to the config to git & deploy on another environment (with allowAdminChanges set to FALSE) with an old non-upgraded database
  3. Run php craft migrate/all

Craft CMS version

4.2.0.1

Plugin version

4.0.4

Multi-site?

Yes

Additional context

No response

engram-design commented 2 years ago

Should be fixed in 4.0.5