From f35632f044f0fcbcb23ed59496a700ca07cc4811 Mon Sep 17 00:00:00 2001 From: Killesreiter Volker Date: Mon, 26 Aug 2024 11:51:59 +0200 Subject: [PATCH 01/17] Remove patches --- BackendCommands.php | 33 --------------------------------- 1 file changed, 33 deletions(-) diff --git a/BackendCommands.php b/BackendCommands.php index d3bca48..e2ac6cd 100644 --- a/BackendCommands.php +++ b/BackendCommands.php @@ -49,8 +49,6 @@ public function preInstallCommand(CommandData $commandData) { $this->populateConfigSyncDirectory(); - // Apply core patches - $this->corePatches(); } /** @@ -89,8 +87,6 @@ public function install() */ public function postInstallCommand($result, CommandData $commandData) { - // Remove the patch. - $this->corePatches($revert = true); $this->process(['git', 'checkout', $this->siteDirectory().'/settings.php'], $this->projectDirectory()); } @@ -396,35 +392,6 @@ protected function populateConfigSyncDirectory(): void } } - /** - * Apply or revoke patches to drupal core. - * - * @param bool $revert - */ - protected function corePatches(bool $revert = false) - { - $patches = [ - 'https://www.drupal.org/files/issues/2020-09-14/3169756-2-11.patch', - 'https://www.drupal.org/files/issues/2020-06-03/2488350-3-98.patch', - ]; - - $command = ['patch', '-p1', '--silent']; - if ($revert) { - $command[] = '-R'; - $patches = array_reverse($patches); - } - - foreach ($patches as $patch) { - $stream = fopen($patch, 'r'); - try { - $this->process($command, $this->drupalRootDirectory(), null, $stream); - } catch (\Exception $e) { - $this->logger()->info('A patch was not applied correctly, continuing without this patch.'); - } - fclose($stream); - } - } - /** * Get all config files in a given directory. * From f1e6acf10d8c59d6e92b1b0611f561bcb254c44e Mon Sep 17 00:00:00 2001 From: Killesreiter Volker Date: Mon, 26 Aug 2024 11:58:07 +0200 Subject: [PATCH 02/17] Add focusplus to $siteDomainDirectoryMapping --- BackendCommandsTrait.php | 1 + 1 file changed, 1 insertion(+) diff --git a/BackendCommandsTrait.php b/BackendCommandsTrait.php index 6d97b8f..40199f9 100644 --- a/BackendCommandsTrait.php +++ b/BackendCommandsTrait.php @@ -26,6 +26,7 @@ trait BackendCommandsTrait private $siteDomainDirectoryMapping = [ '@elle.dev' => 'elle.de', '@esquire.dev' => 'esquire.de', + '@focusplus.dev' => 'focusplus.de', '@freundin.dev' => 'freundin.de', '@harpersbazaar.dev' => 'harpersbazaar.de', '@instyle.dev' => 'instyle.de', From 1291a80ee5bb48350673c6a8b6c36282a6dcabd4 Mon Sep 17 00:00:00 2001 From: Killesreiter Volker Date: Mon, 26 Aug 2024 12:02:13 +0200 Subject: [PATCH 03/17] fix cs --- BackendCommands.php | 1 - 1 file changed, 1 deletion(-) diff --git a/BackendCommands.php b/BackendCommands.php index e2ac6cd..654b5a5 100644 --- a/BackendCommands.php +++ b/BackendCommands.php @@ -48,7 +48,6 @@ public function __construct() public function preInstallCommand(CommandData $commandData) { $this->populateConfigSyncDirectory(); - } /** From ba8d6882813783d48f01ae56ef2f262b0537c429 Mon Sep 17 00:00:00 2001 From: Killesreiter Volker Date: Mon, 26 Aug 2024 13:15:35 +0200 Subject: [PATCH 04/17] fix project-directory option --- BackendCommands.php | 38 ++++---------------------------------- BackendCommandsTrait.php | 18 ++---------------- 2 files changed, 6 insertions(+), 50 deletions(-) diff --git a/BackendCommands.php b/BackendCommands.php index 654b5a5..b67187b 100644 --- a/BackendCommands.php +++ b/BackendCommands.php @@ -127,12 +127,12 @@ public function updateDatabase() /** * Add option to command. * - * @hook option config:export + * @hook option backend:create-testing-dump backend:install config:export config:import * * @param \Symfony\Component\Console\Command\Command $command * @param \Consolidation\AnnotatedCommand\AnnotationData $annotationData */ - public function additionalConfigExportOption(Command $command, AnnotationData $annotationData) + public function additionalBackendOptions(Command $command, AnnotationData $annotationData) { $command->addOption( 'project-directory', @@ -143,12 +143,12 @@ public function additionalConfigExportOption(Command $command, AnnotationData $a } /** - * @hook init config:export + * @hook init backend:create-testing-dump backend:install config:export config:import * * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Consolidation\AnnotatedCommand\AnnotationData $annotationData */ - public function initConfigExportCommand(InputInterface $input, AnnotationData $annotationData) + public function initBackendCommands(InputInterface $input, AnnotationData $annotationData) { $this->initCommands($input, $annotationData); } @@ -233,36 +233,6 @@ public function preConfigImportCommand(CommandData $commandData) $this->populateConfigSyncDirectory(); } - /** - * Add option to command. - * - * @hook option config:import - * - * @param \Symfony\Component\Console\Command\Command $command - * @param \Consolidation\AnnotatedCommand\AnnotationData $annotationData - */ - public function additionalConfigImportOption(Command $command, AnnotationData $annotationData) - { - $command->addOption( - 'project-directory', - '', - InputOption::VALUE_NONE, - 'The base directory of the project. Defaults to composer root of project. Option added by burdastyle backend commands.' - ); - } - - /** - * @hook init config:import - * - * @param \Symfony\Component\Console\Input\InputInterface $input - * @param \Consolidation\AnnotatedCommand\AnnotationData $annotationData - */ - public function initConfigImportCommand(InputInterface $input, AnnotationData $annotationData) - { - $this->initCommands($input, $annotationData); - } - - /** * Prepare an update branch. Does code update, database update and config export. * diff --git a/BackendCommandsTrait.php b/BackendCommandsTrait.php index 40199f9..c14532b 100644 --- a/BackendCommandsTrait.php +++ b/BackendCommandsTrait.php @@ -3,13 +3,12 @@ namespace Drush\Commands\BurdaStyleGroup; use Consolidation\AnnotatedCommand\AnnotationData; -use Consolidation\AnnotatedCommand\CommandError; use Consolidation\SiteAlias\SiteAliasInterface; use Consolidation\SiteAlias\SiteAliasManagerAwareTrait; use Drupal\Core\Site\Settings; use Drush\Drush; use Symfony\Component\Console\Input\InputInterface; -use Webmozart\PathUtil\Path; +use Symfony\Component\Filesystem\Path; /** * Trait for backend drush commands. @@ -38,7 +37,7 @@ trait BackendCommandsTrait private $projectDirectory; /** - * @hook init + * Init params. * * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Consolidation\AnnotatedCommand\AnnotationData $annotationData @@ -49,19 +48,6 @@ public function initCommands(InputInterface $input, AnnotationData $annotationDa $this->projectDirectory = $input->getOption('project-directory') ?: Drush::bootstrapManager()->getComposerRoot(); } - /** - * Define default options for most backend commands. - * - * @hook option @options-backend - * - * @option project-directory The base directory of the project. Defaults to composer root of project. - * - * @param array $options - */ - public function optionsBackend($options = ['project-directory' => false]) - { - } - /** * Drush command wrapper. * From 4e4bef4c979497684d9526b67d220d3f8db75943 Mon Sep 17 00:00:00 2001 From: Killesreiter Volker Date: Mon, 26 Aug 2024 14:07:52 +0200 Subject: [PATCH 05/17] another way --- BackendCommands.php | 67 +++++++++++++++++++++++++++++++++++++--- BackendCommandsTrait.php | 14 ++------- 2 files changed, 65 insertions(+), 16 deletions(-) diff --git a/BackendCommands.php b/BackendCommands.php index b67187b..60d1703 100644 --- a/BackendCommands.php +++ b/BackendCommands.php @@ -38,6 +38,36 @@ public function __construct() $this->filesystem = new Filesystem(); } + /** + * @hook init @options-backend + * + * @param \Symfony\Component\Console\Input\InputInterface $input + * @param \Consolidation\AnnotatedCommand\AnnotationData $annotationData + */ + public function initCommands(InputInterface $input, AnnotationData $annotationData) + { + $this->projectDirectory = $input->getOption('project-directory') ?: Drush::bootstrapManager()->getComposerRoot(); + } + + /** + * Define default options for most backend commands. + * + * @hook option @options-backend + * + * @option project-directory The base directory of the project. Defaults to composer root of project. + * + * @param array $options + */ + public function optionsBackend(Command $command, AnnotationData $annotationData) + { + $command->addOption( + 'project-directory', + '', + InputOption::VALUE_NONE, + 'The base directory of the project. Defaults to composer root of project. Option added by burdastyle backend commands.' + ); + } + /** * Prepare file system and code to be ready for install. * @@ -127,12 +157,41 @@ public function updateDatabase() /** * Add option to command. * - * @hook option backend:create-testing-dump backend:install config:export config:import + * @hook option config:export + * + * @param \Symfony\Component\Console\Command\Command $command + * @param \Consolidation\AnnotatedCommand\AnnotationData $annotationData + */ + public function additionalConfigExportOptions(Command $command, AnnotationData $annotationData) + { + $command->addOption( + 'project-directory', + '', + InputOption::VALUE_NONE, + 'The base directory of the project. Defaults to composer root of project. Option added by burdastyle backend commands.' + ); + } + + /** + * @hook init config:export + * + * @param \Symfony\Component\Console\Input\InputInterface $input + * @param \Consolidation\AnnotatedCommand\AnnotationData $annotationData + */ + public function initConfigExportCommands(InputInterface $input, AnnotationData $annotationData) + { + $this->initCommands($input, $annotationData); + } + + /** + * Add option to command. + * + * @hook option config:import * * @param \Symfony\Component\Console\Command\Command $command * @param \Consolidation\AnnotatedCommand\AnnotationData $annotationData */ - public function additionalBackendOptions(Command $command, AnnotationData $annotationData) + public function additionalConfigImportOptions(Command $command, AnnotationData $annotationData) { $command->addOption( 'project-directory', @@ -143,12 +202,12 @@ public function additionalBackendOptions(Command $command, AnnotationData $annot } /** - * @hook init backend:create-testing-dump backend:install config:export config:import + * @hook init config:import * * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Consolidation\AnnotatedCommand\AnnotationData $annotationData */ - public function initBackendCommands(InputInterface $input, AnnotationData $annotationData) + public function initConfigImportCommands(InputInterface $input, AnnotationData $annotationData) { $this->initCommands($input, $annotationData); } diff --git a/BackendCommandsTrait.php b/BackendCommandsTrait.php index c14532b..c7141c7 100644 --- a/BackendCommandsTrait.php +++ b/BackendCommandsTrait.php @@ -7,7 +7,9 @@ use Consolidation\SiteAlias\SiteAliasManagerAwareTrait; use Drupal\Core\Site\Settings; use Drush\Drush; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Filesystem\Path; /** @@ -36,18 +38,6 @@ trait BackendCommandsTrait */ private $projectDirectory; - /** - * Init params. - * - * @param \Symfony\Component\Console\Input\InputInterface $input - * @param \Consolidation\AnnotatedCommand\AnnotationData $annotationData - */ - public function initCommands(InputInterface $input, AnnotationData $annotationData) - { - // Initialize project directory. - $this->projectDirectory = $input->getOption('project-directory') ?: Drush::bootstrapManager()->getComposerRoot(); - } - /** * Drush command wrapper. * From 73286850e44f11c2c4612f29a3eeaba18ff331a0 Mon Sep 17 00:00:00 2001 From: Killesreiter Volker Date: Mon, 26 Aug 2024 14:16:21 +0200 Subject: [PATCH 06/17] Remove sql create and cache rebuild on backend:install --- BackendCommands.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/BackendCommands.php b/BackendCommands.php index 60d1703..eef0846 100644 --- a/BackendCommands.php +++ b/BackendCommands.php @@ -98,10 +98,6 @@ public function preInstallCommand(CommandData $commandData) */ public function install() { - // Cleanup existing installation. - $this->drush($this->selfRecord(), 'sql-create', [], ['yes' => $this->input()->getOption('yes')]); - $this->drush($this->selfRecord(), 'cache:rebuild'); - // Do the site install $this->drush($this->selfRecord(), 'site:install', [], ['existing-config' => true, 'yes' => $this->input()->getOption('yes')]); } From 7b657fda590548cc72c45df670b8c258e9f6159e Mon Sep 17 00:00:00 2001 From: Killesreiter Volker Date: Mon, 26 Aug 2024 14:18:07 +0200 Subject: [PATCH 07/17] add back cache rebuild but after install --- BackendCommands.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/BackendCommands.php b/BackendCommands.php index eef0846..45bec8b 100644 --- a/BackendCommands.php +++ b/BackendCommands.php @@ -98,8 +98,11 @@ public function preInstallCommand(CommandData $commandData) */ public function install() { - // Do the site install + // Do the site install. $this->drush($this->selfRecord(), 'site:install', [], ['existing-config' => true, 'yes' => $this->input()->getOption('yes')]); + + // Clear caches. + $this->drush($this->selfRecord(), 'cache:rebuild'); } /** From 9d5c2889d63bbe720f938868e12a41ff8a2a6348 Mon Sep 17 00:00:00 2001 From: Killesreiter Volker Date: Tue, 27 Aug 2024 10:42:07 +0200 Subject: [PATCH 08/17] create default settings when necessary --- BackendCommands.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/BackendCommands.php b/BackendCommands.php index 45bec8b..3b17d81 100644 --- a/BackendCommands.php +++ b/BackendCommands.php @@ -352,7 +352,32 @@ public function createTestingDump() $dbSpec = $sql->getDbSpec(); $dbUrl = $dbSpec['driver'].'://'.$dbSpec['username'].':'.$dbSpec['password'].'@'.$dbSpec['host'].':'.$dbSpec['port'].'/'.$dbSpec['database']; + $default_settings_file = $this->drupalRootDirectory() . '/sites/default/settings.php'; + if (!file_exists($default_settings_file)) { + $file_string = << '{{ database }}', + 'username' => '{{ username }}', + 'password' => '{{ password }}', + 'prefix' => '', + 'host' => '{{ host }}', + 'port' => '{{ port }}', + 'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql', + 'driver' => '{{ driver }}', +]; +EOF; + $file_string = str_replace(['{{ database }}', '{{ username }}', '{{ password }}', '{{ host }}', '{{ port }}', '{{ driver }}'], [$dbSpec['database'], $dbSpec['username'], $dbSpec['password'], $dbSpec['host'], $dbSpec['port'], $dbSpec['driver']], $file_string); + + $default_settings_file_created = + file_put_contents($default_settings_file, $file_string); + } + $this->process(['php', 'core/scripts/db-tools.php', 'dump-database-d8-mysql', '--database-url', $dbUrl], $this->drupalRootDirectory()); + + if (!empty($default_settings_file_created)) { + unlink($default_settings_file); + } } /** From 4768a46146d1dfb4a62f21c25ed2cc6248f9f6a2 Mon Sep 17 00:00:00 2001 From: Killesreiter Volker Date: Tue, 27 Aug 2024 10:50:18 +0200 Subject: [PATCH 09/17] fix cs --- BackendCommands.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/BackendCommands.php b/BackendCommands.php index 3b17d81..3c06bf3 100644 --- a/BackendCommands.php +++ b/BackendCommands.php @@ -56,7 +56,8 @@ public function initCommands(InputInterface $input, AnnotationData $annotationDa * * @option project-directory The base directory of the project. Defaults to composer root of project. * - * @param array $options + * @param \Symfony\Component\Console\Command\Command $command + * @param \Consolidation\AnnotatedCommand\AnnotationData $annotationData */ public function optionsBackend(Command $command, AnnotationData $annotationData) { @@ -352,9 +353,9 @@ public function createTestingDump() $dbSpec = $sql->getDbSpec(); $dbUrl = $dbSpec['driver'].'://'.$dbSpec['username'].':'.$dbSpec['password'].'@'.$dbSpec['host'].':'.$dbSpec['port'].'/'.$dbSpec['database']; - $default_settings_file = $this->drupalRootDirectory() . '/sites/default/settings.php'; - if (!file_exists($default_settings_file)) { - $file_string = <<drupalRootDirectory().'/sites/default/settings.php'; + if (!file_exists($defaultSettingsFile)) { + $fileString = << '{{ database }}', @@ -367,16 +368,16 @@ public function createTestingDump() 'driver' => '{{ driver }}', ]; EOF; - $file_string = str_replace(['{{ database }}', '{{ username }}', '{{ password }}', '{{ host }}', '{{ port }}', '{{ driver }}'], [$dbSpec['database'], $dbSpec['username'], $dbSpec['password'], $dbSpec['host'], $dbSpec['port'], $dbSpec['driver']], $file_string); + $fileString = str_replace(['{{ database }}', '{{ username }}', '{{ password }}', '{{ host }}', '{{ port }}', '{{ driver }}'], [$dbSpec['database'], $dbSpec['username'], $dbSpec['password'], $dbSpec['host'], $dbSpec['port'], $dbSpec['driver']], $fileString); - $default_settings_file_created = - file_put_contents($default_settings_file, $file_string); + $defaultSettingsFileCreated = + file_put_contents($defaultSettingsFile, $fileString); } $this->process(['php', 'core/scripts/db-tools.php', 'dump-database-d8-mysql', '--database-url', $dbUrl], $this->drupalRootDirectory()); - if (!empty($default_settings_file_created)) { - unlink($default_settings_file); + if (!empty($defaultSettingsFileCreated)) { + unlink($defaultSettingsFile); } } From cc7c31cf1079fb22fa69a9f2dd3078ae96488173 Mon Sep 17 00:00:00 2001 From: Killesreiter Volker Date: Tue, 27 Aug 2024 11:04:39 +0200 Subject: [PATCH 10/17] fix cs 2 --- BackendCommands.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/BackendCommands.php b/BackendCommands.php index 3c06bf3..b3127fd 100644 --- a/BackendCommands.php +++ b/BackendCommands.php @@ -41,8 +41,8 @@ public function __construct() /** * @hook init @options-backend * - * @param \Symfony\Component\Console\Input\InputInterface $input - * @param \Consolidation\AnnotatedCommand\AnnotationData $annotationData + * @param \Symfony\Component\Console\Input\InputInterface $input + * @param \Consolidation\AnnotatedCommand\AnnotationData $annotationData */ public function initCommands(InputInterface $input, AnnotationData $annotationData) { @@ -355,7 +355,7 @@ public function createTestingDump() $defaultSettingsFile = $this->drupalRootDirectory().'/sites/default/settings.php'; if (!file_exists($defaultSettingsFile)) { - $fileString = << '{{ database }}', From 30e6599099bd9b573bbf9dbc2684ccbb8979f2b0 Mon Sep 17 00:00:00 2001 From: Killesreiter Volker Date: Tue, 27 Aug 2024 11:06:13 +0200 Subject: [PATCH 11/17] fix cs 3 --- BackendCommands.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/BackendCommands.php b/BackendCommands.php index b3127fd..3bb71b3 100644 --- a/BackendCommands.php +++ b/BackendCommands.php @@ -41,8 +41,8 @@ public function __construct() /** * @hook init @options-backend * - * @param \Symfony\Component\Console\Input\InputInterface $input - * @param \Consolidation\AnnotatedCommand\AnnotationData $annotationData + * @param \Symfony\Component\Console\Input\InputInterface $input + * @param \Consolidation\AnnotatedCommand\AnnotationData $annotationData */ public function initCommands(InputInterface $input, AnnotationData $annotationData) { @@ -56,7 +56,7 @@ public function initCommands(InputInterface $input, AnnotationData $annotationDa * * @option project-directory The base directory of the project. Defaults to composer root of project. * - * @param \Symfony\Component\Console\Command\Command $command + * @param \Symfony\Component\Console\Command\Command $command * @param \Consolidation\AnnotatedCommand\AnnotationData $annotationData */ public function optionsBackend(Command $command, AnnotationData $annotationData) From a1433e00a2ec015f0301db7737ba27d3c0f1e15e Mon Sep 17 00:00:00 2001 From: Killesreiter Volker Date: Tue, 27 Aug 2024 11:06:57 +0200 Subject: [PATCH 12/17] fix cs 4 --- BackendCommands.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BackendCommands.php b/BackendCommands.php index 3bb71b3..9f8bbdb 100644 --- a/BackendCommands.php +++ b/BackendCommands.php @@ -42,7 +42,7 @@ public function __construct() * @hook init @options-backend * * @param \Symfony\Component\Console\Input\InputInterface $input - * @param \Consolidation\AnnotatedCommand\AnnotationData $annotationData + * @param \Consolidation\AnnotatedCommand\AnnotationData $annotationData */ public function initCommands(InputInterface $input, AnnotationData $annotationData) { From 5d0d3b0ae53255033d515fbea2cd6ce89662f6cc Mon Sep 17 00:00:00 2001 From: Killesreiter Volker Date: Tue, 27 Aug 2024 11:57:32 +0200 Subject: [PATCH 13/17] move around --- BackendCommands.php | 54 ++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/BackendCommands.php b/BackendCommands.php index 9f8bbdb..eac6d19 100644 --- a/BackendCommands.php +++ b/BackendCommands.php @@ -353,31 +353,18 @@ public function createTestingDump() $dbSpec = $sql->getDbSpec(); $dbUrl = $dbSpec['driver'].'://'.$dbSpec['username'].':'.$dbSpec['password'].'@'.$dbSpec['host'].':'.$dbSpec['port'].'/'.$dbSpec['database']; + // Prepare settings file. $defaultSettingsFile = $this->drupalRootDirectory().'/sites/default/settings.php'; - if (!file_exists($defaultSettingsFile)) { - $fileString = << '{{ database }}', - 'username' => '{{ username }}', - 'password' => '{{ password }}', - 'prefix' => '', - 'host' => '{{ host }}', - 'port' => '{{ port }}', - 'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql', - 'driver' => '{{ driver }}', -]; -EOF; - $fileString = str_replace(['{{ database }}', '{{ username }}', '{{ password }}', '{{ host }}', '{{ port }}', '{{ driver }}'], [$dbSpec['database'], $dbSpec['username'], $dbSpec['password'], $dbSpec['host'], $dbSpec['port'], $dbSpec['driver']], $fileString); - - $defaultSettingsFileCreated = - file_put_contents($defaultSettingsFile, $fileString); + if (file_exists($defaultSettingsFile)) { + $tmpName = tempnam( $this->drupalRootDirectory().'/sites/default/', 'settings.tmp'); + rename($defaultSettingsFile, $tmpName); } + $this->prepareSettingsFile($defaultSettingsFile, $dbSpec); $this->process(['php', 'core/scripts/db-tools.php', 'dump-database-d8-mysql', '--database-url', $dbUrl], $this->drupalRootDirectory()); - if (!empty($defaultSettingsFileCreated)) { - unlink($defaultSettingsFile); + if (!empty($tmpName)) { + rename($tmpName, $defaultSettingsFile); } } @@ -500,4 +487,31 @@ private function filesAreEqual($firstFile, $secondFile): bool return true; } + + /** + * Generates default settings file with current db params. + * + * @param $defaultSettingsFile + * @param $dbSpec + * @return void + */ + private function prepareSettingsFile($defaultSettingsFile, $dbSpec) { + + $fileString = << '{{ database }}', + 'username' => '{{ username }}', + 'password' => '{{ password }}', + 'prefix' => '', + 'host' => '{{ host }}', + 'port' => '{{ port }}', + 'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql', + 'driver' => '{{ driver }}', +]; +EOF; + $fileString = str_replace(['{{ database }}', '{{ username }}', '{{ password }}', '{{ host }}', '{{ port }}', '{{ driver }}'], [$dbSpec['database'], $dbSpec['username'], $dbSpec['password'], $dbSpec['host'], $dbSpec['port'], $dbSpec['driver']], $fileString); + file_put_contents($defaultSettingsFile, $fileString, FILE_APPEND); + + } } From 86f6e371397f40deac86b37ebf7d393e56a7ecab Mon Sep 17 00:00:00 2001 From: Killesreiter Volker Date: Wed, 28 Aug 2024 09:19:52 +0200 Subject: [PATCH 14/17] fix cs again --- BackendCommands.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/BackendCommands.php b/BackendCommands.php index eac6d19..6ed3230 100644 --- a/BackendCommands.php +++ b/BackendCommands.php @@ -356,7 +356,7 @@ public function createTestingDump() // Prepare settings file. $defaultSettingsFile = $this->drupalRootDirectory().'/sites/default/settings.php'; if (file_exists($defaultSettingsFile)) { - $tmpName = tempnam( $this->drupalRootDirectory().'/sites/default/', 'settings.tmp'); + $tmpName = tempnam($this->drupalRootDirectory().'/sites/default/', 'settings.tmp'); rename($defaultSettingsFile, $tmpName); } $this->prepareSettingsFile($defaultSettingsFile, $dbSpec); @@ -493,9 +493,11 @@ private function filesAreEqual($firstFile, $secondFile): bool * * @param $defaultSettingsFile * @param $dbSpec + * * @return void */ - private function prepareSettingsFile($defaultSettingsFile, $dbSpec) { + private function prepareSettingsFile($defaultSettingsFile, $dbSpec) + { $fileString = << Date: Wed, 28 Aug 2024 13:20:44 +0200 Subject: [PATCH 15/17] Remove db_url --- BackendCommands.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/BackendCommands.php b/BackendCommands.php index 6ed3230..de53417 100644 --- a/BackendCommands.php +++ b/BackendCommands.php @@ -351,7 +351,6 @@ public function createTestingDump() { $sql = SqlBase::create(); $dbSpec = $sql->getDbSpec(); - $dbUrl = $dbSpec['driver'].'://'.$dbSpec['username'].':'.$dbSpec['password'].'@'.$dbSpec['host'].':'.$dbSpec['port'].'/'.$dbSpec['database']; // Prepare settings file. $defaultSettingsFile = $this->drupalRootDirectory().'/sites/default/settings.php'; @@ -361,7 +360,7 @@ public function createTestingDump() } $this->prepareSettingsFile($defaultSettingsFile, $dbSpec); - $this->process(['php', 'core/scripts/db-tools.php', 'dump-database-d8-mysql', '--database-url', $dbUrl], $this->drupalRootDirectory()); + $this->process(['php', 'core/scripts/db-tools.php', 'dump-database-d8-mysql'], $this->drupalRootDirectory()); if (!empty($tmpName)) { rename($tmpName, $defaultSettingsFile); From 20e16a0daccedf1c501fe4b0075a4f31fbf27b13 Mon Sep 17 00:00:00 2001 From: Killesreiter Volker Date: Wed, 28 Aug 2024 13:40:08 +0200 Subject: [PATCH 16/17] remove settings file --- BackendCommands.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/BackendCommands.php b/BackendCommands.php index de53417..eb824b1 100644 --- a/BackendCommands.php +++ b/BackendCommands.php @@ -362,9 +362,13 @@ public function createTestingDump() $this->process(['php', 'core/scripts/db-tools.php', 'dump-database-d8-mysql'], $this->drupalRootDirectory()); + // Cleanup settings file. if (!empty($tmpName)) { rename($tmpName, $defaultSettingsFile); } + else { + unlink($defaultSettingsFile); + } } /** From 986b389073573f78fa0c5ae634cc2250075d0b15 Mon Sep 17 00:00:00 2001 From: Killesreiter Volker Date: Wed, 28 Aug 2024 13:44:36 +0200 Subject: [PATCH 17/17] fix cs --- BackendCommands.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/BackendCommands.php b/BackendCommands.php index eb824b1..c51c301 100644 --- a/BackendCommands.php +++ b/BackendCommands.php @@ -365,8 +365,7 @@ public function createTestingDump() // Cleanup settings file. if (!empty($tmpName)) { rename($tmpName, $defaultSettingsFile); - } - else { + } else { unlink($defaultSettingsFile); } }