From b043a3204cc9b8a1557764ede5f2bfe2328d394a Mon Sep 17 00:00:00 2001 From: Adam Malone Date: Wed, 22 Apr 2020 12:22:39 +1000 Subject: [PATCH] Adds in the functionality to delete db backups. (#80) --- composer.lock | 53 ++++++-------------------- src/Commands/DbBackupCommand.php | 26 +++++++++++++ tests/AcquiaCliTestCase.php | 3 ++ tests/Commands/DbBackupCommandTest.php | 4 ++ 4 files changed, 45 insertions(+), 41 deletions(-) diff --git a/composer.lock b/composer.lock index ca1a488..ed9dd89 100644 --- a/composer.lock +++ b/composer.lock @@ -2083,34 +2083,20 @@ "portable", "shim" ], - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], "time": "2020-03-09T19:04:49+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.14.0", + "version": "v1.15.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "34094cfa9abe1f0f14f48f490772db7a775559f2" + "reference": "81ffd3a9c6d707be22e3012b827de1c9775fc5ac" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/34094cfa9abe1f0f14f48f490772db7a775559f2", - "reference": "34094cfa9abe1f0f14f48f490772db7a775559f2", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/81ffd3a9c6d707be22e3012b827de1c9775fc5ac", + "reference": "81ffd3a9c6d707be22e3012b827de1c9775fc5ac", "shasum": "" }, "require": { @@ -2122,7 +2108,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.14-dev" + "dev-master": "1.15-dev" } }, "autoload": { @@ -2156,7 +2142,7 @@ "portable", "shim" ], - "time": "2020-01-13T11:15:53+00:00" + "time": "2020-03-09T19:04:49+00:00" }, { "name": "symfony/polyfill-php72", @@ -2211,20 +2197,6 @@ "portable", "shim" ], - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], "time": "2020-02-27T09:26:54+00:00" }, { @@ -2498,16 +2470,16 @@ }, { "name": "typhonius/acquia-php-sdk-v2", - "version": "2.0.9", + "version": "2.0.10", "source": { "type": "git", "url": "https://github.com/typhonius/acquia-php-sdk-v2.git", - "reference": "fbde60e01c8c792e6ae3dd9470a5058605149f4c" + "reference": "b41207e8458dde482c347519f122f41df3109fdd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/typhonius/acquia-php-sdk-v2/zipball/fbde60e01c8c792e6ae3dd9470a5058605149f4c", - "reference": "fbde60e01c8c792e6ae3dd9470a5058605149f4c", + "url": "https://api.github.com/repos/typhonius/acquia-php-sdk-v2/zipball/b41207e8458dde482c347519f122f41df3109fdd", + "reference": "b41207e8458dde482c347519f122f41df3109fdd", "shasum": "" }, "require": { @@ -2542,7 +2514,7 @@ } ], "description": "A PHP SDK for Acquia CloudAPI v2", - "time": "2020-04-20T02:50:46+00:00" + "time": "2020-04-22T00:27:13+00:00" } ], "packages-dev": [ @@ -5118,6 +5090,5 @@ "platform": { "php": ">=7.1" }, - "platform-dev": [], - "plugin-api-version": "1.1.0" + "platform-dev": [] } diff --git a/src/Commands/DbBackupCommand.php b/src/Commands/DbBackupCommand.php index 2cb94fc..7149771 100644 --- a/src/Commands/DbBackupCommand.php +++ b/src/Commands/DbBackupCommand.php @@ -266,4 +266,30 @@ function ( $this->writeln(PHP_EOL); $this->say(sprintf('Database backup downloaded to %s', $location)); } + + /** + * Deletes a database backup. + * + * @param string $uuid + * @param string $environment + * @param string $dbName + * @param int $backupId + * + * @command database:backup:delete + * @aliases db:backup:delete + */ + public function dbBackupDelete(DatabaseBackups $databaseBackupsAdapter, $uuid, $environment, $dbName, $backupId) + { + $environment = $this->cloudapiService->getEnvironment($uuid, $environment); + + if ( + $this->confirm( + sprintf('Are you sure you want to delete backup id %s in %s?', $backupId, $environment->label) + ) + ) { + $this->say(sprintf('Deleting backup %s to %s on %s', $backupId, $dbName, $environment->label)); + $response = $databaseBackupsAdapter->delete($environment->uuid, $dbName, $backupId); + $this->waitForNotification($response); + } + } } diff --git a/tests/AcquiaCliTestCase.php b/tests/AcquiaCliTestCase.php index bede1cd..ed01c3c 100644 --- a/tests/AcquiaCliTestCase.php +++ b/tests/AcquiaCliTestCase.php @@ -351,6 +351,9 @@ public static function getFixtureMap() 'get' => 'Logs/downloadLog.dat', 'post' => 'Logs/createLogSnapshot.json' ], + '/environments/24-a47ac10b-58cc-4372-a567-0e02b2c3d470/databases/dbName/backups/1234' => [ + 'delete' => 'DatabaseBackups/deleteDatabaseBackup.json' + ], '/ides/215824ff-272a-4a8c-9027-df32ed1d68a9' => [ 'delete' => 'Ides/deleteIde.json' ], diff --git a/tests/Commands/DbBackupCommandTest.php b/tests/Commands/DbBackupCommandTest.php index cc179e6..ef9a72e 100644 --- a/tests/Commands/DbBackupCommandTest.php +++ b/tests/Commands/DbBackupCommandTest.php @@ -120,6 +120,10 @@ public function dbBackupProvider() ['database:backup:link', 'devcloud:devcloud2', 'dev', 'dbName', '1234'], $dbLink . PHP_EOL ], + [ + ['database:backup:delete', 'devcloud:devcloud2', 'dev', 'dbName', '1234'], + '> Deleting backup 1234 to dbName on Dev' . PHP_EOL + ], ]; } }