diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 81ca752943..f471313be8 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1190,6 +1190,7 @@ phutil_register_library_map(array( 'HarbormasterLintPropertyView' => 'applications/harbormaster/view/HarbormasterLintPropertyView.php', 'HarbormasterManagementArchiveLogsWorkflow' => 'applications/harbormaster/management/HarbormasterManagementArchiveLogsWorkflow.php', 'HarbormasterManagementBuildWorkflow' => 'applications/harbormaster/management/HarbormasterManagementBuildWorkflow.php', + 'HarbormasterManagementRestartWorkflow' => 'applications/harbormaster/management/HarbormasterManagementRestartWorkflow.php', 'HarbormasterManagementUpdateWorkflow' => 'applications/harbormaster/management/HarbormasterManagementUpdateWorkflow.php', 'HarbormasterManagementWorkflow' => 'applications/harbormaster/management/HarbormasterManagementWorkflow.php', 'HarbormasterMessageType' => 'applications/harbormaster/engine/HarbormasterMessageType.php', @@ -5785,6 +5786,7 @@ phutil_register_library_map(array( 'HarbormasterLintPropertyView' => 'AphrontView', 'HarbormasterManagementArchiveLogsWorkflow' => 'HarbormasterManagementWorkflow', 'HarbormasterManagementBuildWorkflow' => 'HarbormasterManagementWorkflow', + 'HarbormasterManagementRestartWorkflow' => 'HarbormasterManagementWorkflow', 'HarbormasterManagementUpdateWorkflow' => 'HarbormasterManagementWorkflow', 'HarbormasterManagementWorkflow' => 'PhabricatorManagementWorkflow', 'HarbormasterMessageType' => 'Phobject', diff --git a/src/applications/harbormaster/management/HarbormasterManagementRestartWorkflow.php b/src/applications/harbormaster/management/HarbormasterManagementRestartWorkflow.php new file mode 100644 index 0000000000..2a38e10409 --- /dev/null +++ b/src/applications/harbormaster/management/HarbormasterManagementRestartWorkflow.php @@ -0,0 +1,100 @@ +setName('restart') + ->setExamples( + "**restart** --active\n". + '**restart** --id id') + ->setSynopsis(pht('Restart Harbormaster builds.')) + ->setArguments( + array( + array( + 'name' => 'id', + 'param' => 'id', + 'repeat' => true, + 'help' => pht('Select one or more builds by ID.'), + ), + array( + 'name' => 'active', + 'help' => pht('Select all active builds.'), + ), + )); + } + + public function execute(PhutilArgumentParser $args) { + $viewer = $this->getViewer(); + $ids = $args->getArg('id'); + $active = $args->getArg('active'); + + if (!$ids && !$active) { + throw new PhutilArgumentUsageException( + pht('Use --id or --active to select builds.')); + } if ($ids && $active) { + throw new PhutilArgumentUsageException( + pht('Use one of --id or --active to select builds, but not both.')); + } + + $query = id(new HarbormasterBuildQuery()) + ->setViewer($viewer); + if ($ids) { + $query->withIDs($ids); + } else { + $query->withBuildStatuses( + HarbormasterBuildStatus::getActiveStatusConstants()); + } + $builds = $query->execute(); + + $console = PhutilConsole::getConsole(); + $count = count($builds); + if (!$count) { + $console->writeOut("%s\n", pht('No builds to restart.')); + return 0; + } + $prompt = pht('Restart %s build(s)?', new PhutilNumber($count)); + if (!phutil_console_confirm($prompt)) { + $console->writeOut("%s\n", pht('Cancelled.')); + return 1; + } + + $app_phid = id(new PhabricatorHarbormasterApplication())->getPHID(); + $editor = id(new HarbormasterBuildTransactionEditor()) + ->setActor($viewer) + ->setActingAsPHID($app_phid) + ->setContentSource($this->newContentSource()); + foreach ($builds as $build) { + $console->writeOut( + " %s %s\n", + pht('RESTARTING'), + pht('Build %d: %s', $build->getID(), $build->getName())); + if (!$build->canRestartBuild()) { + $console->writeOut( + " %s %s\n", + pht('INVALID'), + pht('Cannot be restarted.')); + continue; + } + $xactions = array(); + $xactions[] = id(new HarbormasterBuildTransaction()) + ->setTransactionType(HarbormasterBuildTransaction::TYPE_COMMAND) + ->setNewValue(HarbormasterBuildCommand::COMMAND_RESTART); + try { + $editor->applyTransactions($build, $xactions); + } catch (Exception $e) { + $message = phutil_console_wrap($e->getMessage(), 2); + $console->writeOut( + " %s \n%s\n", + pht('FAILED'), + $message); + continue; + } + $console->writeOut(" %s \n", pht('SUCCESS')); + } + + return 0; + } + +} diff --git a/src/infrastructure/internationalization/translation/PhabricatorUSEnglishTranslation.php b/src/infrastructure/internationalization/translation/PhabricatorUSEnglishTranslation.php index c65103d4ef..b11f67ceb4 100644 --- a/src/infrastructure/internationalization/translation/PhabricatorUSEnglishTranslation.php +++ b/src/infrastructure/internationalization/translation/PhabricatorUSEnglishTranslation.php @@ -1573,6 +1573,11 @@ final class PhabricatorUSEnglishTranslation '%s updated the invite list for %s, invited %s: %s; uninvinted %s: %s.' => '%s updated the invite list for %s, invited: %4$s; uninvited: %6$s.', + + 'Restart %s build(s)?' => array( + 'Restart %s build?', + 'Restart %s builds?', + ), ); }