From 89ac8020c269f5149280021373f2b6591088eb61 Mon Sep 17 00:00:00 2001 From: Dane Powell Date: Fri, 2 Aug 2024 08:33:12 -0700 Subject: [PATCH] CLI-1370: PHP warning in pull:db when backup fails --- src/Command/Env/EnvCertCreateCommand.php | 6 +++++- src/Command/Env/EnvCreateCommand.php | 5 ++++- src/Command/Env/EnvMirrorCommand.php | 17 +++++++++-------- src/Command/Pull/PullCommandBase.php | 5 ++++- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/Command/Env/EnvCertCreateCommand.php b/src/Command/Env/EnvCertCreateCommand.php index 3b5f763d6..72643f6b2 100644 --- a/src/Command/Env/EnvCertCreateCommand.php +++ b/src/Command/Env/EnvCertCreateCommand.php @@ -6,6 +6,7 @@ use Acquia\Cli\Attribute\RequireAuth; use Acquia\Cli\Command\CommandBase; +use Acquia\Cli\Exception\AcquiaCliException; use AcquiaCloudApi\Endpoints\SslCertificates; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; @@ -53,7 +54,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int $legacy ); $notificationUuid = CommandBase::getNotificationUuidFromResponse($response); - $this->waitForNotificationToComplete($acquiaCloudClient, $notificationUuid, 'Installing certificate'); + $success = $this->waitForNotificationToComplete($acquiaCloudClient, $notificationUuid, 'Installing certificate'); + if (!$success) { + throw new AcquiaCliException('Cloud API failed to install certificate'); + } return Command::SUCCESS; } } diff --git a/src/Command/Env/EnvCreateCommand.php b/src/Command/Env/EnvCreateCommand.php index 19cf133a6..29585fd8c 100644 --- a/src/Command/Env/EnvCreateCommand.php +++ b/src/Command/Env/EnvCreateCommand.php @@ -62,7 +62,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int ]); } }; - $this->waitForNotificationToComplete($acquiaCloudClient, $notificationUuid, "Waiting for the environment to be ready. This usually takes 2 - 15 minutes.", $success); + $success = $this->waitForNotificationToComplete($acquiaCloudClient, $notificationUuid, "Waiting for the environment to be ready. This usually takes 2 - 15 minutes.", $success); + if (!$success) { + throw new AcquiaCliException('Cloud API failed to create environment'); + } return Command::SUCCESS; } diff --git a/src/Command/Env/EnvMirrorCommand.php b/src/Command/Env/EnvMirrorCommand.php index 0b2b871e6..b0e79ac9f 100644 --- a/src/Command/Env/EnvMirrorCommand.php +++ b/src/Command/Env/EnvMirrorCommand.php @@ -6,6 +6,7 @@ use Acquia\Cli\Attribute\RequireAuth; use Acquia\Cli\Command\CommandBase; +use Acquia\Cli\Exception\AcquiaCliException; use Acquia\Cli\Output\Checklist; use AcquiaCloudApi\Connector\Client; use AcquiaCloudApi\Endpoints\Databases; @@ -78,17 +79,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int $configCopyResponse = $this->mirrorConfig($sourceEnvironment, $destinationEnvironment, $environmentsResource, $destinationEnvironmentUuid, $outputCallback); } - if (isset($codeCopyResponse)) { - $this->waitForNotificationToComplete($acquiaCloudClient, CommandBase::getNotificationUuidFromResponse($codeCopyResponse), 'Waiting for code copy to complete'); + if (isset($codeCopyResponse) && !$this->waitForNotificationToComplete($acquiaCloudClient, CommandBase::getNotificationUuidFromResponse($codeCopyResponse), 'Waiting for code copy to complete')) { + throw new AcquiaCliException('Cloud API failed to copy code'); } - if (isset($dbCopyResponse)) { - $this->waitForNotificationToComplete($acquiaCloudClient, CommandBase::getNotificationUuidFromResponse($dbCopyResponse), 'Waiting for database copy to complete'); + if (isset($dbCopyResponse) && !$this->waitForNotificationToComplete($acquiaCloudClient, CommandBase::getNotificationUuidFromResponse($dbCopyResponse), 'Waiting for database copy to complete')) { + throw new AcquiaCliException('Cloud API failed to copy database'); } - if (isset($filesCopyResponse)) { - $this->waitForNotificationToComplete($acquiaCloudClient, CommandBase::getNotificationUuidFromResponse($filesCopyResponse), 'Waiting for files copy to complete'); + if (isset($filesCopyResponse) && !$this->waitForNotificationToComplete($acquiaCloudClient, CommandBase::getNotificationUuidFromResponse($filesCopyResponse), 'Waiting for files copy to complete')) { + throw new AcquiaCliException('Cloud API failed to copy files'); } - if (isset($configCopyResponse)) { - $this->waitForNotificationToComplete($acquiaCloudClient, CommandBase::getNotificationUuidFromResponse($configCopyResponse), 'Waiting for config copy to complete'); + if (isset($configCopyResponse) && !$this->waitForNotificationToComplete($acquiaCloudClient, CommandBase::getNotificationUuidFromResponse($configCopyResponse), 'Waiting for config copy to complete')) { + throw new AcquiaCliException('Cloud API failed to copy config'); } $this->io->success([ diff --git a/src/Command/Pull/PullCommandBase.php b/src/Command/Pull/PullCommandBase.php index 5a12dec73..985166d98 100644 --- a/src/Command/Pull/PullCommandBase.php +++ b/src/Command/Pull/PullCommandBase.php @@ -347,8 +347,11 @@ protected function waitForBackup(string $notificationUuid, Client $acquiaCloudCl $this->output->writeln(''); $this->output->writeln('Database backup is ready!'); }; - $this->waitForNotificationToComplete($acquiaCloudClient, $notificationUuid, $spinnerMessage, $successCallback); + $success = $this->waitForNotificationToComplete($acquiaCloudClient, $notificationUuid, $spinnerMessage, $successCallback); Loop::run(); + if (!$success) { + throw new AcquiaCliException('Cloud API failed to create a backup'); + } } private function connectToLocalDatabase(string $dbHost, string $dbUser, string $dbName, string $dbPassword, callable $outputCallback = null): void