Skip to content

Commit

Permalink
Clean up: remove use of deprecated method in backup:create command
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pjcdawkins committed Dec 11, 2023
1 parent 9ae43d6 commit 08168fb
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/Command/Backup/BackupCreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <info>live</info> backup of <info>$environmentId</info>");
Expand All @@ -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: <info>$name</info>");
foreach ($activities as $activity) {
if ($activity->type === 'environment.backup' && !empty($activity->payload['backup_name'])) {
$output->writeln(\sprintf('Backup name: <info>%s</info>', $activity->payload['backup_name']));
break;
}
}

return 0;
Expand Down

0 comments on commit 08168fb

Please sign in to comment.