craftcms / commerce

Fully integrated ecommerce for Craft CMS.
https://craftcms.com/commerce
Other
215 stars 169 forks source link

[5.x]: Migration error when trying to install with existing config #3472

Closed WHITE-developer closed 2 months ago

WHITE-developer commented 2 months ago

What happened?

Description

When running ./craft install with an existing project config the Install migration fails on inserting the default Donation Purchasable because there is no Store yet in the DB

When commenting the default donation function out, the install failes further when applying the existing project config on a likewise issue.

https://github.com/craftcms/commerce/blob/5.x/src/services/OrderStatuses.php#L341

At this point the stores defined in the project.yaml are still not added to the database

Steps to reproduce

  1. have a commerce project setup
  2. run ./craft install on a clean DB
  3. Commerce Install migration fails

Expected behavior

  1. Install migration should finish correctly

Actual behavior

Install migration fails

#0 /var/www/html/vendor/craftcms/commerce/src/services/PaymentCurrencies.php(111): craft\commerce\services\Stores->getCurrentStore()
#1 /var/www/html/vendor/craftcms/commerce/src/services/PaymentCurrencies.php(100): craft\commerce\services\PaymentCurrencies->getPrimaryPaymentCurrency(NULL)
#2 /var/www/html/vendor/craftcms/commerce/src/elements/Donation.php(46): craft\commerce\services\PaymentCurrencies->getPrimaryPaymentCurrencyIso()
#3 /var/www/html/vendor/yiisoft/yii2/base/Component.php(739): craft\commerce\elements\Donation->behaviors()
#4 /var/www/html/vendor/yiisoft/yii2/base/Component.php(465): yii\base\Component->ensureBehaviors()
#5 /var/www/html/vendor/craftcms/cms/src/base/Model.php(88): yii\base\Component->hasEventHandlers('init')
#6 /var/www/html/vendor/craftcms/cms/src/base/Element.php(2320): craft\base\Model->init()
#7 /var/www/html/vendor/yiisoft/yii2/base/BaseObject.php(109): craft\base\Element->init()
#8 /var/www/html/vendor/craftcms/cms/src/base/Model.php(78): yii\base\BaseObject->__construct(Array)
#9 /var/www/html/vendor/craftcms/cms/src/base/Element.php(2185): craft\base\Model->__construct(Array)
#10 /var/www/html/vendor/craftcms/commerce/src/migrations/Install.php(1345): craft\base\Element->__construct()
#11 /var/www/html/vendor/craftcms/commerce/src/migrations/Install.php(1294): craft\commerce\migrations\Install->_defaultDonationPurchasable()
#12 /var/www/html/vendor/craftcms/commerce/src/migrations/Install.php(48): craft\commerce\migrations\Install->insertDefaultData()
#13 /var/www/html/vendor/craftcms/cms/src/db/Migration.php(49): craft\commerce\migrations\Install->safeUp()
#14 /var/www/html/vendor/craftcms/cms/src/db/MigrationManager.php(233): craft\db\Migration->up(true)
#15 /var/www/html/vendor/craftcms/cms/src/base/Plugin.php(144): craft\db\MigrationManager->migrateUp(Object(craft\commerce\migrations\Install))
#16 /var/www/html/vendor/craftcms/cms/src/services/Plugins.php(533): craft\base\Plugin->install()
#17 /var/www/html/vendor/craftcms/cms/src/migrations/Install.php(1203): craft\services\Plugins->installPlugin('commerce')
#18 /var/www/html/vendor/craftcms/cms/src/migrations/Install.php(1102): craft\migrations\Install->_installPlugins()
#19 /var/www/html/vendor/craftcms/cms/src/migrations/Install.php(79): craft\migrations\Install->insertDefaultData()
#20 /var/www/html/vendor/craftcms/cms/src/db/Migration.php(49): craft\migrations\Install->safeUp()
#21 /var/www/html/vendor/craftcms/cms/src/db/MigrationManager.php(233): craft\db\Migration->up(true)
#22 /var/www/html/vendor/craftcms/cms/src/console/controllers/InstallController.php(213): craft\db\MigrationManager->migrateUp(Object(craft\migrations\Install))
#23 [internal function]: craft\console\controllers\InstallController->actionCraft('UK')
#24 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#25 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#26 /var/www/html/vendor/yiisoft/yii2/console/Controller.php(180): yii\base\Controller->runAction('', Array)
#27 /var/www/html/vendor/craftcms/cms/src/console/ControllerTrait.php(89): yii\console\Controller->runAction('', Array)
#28 /var/www/html/vendor/craftcms/cms/src/console/Controller.php(216): craft\console\Controller->traitRunAction('', Array)
#29 /var/www/html/vendor/yiisoft/yii2/base/Module.php(552): craft\console\Controller->runAction('', Array)
#30 /var/www/html/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('install', Array)
#31 /var/www/html/vendor/craftcms/cms/src/console/Application.php(91): yii\console\Application->runAction('install', Array)
#32 /var/www/html/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('install', Array)
#33 /var/www/html/vendor/craftcms/cms/src/console/Application.php(122): yii\console\Application->handleRequest(Object(craft\console\Request))
#34 /var/www/html/vendor/yiisoft/yii2/base/Application.php(384): craft\console\Application->handleRequest(Object(craft\console\Request))
#35 /var/www/html/craft(13): yii\base\Application->run()```

### Craft CMS version

5.1.0

### Craft Commerce version

5.0.0

### PHP version

8.3.6

### Operating system and version

_No response_

### Database type and version

mysql 8.0

### Image driver and version

_No response_

### Installed plugins and versions

_No response_
linear[bot] commented 2 months ago

PT-1682 [5.x]: Migration error when trying to install with existing config

nfourtythree commented 2 months ago

Hi @WHITE-developer

So I am assuming that the project config in this scenario is like a "starter" config for new projects, is that correct?

If so has this config been updated for Commerce 5 compatibility before trying to use it with a fresh install of 5?

Thanks

WHITE-developer commented 2 months ago

Hi @nfourtythree It is a project config started on the Beta of commerce 5 (there is a config/project/commerce/stores/primary--{uid}.yaml)

nfourtythree commented 2 months ago

Hi @WHITE-developer

Thank you for your reply, could you please send across your composer files along with your project config to support@craftcms.com

That way I can get things setup and replicate this issue to see what is going on.

Thanks!

nfourtythree commented 2 months ago

Have tried to replicate this issue but have been unable to reproduce it when having an existing project config.

If you could provide more detailed steps or maybe even an example project where the error is reproducible, we can look into it further.

Thanks!

nfourtythree commented 2 months ago

Hi @WHITE-developer

Thank you for sending the files and extra info it was really helpful to get this issue sorted.

We have pushed up a fix which will be included in the next release of Commerce.

To get this early, change your craftcms/commerce requirement in your project's composer.json to:

"require": {
  "craftcms/commerce": "5.x-dev#d64c075dc359f6c56fb552aeeda6fa704a08be2d as 5.0.2",
  "...": "..."
}

Then run composer update.

Thanks!

nfourtythree commented 2 months ago

Commerce 5.0.3 has been released with this fix included.

Thanks!