Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Craft install migration fails when campaign types exist in project config #332

Closed
fthues opened this issue Oct 10, 2022 · 4 comments
Closed
Labels
bug Something isn't working

Comments

@fthues
Copy link

fthues commented Oct 10, 2022

We have four campaign types defined in our project config. Setting up the site on a new environment errors out while Craft tries to apply the project config:

 > applying existing project config ... Exception: Attempt to read property "name" on null (/var/www/html/vendor/putyourlightson/craft-campaign/src/services/CampaignTypesService.php:263)
#0 /var/www/html/vendor/putyourlightson/craft-campaign/src/services/CampaignTypesService.php(263): yii\base\ErrorHandler->handleError(2, 'Attempt to read...', '/var/www/html/v...', 263)
#1 /var/www/html/vendor/craftcms/cms/src/services/ProjectConfig.php(1125): putyourlightson\campaign\services\CampaignTypesService->handleChangedCampaignType(Object(craft\events\ConfigEvent))
#2 [internal function]: craft\services\ProjectConfig->handleChangeEvent(Object(craft\events\ConfigEvent))
#3 /var/www/html/vendor/yiisoft/yii2/base/Component.php(633): call_user_func(Array, Object(craft\events\ConfigEvent))
#4 /var/www/html/vendor/craftcms/cms/src/models/ProjectConfigData.php(79): yii\base\Component->trigger('addItem', Object(craft\events\ConfigEvent))
#5 /var/www/html/vendor/craftcms/cms/src/services/ProjectConfig.php(1115): craft\models\ProjectConfigData->commitChanges(NULL, Array, 'campaign.campai...')
#6 [internal function]: craft\services\ProjectConfig->handleChangeEvent(Object(craft\events\ConfigEvent))
#7 /var/www/html/vendor/yiisoft/yii2/base/Component.php(633): call_user_func(Array, Object(craft\events\ConfigEvent))
#8 /var/www/html/vendor/craftcms/cms/src/models/ProjectConfigData.php(79): yii\base\Component->trigger('addItem', Object(craft\events\ConfigEvent))
#9 /var/www/html/vendor/craftcms/cms/src/services/ProjectConfig.php(1231): craft\models\ProjectConfigData->commitChanges(NULL, Array, 'campaign.campai...', true, NULL, true)
#10 /var/www/html/vendor/craftcms/cms/src/services/ProjectConfig.php(1253): craft\services\ProjectConfig->craft\services\{closure}('campaign.campai...', true)
[...]
*** failed to install Craft: An error occurred while executing the "craft\migrations\Install migration: Attempt to read property "name" on null

This also seems to happen whenever the Campaign project config is initially applied on an existing Craft install (without Campaign being installed previously).

The error is thrown in CampaignTypesService. The resave job it's adding to the queue is accessing $campaignType, which is always null.

Adding a naive null check on line 252 seems to have helped, but I'm not familiar enough with the plugin's internals to judge whether this is a bad idea, we'd probably want to exit the function before we even reach this line (or rather not even trigger it in the first place):

        if (!$isNew && !is_null($campaignType)) {

Versions

  • craftcms/cms 4.2.5.2
  • putyourlightson/craft-campaign 2.1.7
@fthues fthues added the bug Something isn't working label Oct 10, 2022
@bencroker
Copy link
Collaborator

Thanks for reporting this, I'll look into it and release a fix soon.

@bencroker
Copy link
Collaborator

I'm not sure what is causing you to experience this issue, but can you please test and see if the change made in 431d8c2 solves it for you?

@fthues
Copy link
Author

fthues commented Oct 10, 2022

Wow, it actually does, thanks so much for the quick resolution!

I made sure to switch back and forth between develop and 431d8c2 a couple of times (dropping all database tables after each switch and running craft setup again). develop errors out every time, 431d8c2 runs flawlessly.

They say computer science is hard but I guess sometimes a cache clear is all you need. 😅

@bencroker
Copy link
Collaborator

Haha, yeah starting with the simple things tends to pay off! Released in version 2.1.8, thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants