timmyomahony / craft-matrix-field-preview

Configure a screenshot preview for all your matrix field blocks, giving your clients a better publishing experience.
https://plugins.craftcms.com/matrix-field-preview
Other
16 stars 4 forks source link

'Changes to the project config are not possible while in read-only mode.' #50

Closed timmyomahony closed 2 years ago

timmyomahony commented 4 years ago

I got this error when installing 1.1.3 up from 1.0.7 on production when running migrations craft migrate/all:

Exception 'craft\errors\MigrateException' with message 'An error occurred while migrating Matrix Field Preview.'

in /home/forge/weareferal.com/vendor/craftcms/cms/src/services/Updates.php:235

Caused by: Exception 'yii\base\NotSupportedException' with message 'Changes to the project config are not possible while in read-only mode.'

in /home/forge/weareferal.com/vendor/craftcms/cms/src/services/ProjectConfig.php:458

Stack trace:
#0 /home/forge/weareferal.com/vendor/craftcms/cms/src/services/Updates.php(151): craft\services\ProjectConfig->set()
#1 /home/forge/weareferal.com/vendor/craftcms/cms/src/services/Updates.php(228): craft\services\Updates->setNewPluginInfo()
#2 /home/forge/weareferal.com/vendor/craftcms/cms/src/console/controllers/MigrateController.php(328): craft\services\Updates->runMigrations()
#3 [internal function]: craft\console\controllers\MigrateController->actionAll()
#4 /home/forge/weareferal.com/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array()
#5 /home/forge/weareferal.com/vendor/yiisoft/yii2/base/Controller.php(180): yii\base\InlineAction->runWithParams()
#6 /home/forge/weareferal.com/vendor/yiisoft/yii2/console/Controller.php(179): yii\base\Controller->runAction()
#7 /home/forge/weareferal.com/vendor/yiisoft/yii2/base/Module.php(528): yii\console\Controller->runAction()
#8 /home/forge/weareferal.com/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction()
#9 /home/forge/weareferal.com/vendor/craftcms/cms/src/console/Application.php(101): yii\console\Application->runAction()
#10 /home/forge/weareferal.com/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction()
#11 /home/forge/weareferal.com/vendor/yiisoft/yii2/base/Application.php(386): yii\console\Application->handleRequest()
#12 /home/forge/weareferal.com/craft(22): yii\base\Application->run()
#13 {main}
Script @php craft migrate/all handling the craft-update event returned with error code 1
Script @craft-update was called via post-install-cmd

Why I think this is happening:

There is a schema change to the plugin as part of this 1.1 update (1.0 to 1.1). This is so that Craft understands that the plugin has migrations to run. This schema change involves the project config being updated (config/project/plugins/plugins.yaml). This should happen locally when you update the plugin and those changes should be checked into git and deployed with the update so that the production server runs the database migrations but already has the updated project config.

In my case when I updated the plugin locally, for some reason the project config changes weren't created or I didn't check them in (need to test this again). I deployed to my development environment (where admin changes are allowed) and didn't notice that the project config changes were happening there. When I went to deploy to production, because admin changes aren't allowed, I get this error.

The fix in my case was to manually update the schema for this plugin in config/project/plugins/plugins.yaml to use the new schema:

matrix-field-preview:
  edition: standard
  enabled: true
  licenseKey: 
  schemaVersion: 1.1.0

I need to test why these project config changes to schema weren't added to my local version when updating

timmyomahony commented 2 years ago

Haven't been able to replicate since, so closing for the moment. Please comment if you run into this and I'll investigate further.