From f17ad8ba4d7c361dea676a3f7f5e7197bd6eef36 Mon Sep 17 00:00:00 2001 From: robertSt7 Date: Thu, 30 Mar 2023 14:40:00 +0200 Subject: [PATCH] Improve: Add configuration storage locations to Symfony tree --- .github/ci/files/.env.test | 1 - .github/ci/files/config/system.yml | 5 +++++ .github/ci/scripts/setup-environment.sh | 1 - doc/20_Deployment.md | 12 ++++++++---- phpstan-baseline.neon | 13 +++++++++---- src/Configuration/Dao.php | 10 ++++++++-- src/Configuration/DatahubConfigLocator.php | 2 +- src/DependencyInjection/Configuration.php | 21 +++++++++++++++++++++ 8 files changed, 52 insertions(+), 13 deletions(-) delete mode 100644 .github/ci/files/.env.test diff --git a/.github/ci/files/.env.test b/.github/ci/files/.env.test deleted file mode 100644 index 849f2580..00000000 --- a/.github/ci/files/.env.test +++ /dev/null @@ -1 +0,0 @@ -PIMCORE_WRITE_TARGET_DATA_HUB=settings-store \ No newline at end of file diff --git a/.github/ci/files/config/system.yml b/.github/ci/files/config/system.yml index 8bda27bf..ffc5758f 100644 --- a/.github/ci/files/config/system.yml +++ b/.github/ci/files/config/system.yml @@ -72,3 +72,8 @@ pimcore_admin: color_login_screen: '' color_admin_interface: '' login_screen_custom_image: '' +pimcore_data_hub: + config_location: + data_hub: + target: 'settings-store' + diff --git a/.github/ci/scripts/setup-environment.sh b/.github/ci/scripts/setup-environment.sh index c03a4b23..3aa92ece 100755 --- a/.github/ci/scripts/setup-environment.sh +++ b/.github/ci/scripts/setup-environment.sh @@ -6,7 +6,6 @@ mkdir -p var/config mkdir -p bin cp .github/ci/files/.env . -cp .github/ci/files/.env.test . cp -r .github/ci/files/config/. config cp -r .github/ci/files/templates/. templates cp -r .github/ci/files/bin/console bin/console diff --git a/doc/20_Deployment.md b/doc/20_Deployment.md index 5e4b18f9..c9686fc6 100644 --- a/doc/20_Deployment.md +++ b/doc/20_Deployment.md @@ -27,8 +27,7 @@ for specific definitions. ### Configuration Storage -The configuration user interface utilizes the `LocationAwareConfigRepository` for storing the configuration. With -the environment variable `PIMCORE_WRITE_TARGET_DATA_HUB` the storage location can be configured, possible values are +The configuration user interface utilizes the `LocationAwareConfigRepository` for storing the configuration. In the symfony tree the storage location can be configured, possible values are - `symfony-config` - write configs as Symfony Config as YAML files to `/var/config/data-hub/.yaml` - `settings-store` - write configs to the SettingsStore - `disabled` - do not allow to edit/write configs at all @@ -40,8 +39,13 @@ won't see any update, because these configs are read only. Details also see [Pimcore Docs](https://pimcore.com/docs/pimcore/current/Development_Documentation/Deployment/Configuration_Environments.html#page_Configuration-Storage-Locations-Fallbacks). #### Example -```env -PIMCORE_WRITE_TARGET_DATA_HUB=symfony-config +```yaml +pimcore_data_hub: + config_location: + data_hub: + target: 'symfony-config' + options: + directory: '/var/www/html/var/config/data_hub' ``` Additionally, it is also possible to define the configuration directly in a symfony configuration file without using diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index d909f026..4bb54091 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -2,24 +2,29 @@ parameters: ignoreErrors: - message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeDefinition\\:\\:children\\(\\)\\.$#" - count: 3 + count: 4 path: src/DependencyInjection/Configuration.php - - message: "#Call to static method addConfigLocationWithWriteTargetNodes() on an unknown class#" + message: "#Call to static method addConfigLocationWithWriteTargetNodes\\(\\) on an unknown class\\.$#" count: 1 path: src/DependencyInjection/Configuration.php - - message: "#Call to static method getConfigNodeFromSymfonyTree() on an unknown class#" + message: "#Call to static method getConfigNodeFromSymfonyTree\\(\\) on an unknown class\\.$#" count: 1 path: src/DependencyInjection/PimcoreDataHubExtension.php - - message: "#Call to static method getSymfonyConfigFiles() on an unknown class#" + message: "#Call to static method getSymfonyConfigFiles\\(\\) on an unknown class\\.$#" count: 1 path: src/DependencyInjection/PimcoreDataHubExtension.php + - + message: "#Call to an undefined static method Pimcore\\\\Config\\\\LocationAwareConfigRepository\\:\\:getStorageConfigurationCompatibilityLayer\\(\\)\\.$#" + count: 1 + path: src/Configuration/Dao.php + - message: "#^Constructor of class Pimcore\\\\Bundle\\\\DataHubBundle\\\\GraphQL\\\\AssetType\\\\AssetFolderType has an unused parameter \\$config\\.$#" count: 1 diff --git a/src/Configuration/Dao.php b/src/Configuration/Dao.php index ccb8c9b9..8ce419c7 100644 --- a/src/Configuration/Dao.php +++ b/src/Configuration/Dao.php @@ -64,12 +64,18 @@ public function configure(): void 'storageConfig' => $storageConfig, ]); } else { + $storageConfig = Config\LocationAwareConfigRepository::getStorageConfigurationCompatibilityLayer( + $config, + 'data_hub', + 'PIMCORE_CONFIG_STORAGE_DIR_DATA_HUB', + 'PIMCORE_WRITE_TARGET_DATA_HUB' + ); + parent::configure([ 'containerConfig' => $config['configurations'] ?? [], 'settingsStoreScope' => 'pimcore_data_hub', - 'storageDirectory' => self::CONFIG_PATH, + 'storageDirectory' => $storageConfig, 'legacyConfigFile' => self::LEGACY_FILE, - 'writeTargetEnvVariableName' => 'PIMCORE_WRITE_TARGET_DATA_HUB' ]); } } diff --git a/src/Configuration/DatahubConfigLocator.php b/src/Configuration/DatahubConfigLocator.php index 3c101210..de82b269 100644 --- a/src/Configuration/DatahubConfigLocator.php +++ b/src/Configuration/DatahubConfigLocator.php @@ -20,7 +20,7 @@ use Symfony\Component\Finder\Finder; /** - * @deprecated will be removed in Pimcore 11 + * @deprecated will be removed in Data-Hub 2.0 * Locates data hub configs */ class DatahubConfigLocator diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index cf188af9..d3b5381c 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -48,7 +48,28 @@ public function getConfigTreeBuilder() $this->addSupportedTypes($rootNode); if (\Pimcore\Version::getMajorVersion() >= 11) { + /** @var ArrayNodeDefinition $rootNode */ ConfigurationHelper::addConfigLocationWithWriteTargetNodes($rootNode, ['data_hub']); + } else { + $rootNode + ->children() + ->arrayNode('config_location') + ->addDefaultsIfNotSet() + ->children() + ->arrayNode('data_hub') + ->addDefaultsIfNotSet() + ->children() + ->enumNode('target') + ->values(['symfony-config', 'settings-store']) + ->defaultValue('symfony-config') + ->end() + ->arrayNode('options') + ->defaultValue(['directory' => '%kernel.project_dir%data_hub']) + ->variablePrototype() + ->end() + ->end() + ->end() + ->end(); } return $treeBuilder;