Skip to content

Commit

Permalink
EZP-31740: Fixed and migrated DFS configuration to Symfony 5 (#596)
Browse files Browse the repository at this point in the history
* Migrated DFS configuration to Symfony 5

* Migrated Platform.sh DFS integration to Symfony 5

Co-Authored-By: Tomasz Paloc <[email protected]>
  • Loading branch information
alongosz and Tomasz Paloc authored Sep 25, 2020
1 parent 2ff48e5 commit e41ebdf
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 61 deletions.
28 changes: 19 additions & 9 deletions config/packages/dfs/dfs.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
54 changes: 16 additions & 38 deletions config/packages/overrides/generic.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 22 additions & 14 deletions config/packages/overrides/platformsh.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down

0 comments on commit e41ebdf

Please sign in to comment.