From e41ebdfa59441d9d455b352570b09c86dc5306a0 Mon Sep 17 00:00:00 2001 From: Andrew Longosz Date: Fri, 25 Sep 2020 15:34:14 +0200 Subject: [PATCH] EZP-31740: Fixed and migrated DFS configuration to Symfony 5 (#596) * Migrated DFS configuration to Symfony 5 * Migrated Platform.sh DFS integration to Symfony 5 Co-Authored-By: Tomasz Paloc --- config/packages/dfs/dfs.yaml | 28 ++++++++---- config/packages/overrides/generic.php | 54 +++++++----------------- config/packages/overrides/platformsh.php | 36 ++++++++++------ 3 files changed, 57 insertions(+), 61 deletions(-) diff --git a/config/packages/dfs/dfs.yaml b/config/packages/dfs/dfs.yaml index f3af8317a6..f99ad24adc 100644 --- a/config/packages/dfs/dfs.yaml +++ b/config/packages/dfs/dfs.yaml @@ -1,22 +1,32 @@ +parameters: + env(DFS_DATABASE_URL): '%env(resolve:DATABASE_URL)%' + dfs_database_url: '%env(resolve:DFS_DATABASE_URL)%' + ibexa.platform.io.nfs.adapter.config: + root: '%dfs_nfs_path%' + path: '$var_dir$/$storage_dir$/' + writeFlags: ~ + linkHandling: ~ + permissions: [ ] + # new doctrine connection for the dfs legacy_dfs_cluster metadata handler. doctrine: dbal: connections: dfs: - driver: "%dfs_database_driver%" - host: "%dfs_database_host%" - port: "%dfs_database_port%" - user: "%dfs_database_user%" - password: "%dfs_database_password%" - dbname: "%dfs_database_name%" - charset: utf8mb4 + # configure these for your database server + driver: '%dfs_database_driver%' + charset: '%dfs_database_charset%' + default_table_options: + charset: '%dfs_database_charset%' + collate: '%dfs_database_collation%' + url: '%dfs_database_url%' # define the flysystem handler oneup_flysystem: adapters: nfs_adapter: - local: - directory: "/%dfs_nfs_path%/$var_dir$/$storage_dir$" + custom: + service: ibexa.platform.io.nfs.adapter.site_access_aware # define the ez handlers ez_io: diff --git a/config/packages/overrides/generic.php b/config/packages/overrides/generic.php index d583f6a9d6..02cbb68cf4 100644 --- a/config/packages/overrides/generic.php +++ b/config/packages/overrides/generic.php @@ -6,49 +6,27 @@ use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\Loader; -require_once dirname(__DIR__, 2).'/bootstrap.php'; +require_once dirname(__DIR__, 2) . '/bootstrap.php'; - if ($dfsNfsPath = $_SERVER['DFS_NFS_PATH'] ?? false) { +/** @var \Symfony\Component\DependencyInjection\ContainerBuilder $container */ +if ($dfsNfsPath = $_SERVER['DFS_NFS_PATH'] ?? false) { $container->setParameter('dfs_nfs_path', $dfsNfsPath); - if ($value = $_SERVER['DFS_DATABASE_DRIVER'] ?? false) { - $container->setParameter('dfs_database_driver', $value); - } else { - $container->setParameter('dfs_database_driver', $container->getParameter('database_driver')); + $parameterMap = [ + 'dfs_database_charset' => 'database_charset', + 'dfs_database_driver' => 'database_driver', + 'dfs_database_collation' => 'database_collation', + ]; + + foreach ($parameterMap as $dfsParameter => $platformParameter) { + $container->setParameter( + $dfsParameter, + $_SERVER[strtoupper($dfsParameter)] ?? $container->getParameter($platformParameter) + ); } - if ($value = $_SERVER['DFS_DATABASE_HOST'] ?? false) { - $container->setParameter('dfs_database_host', $value); - } else { - $container->setParameter('dfs_database_host', $container->getParameter('database_host')); - } - - if ($value = $_SERVER['DFS_DATABASE_PORT'] ?? false) { - $container->setParameter('dfs_database_port', $value); - } else { - $container->setParameter('dfs_database_port', $container->getParameter('database_port')); - } - - if ($value = $_SERVER['DFS_DATABASE_NAME'] ?? false) { - $container->setParameter('dfs_database_name', $value); - } else { - $container->setParameter('dfs_database_name', $container->getParameter('database_name')); - } - - if ($value = $_SERVER['DFS_DATABASE_USER'] ?? false) { - $container->setParameter('dfs_database_user', $value); - } else { - $container->setParameter('dfs_database_user', $container->getParameter('database_user')); - } - - if ($value = $_SERVER['DFS_DATABASE_PASSWORD'] ?? false) { - $container->setParameter('dfs_database_password', $value); - } else { - $container->setParameter('dfs_database_password', $container->getParameter('database_password')); - } - - $loader = new Loader\YamlFileLoader($container, new FileLocator(dirname(__DIR__).'/dfs')); - $loader->load('dfs.yml'); + $loader = new Loader\YamlFileLoader($container, new FileLocator(dirname(__DIR__) . '/dfs')); + $loader->load('dfs.yaml'); } // Cache settings diff --git a/config/packages/overrides/platformsh.php b/config/packages/overrides/platformsh.php index 3a296ca5c1..c97b6c0774 100644 --- a/config/packages/overrides/platformsh.php +++ b/config/packages/overrides/platformsh.php @@ -24,29 +24,37 @@ // PLATFORMSH_DFS_NFS_PATH is different compared to DFS_NFS_PATH in the sense that it is relative to ezplatform dir // DFS_NFS_PATH is an absolute path if ($dfsNfsPath = $_SERVER['PLATFORMSH_DFS_NFS_PATH'] ?? false) { - $container->setParameter('dfs_nfs_path', sprintf('%s/%s', dirname($container->getParameter('kernel.project_dir')), $dfsNfsPath)); - + $container->setParameter('dfs_nfs_path', sprintf('%s/%s', $container->getParameter('kernel.project_dir'), $dfsNfsPath)); + + // Map common parameters + $container->setParameter('dfs_database_charset', $container->getParameter('database_charset')); + $container->setParameter( + 'dfs_database_collation', + $container->getParameter('database_collation') + ); if (array_key_exists('dfs_database', $relationships)) { + // process dedicated P.sh dedicated config foreach ($relationships['dfs_database'] as $endpoint) { if (empty($endpoint['query']['is_master'])) { continue; } - $container->setParameter('dfs_database_driver', 'pdo_' . $endpoint['scheme']); - $container->setParameter('dfs_database_host', $endpoint['host']); - $container->setParameter('dfs_database_port', $endpoint['port']); - $container->setParameter('dfs_database_name', $endpoint['path']); - $container->setParameter('dfs_database_user', $endpoint['username']); - $container->setParameter('dfs_database_password', $endpoint['password']); + $container->setParameter( + 'dfs_database_url', + sprintf( + '%s://%s:%s:%d@%s/%s', + $endpoint['scheme'], + $endpoint['username'], + $endpoint['password'], + $endpoint['port'], + $endpoint['host'], + $endpoint['path'] + ) + ); } } else { - // If dfs_database endpoint is not defined, we'll use the default database for DFS too + // or set fallback from the Repository database, if not configured $container->setParameter('dfs_database_driver', $container->getParameter('database_driver')); - $container->setParameter('dfs_database_host', $container->getParameter('database_host')); - $container->setParameter('dfs_database_port', $container->getParameter('database_port')); - $container->setParameter('dfs_database_name', $container->getParameter('database_name')); - $container->setParameter('dfs_database_user', $container->getParameter('database_user')); - $container->setParameter('dfs_database_password', $container->getParameter('database_password')); } $loader = new Loader\YamlFileLoader($container, new FileLocator(dirname(__DIR__).'/dfs'));