craftcms / cms

Build bespoke content experiences with Craft.
https://craftcms.com
Other
3.28k stars 635 forks source link

Project config deleted when installing #4113

Closed nixondesigndev closed 5 years ago

nixondesigndev commented 5 years ago

Description

We currently have a Craft starter composer project that includes a project.yml that sets up some basic sections, settings etc. When running Craft setup via the CP or CLI the project.yml is being overwritten with a fresh one. In this intentional? Is using project.yml in this way supported/advised?

Steps to reproduce

  1. Create a fresh craft install with an existing project.yml (sections, fields etc).
  2. Check contents of project.yml.

Additional info

I've sent the files we are working with to support@.

andris-sevcenko commented 5 years ago

If you are using a project.yaml that is not compatible with the Craft version you are installing for some reason, it will be copied over to storage/config-backups/project-{TIMESTAMP}.yaml, where timestamp is in the format "Ymd-His".

The reasons why it is incompatible should be logged to either your storage/logs/console.log or storage/logs/web.log file, depending on the method you used for installation.

wouter-vs commented 5 years ago

I have the same problem.

In the console.log file I can only find lines like the following concerning the project.yaml. The project.yaml I'm using was generated on the same version of Craft as the one I'm using to setup the new project.

According to 3291 this should be fixed.

2019-04-09 15:02:05 [-][-][-][info][yii\db\Command::execute] UPDATEinfoSETid=1,version='3.1.21.1',schemaVersion='3.1.26',maintenance=0,config='a:6:{s:11:\"fieldGroups\";a:1:{s:36:\"716f91ea-0fe8-4360-8811-ad7f3d868c53\";a:1:{s:4:\"name\";s:6:\"Common\";}}s:5:\"email\";a:3:{s:9:\"fromEmail\";s:16:\"wouter@liftov.be\";s:8:\"fromName\";s:18:\"Liftov Boilerplate\";s:13:\"transportType\";s:37:\"craft\\mail\\transportadapters\\Sendmail\";}s:10:\"siteGroups\";a:1:{s:36:\"125bb00e-537c-4c40-9ff4-cd5cdeb252ff\";a:1:{s:4:\"name\";s:18:\"Liftov Boilerplate\";}}s:5:\"sites\";a:1:{s:36:\"ed8db9c9-e67d-4c02-aed7-af07afb9293c\";a:8:{s:7:\"baseUrl\";s:5:\"@web/\";s:6:\"handle\";s:7:\"default\";s:7:\"hasUrls\";b:1;s:8:\"language\";s:5:\"en-US\";s:4:\"name\";s:18:\"Liftov Boilerplate\";s:7:\"primary\";b:1;s:9:\"siteGroup\";s:36:\"125bb00e-537c-4c40-9ff4-cd5cdeb252ff\";s:9:\"sortOrder\";i:1;}}s:6:\"system\";a:5:{s:7:\"edition\";s:4:\"solo\";s:4:\"name\";s:18:\"Liftov Boilerplate\";s:4:\"live\";b:1;s:13:\"schemaVersion\";s:6:\"3.1.26\";s:8:\"timeZone\";s:19:\"America/Los_Angeles\";}s:5:\"users\";a:5:{s:24:\"requireEmailVerification\";b:1;s:23:\"allowPublicRegistration\";b:0;s:12:\"defaultGroup\";N;s:14:\"photoVolumeUid\";N;s:12:\"photoSubpath\";s:0:\"\";}}',configMap='{\"fieldGroups\":\"@config/project.yaml\",\"email\":\"@config/project.yaml\",\"siteGroups\":\"@config/project.yaml\",\"sites\":\"@config/project.yaml\",\"system\":\"@config/project.yaml\",\"users\":\"@config/project.yaml\"}',uid='dec2ef51-a97a-4a1d-a84a-aaeceb4d6d13',fieldVersion='yeBkIcRWXHOC',dateUpdated='2019-04-09 15:02:05',dateCreated='2019-04-09 15:02:04'

narration-sd commented 5 years ago

Andris, seeing these fly by, it does seem to me that the project.yaml capability would help itself sort out by having its own log. Easy to arrange with Yii/Craft, and both persons having experiences and yourselves would benefit from the single-pointing and its clarity.

Cheap win? This is a brave project, for you and for those who have reasons to be in from the start. Regret I can't be more helpful, as I've been deep in getting another complicated project finally out the door, 'in relative minutes', and in fact the way that's happening has been subtle but big win changes in architecture, but more than equal first, creating an unusual communication system. I think you might be interested in that, sometime when there time in either household.

