waitAndLog() public static méthode

Wait for a single activity to complete, and display the log continuously.
public static waitAndLog ( Platformsh\Client\Model\Activity $activity, Symfony\Component\Console\Output\OutputInterface $output, string $success = null, string $failure = null ) : boolean
$activity Platformsh\Client\Model\Activity
$output Symfony\Component\Console\Output\OutputInterface
$success string
$failure string
Résultat boolean True if the activity succeeded, false otherwise.
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->validateInput($input);
     $selectedEnvironment = $this->getSelectedEnvironment();
     $environmentId = $selectedEnvironment->id;
     if (!$selectedEnvironment->operationAvailable('backup')) {
         $this->stdErr->writeln("Operation not available: cannot create a snapshot of <error>{$environmentId}</error>");
         if ($selectedEnvironment->is_dirty) {
             $this->api()->clearEnvironmentsCache($selectedEnvironment->project);
         }
         return 1;
     }
     $activity = $selectedEnvironment->backup();
     $this->stdErr->writeln("Creating a snapshot of <info>{$environmentId}</info>");
     if (!$input->getOption('no-wait')) {
         $this->stdErr->writeln("Waiting for the snapshot to complete...");
         $success = ActivityUtil::waitAndLog($activity, $this->stdErr, "A snapshot of environment <info>{$environmentId}</info> has been created", "The snapshot failed");
         if (!$success) {
             return 1;
         }
     }
     if (!empty($activity['payload']['backup_name'])) {
         $name = $activity['payload']['backup_name'];
         $output->writeln("Snapshot name: <info>{$name}</info>");
     }
     return 0;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->validateInput($input);
     if ($input->getOption('list')) {
         return $this->listBackups($output);
     }
     $selectedEnvironment = $this->getSelectedEnvironment();
     $environmentId = $selectedEnvironment['id'];
     if (!$selectedEnvironment->operationAvailable('backup')) {
         $this->stdErr->writeln("Operation not available: the environment <error>{$environmentId}</error> cannot be backed up");
         return 1;
     }
     $activity = $selectedEnvironment->backup();
     $this->stdErr->writeln("Backing up <info>{$environmentId}</info>");
     if (!$input->getOption('no-wait')) {
         $success = ActivityUtil::waitAndLog($activity, $this->stdErr, "A backup of environment <info>{$environmentId}</info> has been created", "The backup failed");
         if (!$success) {
             return 1;
         }
     }
     if (!empty($activity['payload']['backup_name'])) {
         $name = $activity['payload']['backup_name'];
         $output->writeln("Backup name: <info>{$name}</info>");
     }
     return 0;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->validateInput($input);
     $selectedEnvironment = $this->getSelectedEnvironment();
     $environmentId = $selectedEnvironment->id;
     if (!$selectedEnvironment->operationAvailable('merge')) {
         $this->stdErr->writeln("Operation not available: The environment <error>{$environmentId}</error> can't be merged.");
         return 1;
     }
     $parentId = $selectedEnvironment->parent;
     $confirmText = "Are you sure you want to merge <info>{$environmentId}</info> with its parent, <info>{$parentId}</info>?";
     if (!$this->getHelper('question')->confirm($confirmText)) {
         return 1;
     }
     $this->stdErr->writeln("Merging <info>{$environmentId}</info> with <info>{$parentId}</info>");
     $this->api()->clearEnvironmentsCache($selectedEnvironment->project);
     $activity = $selectedEnvironment->merge();
     if (!$input->getOption('no-wait')) {
         $success = ActivityUtil::waitAndLog($activity, $this->stdErr, 'Merge complete', 'Merge failed');
         if (!$success) {
             return 1;
         }
     }
     return 0;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (!$this->validateInput($input, $output)) {
         return 1;
     }
     $selectedEnvironment = $this->getSelectedEnvironment();
     $environmentId = $selectedEnvironment['id'];
     if (!$selectedEnvironment->operationAvailable('merge')) {
         $output->writeln("Operation not available: The environment <error>{$environmentId}</error> can't be merged.");
         return 1;
     }
     $parentId = $selectedEnvironment['parent'];
     if (!$this->getHelper('question')->confirm("Are you sure you want to merge <info>{$environmentId}</info> with its parent, <info>{$parentId}</info>?", $input, $output)) {
         return 0;
     }
     $output->writeln("Merging <info>{$environmentId}</info> with <info>{$parentId}</info>");
     $activity = $selectedEnvironment->merge();
     if (!$input->getOption('no-wait')) {
         $success = ActivityUtil::waitAndLog($activity, $output, 'Merge complete', 'Merge failed');
         if (!$success) {
             return 1;
         }
     }
     // Reload the stored environments.
     $this->getEnvironments(null, true);
     return 0;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (!$this->validateInput($input, $output)) {
         return 1;
     }
     $environment = $this->getSelectedEnvironment();
     $backupName = $input->getArgument('backup');
     if (!empty($backupName)) {
         // Find the specified backup.
         $backupActivities = $environment->getActivities(0, 'environment.backup');
         foreach ($backupActivities as $activity) {
             if ($activity['payload']['backup_name'] == $backupName) {
                 $selectedActivity = $activity;
                 break;
             }
         }
         if (empty($selectedActivity)) {
             $output->writeln("Backup not found: <error>{$backupName}</error>");
             return 1;
         }
     } else {
         // Find the most recent backup.
         $environmentId = $environment['id'];
         $output->writeln("Finding the most recent backup for the environment <info>{$environmentId}</info>");
         $backupActivities = $environment->getActivities(1, 'environment.backup');
         if (!$backupActivities) {
             $output->writeln("No backups found");
             return 1;
         }
         /** @var \Platformsh\Client\Model\Activity $selectedActivity */
         $selectedActivity = reset($backupActivities);
     }
     if (!$selectedActivity->operationAvailable('restore')) {
         if (!$selectedActivity->isComplete()) {
             $output->writeln("The backup is not complete, so it cannot be restored");
         } else {
             $output->writeln("The backup cannot be restored");
         }
         return 1;
     }
     /** @var \Platformsh\Cli\Helper\PlatformQuestionHelper $questionHelper */
     $questionHelper = $this->getHelper('question');
     $name = $selectedActivity['payload']['backup_name'];
     $environmentId = $environment['id'];
     $date = date('Y-m-d H:i', strtotime($selectedActivity['created_at']));
     if (!$questionHelper->confirm("Are you sure you want to restore the backup <comment>{$name}</comment> from <comment>{$date}</comment>?", $input, $output)) {
         return 1;
     }
     $output->writeln("Restoring backup <info>{$name}</info>");
     $activity = $selectedActivity->restore();
     if (!$input->getOption('no-wait')) {
         $success = ActivityUtil::waitAndLog($activity, $output, "The backup was successfully restored", "Restoring failed");
         if (!$success) {
             return 1;
         }
     }
     return 0;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->validateInput($input);
     $selectedEnvironment = $this->getSelectedEnvironment();
     $environmentId = $selectedEnvironment->id;
     if (!$selectedEnvironment->operationAvailable('synchronize')) {
         $this->stdErr->writeln("Operation not available: The environment <error>{$environmentId}</error> can't be synchronized.");
         if ($selectedEnvironment->is_dirty) {
             $this->api()->clearEnvironmentsCache($selectedEnvironment->project);
         }
         return 1;
     }
     $parentId = $selectedEnvironment->parent;
     $questionHelper = $this->getHelper('question');
     if ($synchronize = $input->getArgument('synchronize')) {
         // The input was invalid.
         if (array_diff($input->getArgument('synchronize'), ['code', 'data', 'both'])) {
             $this->stdErr->writeln("Specify 'code', 'data', or 'both'");
             return 1;
         }
         $syncCode = in_array('code', $synchronize) || in_array('both', $synchronize);
         $syncData = in_array('data', $synchronize) || in_array('both', $synchronize);
         $confirmText = "Are you sure you want to synchronize <info>{$parentId}</info> to <info>{$environmentId}</info>?";
         if (!$questionHelper->confirm($confirmText)) {
             return 1;
         }
     } else {
         $syncCode = $questionHelper->confirm("Synchronize code from <info>{$parentId}</info> to <info>{$environmentId}</info>?", false);
         $syncData = $questionHelper->confirm("Synchronize data from <info>{$parentId}</info> to <info>{$environmentId}</info>?", false);
     }
     if (!$syncCode && !$syncData) {
         $this->stdErr->writeln("<error>You must synchronize at least code or data.</error>");
         return 1;
     }
     $this->stdErr->writeln("Synchronizing environment <info>{$environmentId}</info>");
     $activity = $selectedEnvironment->synchronize($syncData, $syncCode);
     if (!$input->getOption('no-wait')) {
         $success = ActivityUtil::waitAndLog($activity, $this->stdErr, "Synchronization complete", "Synchronization failed");
         if (!$success) {
             return 1;
         }
     }
     return 0;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->envArgName = 'parent';
     $this->validateInput($input, true);
     $selectedProject = $this->getSelectedProject();
     $branchName = $input->getArgument('name');
     if (empty($branchName)) {
         if ($input->isInteractive()) {
             // List environments.
             return $this->runOtherCommand('environments', array('--project' => $selectedProject->id));
         }
         $this->stdErr->writeln("<error>You must specify the name of the new branch.</error>");
         return 1;
     }
     $machineName = Environment::sanitizeId($branchName);
     $environmentId = $this->getSelectedEnvironment()['id'];
     if ($machineName == $environmentId) {
         $this->stdErr->writeln("<comment>Already on {$machineName}</comment>");
         return 1;
     }
     if ($environment = $this->getEnvironment($machineName, $selectedProject)) {
         $checkout = $this->getHelper('question')->confirm("The environment <comment>{$machineName}</comment> already exists. Check out?", $input, $this->stdErr);
         if ($checkout) {
             return $this->runOtherCommand('environment:checkout', array('id' => $environment->id));
         }
         return 1;
     }
     if (!$this->getSelectedEnvironment()->operationAvailable('branch')) {
         $this->stdErr->writeln("Operation not available: The environment <error>{$environmentId}</error> can't be branched.");
         return 1;
     }
     $force = $input->getOption('force');
     $projectRoot = $this->getProjectRoot();
     if (!$projectRoot && $force) {
         $this->stdErr->writeln("<comment>This command was run from outside your local project root, the new Platform.sh branch cannot be checked out in your local Git repository." . " Make sure to run 'platform checkout' or 'git checkout' in your repository directory to switch to the branch you are expecting.</comment>");
         $local_error = true;
     } elseif (!$projectRoot) {
         $this->stdErr->writeln("<error>You must run this command inside the project root, or specify --force.</error>");
         return 1;
     }
     $selectedEnvironment = $this->getSelectedEnvironment();
     $this->stdErr->writeln("Creating a new environment <info>{$branchName}</info>, branched from <info>{$selectedEnvironment['title']}</info>");
     $activity = $selectedEnvironment->branch($branchName, $machineName);
     // Clear the environments cache, as branching has started.
     $this->clearEnvironmentsCache($selectedProject);
     if ($projectRoot) {
         $gitHelper = new GitHelper(new ShellHelper($this->stdErr));
         $gitHelper->setDefaultRepositoryDir($projectRoot . '/' . LocalProject::REPOSITORY_DIR);
         // If the Git branch already exists locally, just check it out.
         $existsLocally = $gitHelper->branchExists($machineName);
         if ($existsLocally) {
             $this->stdErr->writeln("Checking out <info>{$machineName}</info> locally");
             if (!$gitHelper->checkOut($machineName)) {
                 $this->stdErr->writeln('<error>Failed to check out branch locally: ' . $machineName . '</error>');
                 $local_error = true;
                 if (!$force) {
                     return 1;
                 }
             }
         } else {
             // Create a new branch, using the current or specified environment as the parent if it exists locally.
             $parent = $this->getSelectedEnvironment()['id'];
             if (!$gitHelper->branchExists($parent)) {
                 $parent = null;
             }
             $this->stdErr->writeln("Creating local branch <info>{$machineName}</info>");
             if (!$gitHelper->checkOutNew($machineName, $parent)) {
                 $this->stdErr->writeln('<error>Failed to create branch locally: ' . $machineName . '</error>');
                 $local_error = true;
                 if (!$force) {
                     return 1;
                 }
             }
         }
     }
     $remoteSuccess = true;
     if (!$input->getOption('no-wait')) {
         $remoteSuccess = ActivityUtil::waitAndLog($activity, $this->stdErr, "The environment <info>{$branchName}</info> has been branched.", '<error>Branching failed</error>');
         // Clear the environments cache again.
         $this->clearEnvironmentsCache($selectedProject);
     }
     $build = $input->getOption('build');
     if (empty($local_error) && $build && $projectRoot) {
         // Build the new branch.
         try {
             $buildSettings = array('environmentId' => $machineName, 'verbosity' => $output->getVerbosity());
             $builder = new LocalBuild($buildSettings, $output);
             $builder->buildProject($projectRoot);
         } catch (\Exception $e) {
             $this->stdErr->writeln("<comment>The new branch could not be built: \n" . $e->getMessage() . "</comment>");
             return 1;
         }
     }
     $this->clearEnvironmentsCache();
     return $remoteSuccess ? 0 : 1;
 }