Skip to content

Commit

Permalink
Improve: Add configuration storage locations to Symfony tree
Browse files Browse the repository at this point in the history
  • Loading branch information
robertSt7 committed Mar 29, 2023
1 parent fe4e614 commit 4254b84
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 11 deletions.
1 change: 1 addition & 0 deletions doc/Installation_and_Upgrade/02_Upgrade_Notes.md
@@ -1,6 +1,7 @@
# Upgrade Notes

## 1.6.0
- [Config Location] Change default directory for configurations to `var/config/data_hub`
- When using Pimcore 11 configurations from `datahub-configurations.php` are no longer used. To migrate those configurations
to the settings store, use the provided `datahub:configuration:migrate-legacy-config` command.
- Added the ability to import and export each type of data-hub configuration.
Expand Down
27 changes: 20 additions & 7 deletions src/Configuration/Dao.php
Expand Up @@ -46,19 +46,32 @@ class Dao extends Model\Dao\PimcoreLocationAwareConfigDao
*/
private const LEGACY_FILE = 'datahub-configurations.php';

/**
* @deprecated Will be removed in Pimcore 11
*/
public const CONFIG_PATH = PIMCORE_CONFIGURATION_DIRECTORY . '/data-hub';

public function configure(): void
{
$config = \Pimcore::getContainer()->getParameter('pimcore_data_hub');

parent::configure([
'containerConfig' => $config['configurations'] ?? [],
'settingsStoreScope' => 'pimcore_data_hub',
'storageDirectory' => self::CONFIG_PATH,
'legacyConfigFile' => self::LEGACY_FILE,
'writeTargetEnvVariableName' => 'PIMCORE_WRITE_TARGET_DATA_HUB'
]);
if(\Pimcore\Version::getMajorVersion() >= 11) {
$storageConfig = $config['config_location']['data_hub'];

parent::configure([
'containerConfig' => $config['configurations'] ?? [],
'settingsStoreScope' => 'pimcore_data_hub',
'storageConfig' => $storageConfig,
]);
} else {
parent::configure([
'containerConfig' => $config['configurations'] ?? [],
'settingsStoreScope' => 'pimcore_data_hub',
'storageDirectory' => self::CONFIG_PATH,
'legacyConfigFile' => self::LEGACY_FILE,
'writeTargetEnvVariableName' => 'PIMCORE_WRITE_TARGET_DATA_HUB'
]);
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Configuration/DatahubConfigLocator.php
Expand Up @@ -20,6 +20,7 @@
use Symfony\Component\Finder\Finder;

/**
* @deprecated will be removed in Pimcore 11
* Locates data hub configs
*/
class DatahubConfigLocator
Expand Down
3 changes: 3 additions & 0 deletions src/DependencyInjection/Configuration.php
Expand Up @@ -15,6 +15,7 @@

namespace Pimcore\Bundle\DataHubBundle\DependencyInjection;

use Pimcore\Bundle\CoreBundle\DependencyInjection\ConfigurationHelper;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
Expand Down Expand Up @@ -46,6 +47,8 @@ public function getConfigTreeBuilder()
$this->addConfigurationsNode($rootNode);
$this->addSupportedTypes($rootNode);

ConfigurationHelper::addConfigLocationWithWriteTargetNodes($rootNode, ['data_hub']);

return $treeBuilder;
}

Expand Down
23 changes: 19 additions & 4 deletions src/DependencyInjection/PimcoreDataHubExtension.php
Expand Up @@ -15,6 +15,7 @@

namespace Pimcore\Bundle\DataHubBundle\DependencyInjection;

use Pimcore\Bundle\CoreBundle\DependencyInjection\ConfigurationHelper;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
Expand Down Expand Up @@ -51,16 +52,30 @@ public function prepend(ContainerBuilder $container)
$loader->load('doctrine_migrations.yml');
}

$configDir = PIMCORE_CONFIGURATION_DIRECTORY . '/data-hub';
$configDir = PIMCORE_CONFIGURATION_DIRECTORY . '/data_hub';

if (\Pimcore\Version::getMajorVersion() >= 11) {
$containerConfig = ConfigurationHelper::getConfigNodeFromSymfonyTree($container, 'pimcore_data_hub');
$configDir = $containerConfig['config_location']['data_hub']['options']['directory'];
}

$configLoader = new YamlFileLoader(
$container,
new FileLocator($configDir)
);

//load datahub configs
$configLocator = new \Pimcore\Bundle\DataHubBundle\Configuration\DatahubConfigLocator();
foreach ($configLocator->locate('config') as $config) {
$configLoader->load($config);
if (\Pimcore\Version::getMajorVersion() >= 11) {
$configs = ConfigurationHelper::getSymfonyConfigFiles($configDir);
foreach ($configs as $config) {
$configLoader->load($config);
}
}
else {
$configLocator = new \Pimcore\Bundle\DataHubBundle\Configuration\DatahubConfigLocator();
foreach ($configLocator->locate('config') as $config) {
$configLoader->load($config);
}
}
}
}
47 changes: 47 additions & 0 deletions src/Migrations/PimcoreX/Version20230329133119.php
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\DataHubBundle\Migrations\PimcoreX;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20230329133119 extends AbstractMigration
{
public function getDescription(): string
{
return 'rename default dir for symfony-config files';
}

public function up(Schema $schema): void
{
$this->renameConfigFolder('data-hub', '-', '_');
}

public function down(Schema $schema): void
{
$this->renameConfigFolder('data_hub', '_', '-');
}

private function renameConfigFolder(string $folder, string $search, string $replace): void
{
$configDir = \Pimcore::getContainer()->getParameter('kernel.project_dir') . '/var/config/';
if (is_dir($configDir . $folder)) {
rename($configDir . $folder, $configDir . str_replace($search, $replace, $folder));
}
}
}

0 comments on commit 4254b84

Please sign in to comment.