Best, and as we haven't spoken in a while (and I am thinking it's also good to see Wouter), Clive

andris-sevcenko commented 5 years ago

@Moskydesign hard to comment on that without any specifics. In the original issue the project.yaml file was generated using a Craft version with schema version of 3.1.25, while the latest Craft version had 3.1.26. When installing via console, you do get a nice play-by-play of what's happening. As well as whether the project.yaml file is applied or is being copied away to the backups folder along with a reason. Can you run that again and check the output in the console, not log files?

andris-sevcenko commented 5 years ago

@narration-sd that's something to consider. And it might help with debugging down the line, too.

wouter-vs commented 5 years ago

@andris-sevcenko, the steps are the same as with @NixonGit . Only the schema version may have changed to 3.1.26.

However I did see this in the console output:

Can't apply existing project config: Session does not exist in a console request.
> renaming project.yaml to project-20190407-070121.yaml and moving to config backup folder ... done

By debugging the install process I tracked it down to an issue with the ContactFormExtensions plugin.

In the init function they set a notice because the contact form is not installed/activated and thats where it goes wrong.

if (!Craft::$app->plugins->isPluginInstalled('contact-form')) {
   Craft::$app->session->setNotice(Craft::t('contact-form-extensions', 'The Contact Form plugin is not installed or activated, Contact Form Extensions does not work without it.'));
}

But I'm not really sure that the fault is completely with the plug-in. The should of course check if whether the plug-in is installed via console before trying to set a notice. However I wonder why it's not detecting the contact-form plugin as installed, it comes before the contact-form-extensions plugin in the project.yaml file?

Besides that, isn't there a better way to define dependencies than checking this "manually' in each plug-in? I would think the installer can check plug-in dependencies and install them on the go, no idea if this is something thats build into Craft?

craft\errors\MissingComponentException: Session does not exist in a console request. in /vagrant/htdocs/vendor/craftcms/cms/src/console/Application.php on line 133

