Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI-1257: pull:db fails with too many tables #1674

Merged
merged 3 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Command/Pull/PullCommandBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,9 @@
$tables = $this->listTablesQuoted($process->getOutput());
if ($tables) {
$sql = 'DROP TABLE ' . implode(', ', $tables);
$tempnam = $this->localMachineHelper->getFilesystem()->tempnam(sys_get_temp_dir(), 'acli_drop_table_', '.sql');
$this->localMachineHelper->getFilesystem()->dumpFile($tempnam, $sql);
$command = [

Check warning on line 387 in src/Command/Pull/PullCommandBase.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "ArrayItemRemoval": --- Original +++ New @@ @@ $sql = 'DROP TABLE ' . implode(', ', $tables); $tempnam = $this->localMachineHelper->getFilesystem()->tempnam(sys_get_temp_dir(), 'acli_drop_table_', '.sql'); $this->localMachineHelper->getFilesystem()->dumpFile($tempnam, $sql); - $command = ['mysql', '--host', $dbHost, '--user', $dbUser, $dbName, '-e', 'source ' . $tempnam]; + $command = ['--host', $dbHost, '--user', $dbUser, $dbName, '-e', 'source ' . $tempnam]; $process = $this->localMachineHelper->execute($command, $outputCallback, NULL, FALSE, NULL, ['MYSQL_PWD' => $dbPassword]); if (!$process->isSuccessful()) { throw new AcquiaCliException('Unable to drop tables from database. {message}', ['message' => $process->getErrorOutput()]);
'mysql',
'--host',
$dbHost,
Expand All @@ -390,7 +392,7 @@
$dbUser,
$dbName,
'-e',
$sql,
'source ' . $tempnam,

Check warning on line 395 in src/Command/Pull/PullCommandBase.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "Concat": --- Original +++ New @@ @@ $sql = 'DROP TABLE ' . implode(', ', $tables); $tempnam = $this->localMachineHelper->getFilesystem()->tempnam(sys_get_temp_dir(), 'acli_drop_table_', '.sql'); $this->localMachineHelper->getFilesystem()->dumpFile($tempnam, $sql); - $command = ['mysql', '--host', $dbHost, '--user', $dbUser, $dbName, '-e', 'source ' . $tempnam]; + $command = ['mysql', '--host', $dbHost, '--user', $dbUser, $dbName, '-e', $tempnam . 'source ']; $process = $this->localMachineHelper->execute($command, $outputCallback, NULL, FALSE, NULL, ['MYSQL_PWD' => $dbPassword]); if (!$process->isSuccessful()) { throw new AcquiaCliException('Unable to drop tables from database. {message}', ['message' => $process->getErrorOutput()]);

Check warning on line 395 in src/Command/Pull/PullCommandBase.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "ConcatOperandRemoval": --- Original +++ New @@ @@ $sql = 'DROP TABLE ' . implode(', ', $tables); $tempnam = $this->localMachineHelper->getFilesystem()->tempnam(sys_get_temp_dir(), 'acli_drop_table_', '.sql'); $this->localMachineHelper->getFilesystem()->dumpFile($tempnam, $sql); - $command = ['mysql', '--host', $dbHost, '--user', $dbUser, $dbName, '-e', 'source ' . $tempnam]; + $command = ['mysql', '--host', $dbHost, '--user', $dbUser, $dbName, '-e', 'source ']; $process = $this->localMachineHelper->execute($command, $outputCallback, NULL, FALSE, NULL, ['MYSQL_PWD' => $dbPassword]); if (!$process->isSuccessful()) { throw new AcquiaCliException('Unable to drop tables from database. {message}', ['message' => $process->getErrorOutput()]);

Check warning on line 395 in src/Command/Pull/PullCommandBase.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "ConcatOperandRemoval": --- Original +++ New @@ @@ $sql = 'DROP TABLE ' . implode(', ', $tables); $tempnam = $this->localMachineHelper->getFilesystem()->tempnam(sys_get_temp_dir(), 'acli_drop_table_', '.sql'); $this->localMachineHelper->getFilesystem()->dumpFile($tempnam, $sql); - $command = ['mysql', '--host', $dbHost, '--user', $dbUser, $dbName, '-e', 'source ' . $tempnam]; + $command = ['mysql', '--host', $dbHost, '--user', $dbUser, $dbName, '-e', $tempnam]; $process = $this->localMachineHelper->execute($command, $outputCallback, NULL, FALSE, NULL, ['MYSQL_PWD' => $dbPassword]); if (!$process->isSuccessful()) { throw new AcquiaCliException('Unable to drop tables from database. {message}', ['message' => $process->getErrorOutput()]);
];
$process = $this->localMachineHelper->execute($command, $outputCallback, NULL, FALSE, NULL, ['MYSQL_PWD' => $dbPassword]);
if (!$process->isSuccessful()) {
Expand Down
27 changes: 18 additions & 9 deletions tests/phpunit/src/Commands/Pull/PullDatabaseCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ public function testPullDatabases(): void {
$this->mockListSites($sshHelper);
$this->mockGetBackup($environment);
$this->mockExecuteMySqlListTables($localMachineHelper, 'drupal');
$this->mockExecuteMySqlDropDb($localMachineHelper, TRUE);
$this->mockExecuteMySqlImport($localMachineHelper, TRUE, TRUE, 'my_db', 'my_dbdev', 'drupal');
$fs = $this->prophet->prophesize(Filesystem::class);
$this->mockExecuteMySqlDropDb($localMachineHelper, TRUE, $fs);
$this->mockExecuteMySqlImport($localMachineHelper, TRUE, TRUE, 'my_db', 'my_dbdev', 'drupal');
$fs->remove(Argument::type('string'))->shouldBeCalled();
$localMachineHelper->getFilesystem()->willReturn($fs)->shouldBeCalled();

$this->executeCommand([
Expand Down Expand Up @@ -107,10 +108,11 @@ public function testPullDatabaseNoPv(): void {
$this->mockListSites($sshHelper);
$this->mockGetBackup($environment);
$this->mockExecuteMySqlListTables($localMachineHelper, 'drupal');
$this->mockExecuteMySqlDropDb($localMachineHelper, TRUE);
$this->mockExecuteMySqlImport($localMachineHelper, TRUE, FALSE, 'my_db', 'my_dbdev', 'drupal');
$fs = $this->prophet->prophesize(Filesystem::class);
$localMachineHelper->getFilesystem()->willReturn($fs)->shouldBeCalled();
$this->mockExecuteMySqlDropDb($localMachineHelper, TRUE, $fs);
$this->mockExecuteMySqlImport($localMachineHelper, TRUE, FALSE, 'my_db', 'my_dbdev', 'drupal');
$fs->remove(Argument::type('string'))->shouldBeCalled();

$this->executeCommand([
'--no-scripts' => TRUE,
Expand Down Expand Up @@ -208,7 +210,9 @@ public function testPullDatabaseWithMySqlDropError(): void {
$this->mockListSites($sshHelper);
$this->mockGetBackup($environment);
$this->mockExecuteMySqlListTables($localMachineHelper, 'drupal');
$this->mockExecuteMySqlDropDb($localMachineHelper, FALSE);
$fs = $this->prophet->prophesize(Filesystem::class);
$localMachineHelper->getFilesystem()->willReturn($fs)->shouldBeCalled();
$this->mockExecuteMySqlDropDb($localMachineHelper, FALSE, $fs);

$this->expectException(AcquiaCliException::class);
$this->expectExceptionMessage('Unable to drop tables from database');
Expand All @@ -225,7 +229,9 @@ public function testPullDatabaseWithMySqlImportError(): void {
$this->mockListSites($sshHelper);
$this->mockGetBackup($environment);
$this->mockExecuteMySqlListTables($localMachineHelper, 'drupal');
$this->mockExecuteMySqlDropDb($localMachineHelper, TRUE);
$fs = $this->prophet->prophesize(Filesystem::class);
$localMachineHelper->getFilesystem()->willReturn($fs)->shouldBeCalled();
$this->mockExecuteMySqlDropDb($localMachineHelper, TRUE, $fs);
$this->mockExecuteMySqlImport($localMachineHelper, FALSE, TRUE, 'my_db', 'my_dbdev', 'drupal');

$this->expectException(AcquiaCliException::class);
Expand Down Expand Up @@ -286,12 +292,12 @@ protected function setupPullDatabase(bool $mysqlConnectSuccessful, bool $mockIde
// Mock IDE filesystem.
if ($mockIdeFs) {
$this->mockDrupalSettingsRefresh($localMachineHelper);
$this->mockSettingsFiles($fs);
}
$this->mockSettingsFiles($fs);

// Database.
$this->mockExecuteMySqlListTables($localMachineHelper);
$this->mockExecuteMySqlDropDb($localMachineHelper, TRUE);
$this->mockExecuteMySqlDropDb($localMachineHelper, TRUE, $fs);
$this->mockExecuteMySqlImport($localMachineHelper, TRUE, TRUE);
if ($multiDb) {
$this->mockExecuteMySqlListTables($localMachineHelper, 'drupal');
Expand Down Expand Up @@ -357,10 +363,13 @@ protected function mockExecuteMySqlListTables(

protected function mockExecuteMySqlDropDb(
LocalMachineHelper|ObjectProphecy $localMachineHelper,
bool $success
bool $success,
ObjectProphecy $fs
): void {
$localMachineHelper->checkRequiredBinariesExist(["mysql"])->shouldBeCalled();
$process = $this->mockProcess($success);
$fs->tempnam(Argument::type('string'), 'acli_drop_table_', '.sql')->willReturn('something')->shouldBeCalled();
$fs->dumpfile('something', Argument::type('string'))->shouldBeCalled();
$localMachineHelper
->execute(Argument::type('array'), Argument::type('callable'), NULL, FALSE, NULL, ['MYSQL_PWD' => $this->dbPassword])
->willReturn($process->reveal())
Expand Down