-
Notifications
You must be signed in to change notification settings - Fork 50
Description
Describe the bug
Line 87 of .platform.app.yaml includes a drush config-import command in the deploy hook. If the project doesn't actively use configuration management, then the config import will fail with the error included below in the logs section.
Include some logs
W: [error] Drupal\Core\Config\ConfigImporterException: There were errors validating the config synchronization.
W: This import is empty and if applied would delete all of your configuration, so has been rejected. in Drupal\Core\Config\ConfigImporter->validate() (line 750 of /app/web/core/lib/Drupal/Core/Config/ConfigImporter.php).
W:
W: In ConfigImportCommands.php line 360:
W:
W: The import failed due to the following reasons:
W: This import is empty and if applied would delete all of your configuration,
W: so has been rejected.
W:
Reproducing
Do not use configuration management, push change to a project environment.
Expected behavior
Only run config-import if the project is using configuration management.
Your environment
Default Drupal9 template
Screenshots
N/A
Additional context
Note, these changes are identical to #114 as they are related to one another.
Suggest changing deploy to something like the following:
deploy: |
set -e
php ./drush/platformsh_generate_drush_yml.php
cd web
if [ -n "$(drush status bootstrap)" ]; then
drush -y cache-rebuild
drush -y updatedb
if [ -n "$(ls $(drush php:eval "echo realpath(Drupal\Core\Site\Settings::get('config_sync_directory'));")/*.yml 2>/dev/null)" ]; then
drush -y config-import
else
echo "No config to import. Skipping."
fi
else
echo "Drupal not installed. Skipping standard Drupal deploy steps"
fiWe get the config directory from drush, concatenate it with /*.yml and use that with ls. If there are config files, then the return from ls will not be empty so we can continue with config-import.
There was some concern mentioned about settings not being available. According to the docs for Settings::get
Return value
mixed The value of the setting, the provided default if not set.
In the absence of a setting, according to the docs, the default is
By default, Drupal places the configuration sync directory within the site's files directory, using a hash as part of the directory name, thus sites/default/files/config_HASH
if it were to return that default, the call to realpath on a non-existent path will return a false which when echo’ed will be an empty string. Returned back to the ls command, we’re lsing on / which doesnt include any yaml files.
If needed we could break it out further to exit processing if realpath returns an empty string.