From 08168fba31436f2d84ac467acf4b42c625a7dcc7 Mon Sep 17 00:00:00 2001 From: Patrick Dawkins Date: Mon, 11 Dec 2023 15:32:33 +0000 Subject: [PATCH] Clean up: remove use of deprecated method in backup:create command This now accounts for more than one activity potentially being returned by the server, which is not currently the case, but it is a better treatment of the API. --- src/Command/Backup/BackupCreateCommand.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Command/Backup/BackupCreateCommand.php b/src/Command/Backup/BackupCreateCommand.php index 3f83c898b..338d943a3 100644 --- a/src/Command/Backup/BackupCreateCommand.php +++ b/src/Command/Backup/BackupCreateCommand.php @@ -65,7 +65,11 @@ protected function execute(InputInterface $input, OutputInterface $output) $live = $input->getOption('live') || $input->getOption('unsafe'); - $activity = $selectedEnvironment->backup($live); + $result = $selectedEnvironment->runOperation('backup', 'POST', ['safe' => !$live]); + + // Hold the activities as a reference as they may be updated during + // waitMultiple() below, allowing the backup_name to be extracted. + $activities = $result->getActivities(); if ($live) { $this->stdErr->writeln("Creating a live backup of $environmentId"); @@ -83,15 +87,17 @@ protected function execute(InputInterface $input, OutputInterface $output) /** @var \Platformsh\Cli\Service\ActivityMonitor $activityMonitor */ $activityMonitor = $this->getService('activity_monitor'); - $success = $activityMonitor->waitAndLog($activity); + $success = $activityMonitor->waitMultiple($activities, $this->getSelectedProject()); if (!$success) { return 1; } } - if (!empty($activity['payload']['backup_name'])) { - $name = $activity['payload']['backup_name']; - $output->writeln("Backup name: $name"); + foreach ($activities as $activity) { + if ($activity->type === 'environment.backup' && !empty($activity->payload['backup_name'])) { + $output->writeln(\sprintf('Backup name: %s', $activity->payload['backup_name'])); + break; + } } return 0;