Skip to content

Commit

Permalink
move around
Browse files Browse the repository at this point in the history
  • Loading branch information
ol0lll committed Aug 27, 2024
1 parent a1433e0 commit 5d0d3b0
Showing 1 changed file with 34 additions and 20 deletions.
54 changes: 34 additions & 20 deletions BackendCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <<<EOF
<?php
\$databases['default']['default'] = [
'database' => '{{ 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');

Check failure on line 359 in BackendCommands.php

View workflow job for this annotation

GitHub Actions / PHPCS

Space after opening parenthesis of function call prohibited

Check failure on line 359 in BackendCommands.php

View workflow job for this annotation

GitHub Actions / PHPCS

Space after opening parenthesis of function call prohibited
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);
}
}

Expand Down Expand Up @@ -500,4 +487,31 @@ private function filesAreEqual($firstFile, $secondFile): bool

return true;
}

/**
* Generates default settings file with current db params.
*
* @param $defaultSettingsFile
* @param $dbSpec

Check failure on line 495 in BackendCommands.php

View workflow job for this annotation

GitHub Actions / PHPCS

Group annotations together so that annotations of the same type immediately follow each other, and annotations of a different type are separated by a single blank line
* @return void
*/
private function prepareSettingsFile($defaultSettingsFile, $dbSpec) {

Check failure on line 498 in BackendCommands.php

View workflow job for this annotation

GitHub Actions / PHPCS

Opening brace should be on a new line

$fileString = <<<EOF
<?php
\$databases['default']['default'] = [
'database' => '{{ 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);

}

Check failure on line 516 in BackendCommands.php

View workflow job for this annotation

GitHub Actions / PHPCS

Function closing brace must go on the next line following the body; found 1 blank lines before brace
}

0 comments on commit 5d0d3b0

Please sign in to comment.