Call Stack:
    0.0579     389432   1. {main}() /vagrant/htdocs/craft:0
    0.2633    9242712   2. craft\console\Application->run() /vagrant/htdocs/craft:22
    0.2633    9242712   3. craft\console\Application->handleRequest(???) /vagrant/htdocs/vendor/yiisoft/yii2/base/Application.php:386
    0.2634    9243088   4. craft\console\Application->runAction(???, ???) /vagrant/htdocs/vendor/yiisoft/yii2/console/Application.php:147
    0.2634    9243088   5. craft\console\Application->runAction(???, ???) /vagrant/htdocs/vendor/craftcms/cms/src/console/Application.php:93
    0.2634    9243088   6. craft\console\Application->runAction(???, ???) /vagrant/htdocs/vendor/yiisoft/yii2/console/Application.php:180
    0.2683    9479144   7. craft\console\controllers\SetupController->runAction(???, ???) /vagrant/htdocs/vendor/yiisoft/yii2/base/Module.php:528
    0.2683    9479144   8. craft\console\controllers\SetupController->runAction(???, ???) /vagrant/htdocs/vendor/yiisoft/yii2/console/Controller.php:148
    0.2702    9567872   9. yii\base\InlineAction->runWithParams(???) /vagrant/htdocs/vendor/yiisoft/yii2/base/Controller.php:157
    0.2702    9568736  10. call_user_func_array:{/vagrant/htdocs/vendor/yiisoft/yii2/base/InlineAction.php:57}(???, ???) /vagrant/htdocs/vendor/yiisoft/yii2/base/InlineAction.php:57
    0.2702    9568800  11. craft\console\controllers\SetupController->actionIndex() /vagrant/htdocs/vendor/yiisoft/yii2/base/InlineAction.php:57
    8.8641   11048488  12. craft\console\Application->runAction(???, ???) /vagrant/htdocs/vendor/craftcms/cms/src/console/controllers/SetupController.php:124
    8.8642   11048488  13. craft\console\Application->runAction(???, ???) /vagrant/htdocs/vendor/craftcms/cms/src/console/Application.php:93
    8.8642   11048488  14. craft\console\Application->runAction(???, ???) /vagrant/htdocs/vendor/yiisoft/yii2/console/Application.php:180
    8.8713   11106832  15. craft\console\controllers\InstallController->runAction(???, ???) /vagrant/htdocs/vendor/yiisoft/yii2/base/Module.php:528
    8.8714   11106832  16. craft\console\controllers\InstallController->runAction(???, ???) /vagrant/htdocs/vendor/yiisoft/yii2/console/Controller.php:148
    8.8719   11107864  17. yii\base\InlineAction->runWithParams(???) /vagrant/htdocs/vendor/yiisoft/yii2/base/Controller.php:157
    8.8720   11108728  18. call_user_func_array:{/vagrant/htdocs/vendor/yiisoft/yii2/base/InlineAction.php:57}(???, ???) /vagrant/htdocs/vendor/yiisoft/yii2/base/InlineAction.php:57
    8.8721   11174328  19. craft\console\controllers\InstallController->actionCraft() /vagrant/htdocs/vendor/yiisoft/yii2/base/InlineAction.php:57
   21.5785   13353768  20. craft\db\MigrationManager->migrateUp(???) /vagrant/htdocs/vendor/craftcms/cms/src/console/controllers/InstallController.php:161
   21.5787   13354224  21. craft\migrations\Install->up(???) /vagrant/htdocs/vendor/craftcms/cms/src/db/MigrationManager.php:243
   21.5811   13380192  22. craft\migrations\Install->safeUp() /vagrant/htdocs/vendor/craftcms/cms/src/db/Migration.php:56
   27.6389   14587864  23. craft\migrations\Install->insertDefaultData() /vagrant/htdocs/vendor/craftcms/cms/src/migrations/Install.php:73
   42.2104   15930088  24. craft\migrations\Install->_installPlugins() /vagrant/htdocs/vendor/craftcms/cms/src/migrations/Install.php:1020
   42.2516   16427912  25. craft\services\Plugins->createPlugin(???, ???) /vagrant/htdocs/vendor/craftcms/cms/src/migrations/Install.php:1107
   42.2559   16468424  26. yii\BaseYii::createObject(???, ???) /vagrant/htdocs/vendor/craftcms/cms/src/services/Plugins.php:897
   42.2559   16469120  27. yii\di\Container->get(???, ???, ???) /vagrant/htdocs/vendor/yiisoft/yii2/BaseYii.php:349
   42.2560   16469120  28. yii\di\Container->build(???, ???, ???) /vagrant/htdocs/vendor/yiisoft/yii2/di/Container.php:156
   42.2562   16470096  29. ReflectionClass->newInstanceArgs(???) /vagrant/htdocs/vendor/yiisoft/yii2/di/Container.php:384
   42.2562   16470784  30. rias\contactformextensions\ContactFormExtensions->__construct(???, ???, ???) /vagrant/htdocs/vendor/yiisoft/yii2/di/Container.php:384
   42.2567   16472928  31. rias\contactformextensions\ContactFormExtensions->__construct(???, ???, ???) /vagrant/htdocs/vendor/craftcms/cms/src/base/Plugin.php:127
   42.2567   16472928  32. rias\contactformextensions\ContactFormExtensions->__construct(???) /vagrant/htdocs/vendor/yiisoft/yii2/base/Module.php:158
   42.2568   16473360  33. rias\contactformextensions\ContactFormExtensions->init() /vagrant/htdocs/vendor/yiisoft/yii2/base/BaseObject.php:109
   42.2633   16476056  34. craft\console\Application->__get(???) /vagrant/htdocs/vendor/rias/craft-contact-form-extensions/src/ContactFormExtensions.php:84
   42.2633   16476056  35. craft\console\Application->__get(???) /vagrant/htdocs/vendor/yiisoft/yii2/di/ServiceLocator.php:77
   42.2633   16476096  36. craft\console\Application->getSession() /vagrant/htdocs/vendor/yiisoft/yii2/base/Component.php:139
andris-sevcenko commented 5 years ago

But I'm not really sure that the fault is completely with the plug-in. The should of course check if whether the plug-in is installed via console before trying to set a notice.

It depends on the perspective, I guess. Personally, I don't think they should be checking if a plugin is or is not installed, because it shouldn't matter. As long as they require it in the composer.json file, the plugin's code will be present and autoloaded, allowing them to listen to whatever events they want. They just wouldn't trigger as no forms would get submitted.

However I wonder why it's not detecting the contact-form plugin as installed, it comes before the contact-form-extensions plugin in the project.yaml file?

That's a good question that I would defer to @brandonkelly, but I wouldn't take the order of the listed plugins as a guarantee of the order they are going to be installed.

I would think the installer can check plug-in dependencies and install them on the go, no idea if this is something thats build into Craft?

We do have some plans on improving this aspect of Craft, but that's still a little ways off, so "eventually?" is the best answer I can offer at the time.