Skip to content

Commit

Permalink
Fixed #3546
Browse files Browse the repository at this point in the history
  • Loading branch information
andris-sevcenko committed Dec 13, 2018
1 parent e6a1a25 commit 5ccd5ff
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace craft\migrations;

use Craft;
use craft\db\Migration;
use craft\db\Query;
use craft\helpers\ArrayHelper;
use craft\services\Sections;
use yii\helpers\Json;

/**
* m181213_102500_remove_absolue_paths_from_configmap migration.
*/
class m181213_102500_remove_absolue_paths_from_configmap extends Migration
{
/**
* @inheritdoc
*/
public function safeUp()
{
$info = Craft::$app->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;
}
}
16 changes: 14 additions & 2 deletions src/services/ProjectConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit 5ccd5ff

Please sign in to comment.