diff --git a/CHANGELOG-v3.md b/CHANGELOG-v3.md index 80de64e15ec..3ccce7b4aac 100644 --- a/CHANGELOG-v3.md +++ b/CHANGELOG-v3.md @@ -7,6 +7,7 @@ ### Changed - The `app/migrate` web action now applies pending `project.yaml` changes, if the `useProjectConfigFile` config setting is enabled. +- Project Config map now uses relative file paths with aliases instead of absolute paths. ([#3546](https://github.com/craftcms/cms/issues/3546)) ### Fixed - Fixed a bug where restoring elements belonging to deleted sites via `project.yaml` would throw an error. diff --git a/src/migrations/m181213_102500_remove_absolue_paths_from_configmap.php b/src/migrations/m181213_102500_remove_absolue_paths_from_configmap.php new file mode 100644 index 00000000000..bec3533922e --- /dev/null +++ b/src/migrations/m181213_102500_remove_absolue_paths_from_configmap.php @@ -0,0 +1,44 @@ +getInfo(); + $configMap = Json::decode($info->configMap) ?? []; + + foreach ($configMap as &$filePath) { + $filePath = Craft::alias($filePath); + } + + $info->configMap = $configMap; + + Craft::$app->saveInfo($info); + + return true; + } + + /** + * @inheritdoc + */ + public function safeDown() + { + echo "m181213_102500_remove_absolue_paths_from_configmap cannot be reverted.\n"; + return false; + } +} diff --git a/src/services/ProjectConfig.php b/src/services/ProjectConfig.php index 0d2db07fe15..3c214361e95 100644 --- a/src/services/ProjectConfig.php +++ b/src/services/ProjectConfig.php @@ -572,7 +572,13 @@ public function saveModifiedConfigData() $info = Craft::$app->getInfo(); if ($this->_updateConfigMap && $this->_useConfigFile()) { - $info->configMap = Json::encode($this->_generateConfigMap()); + $configMap = $this->_generateConfigMap(); + + foreach ($configMap as &$filePath) { + $filePath = Craft::alias($filePath); + } + + $info->configMap = Json::encode($configMap); } if ($this->_updateConfig) { @@ -865,7 +871,13 @@ private function _getStoredConfigMap(): array return $this->_configMap; } - return $this->_configMap = Json::decode(Craft::$app->getInfo()->configMap) ?? []; + $configMap = Json::decode(Craft::$app->getInfo()->configMap) ?? []; + + foreach ($configMap as &$filePath) { + $filePath = Craft::getAlias($filePath); + } + + return $this->_configMap = $configMap; } /**