Path: blob/master/src/applications/harbormaster/management/HarbormasterManagementRebuildLogWorkflow.php
12256 views
<?php12final class HarbormasterManagementRebuildLogWorkflow3extends HarbormasterManagementWorkflow {45protected function didConstruct() {6$this7->setName('rebuild-log')8->setExamples(9pht(10"**rebuild-log** --id __id__ [__options__]\n".11"**rebuild-log** --all"))12->setSynopsis(13pht(14'Rebuild the file and summary for a log. This is primarily '.15'intended to make it easier to develop new log summarizers.'))16->setArguments(17array(18array(19'name' => 'id',20'param' => 'id',21'help' => pht('Log to rebuild.'),22),23array(24'name' => 'all',25'help' => pht('Rebuild all logs.'),26),27array(28'name' => 'force',29'help' => pht(30'Force logs to rebuild even if they appear to be in good '.31'shape already.'),32),33));34}3536public function execute(PhutilArgumentParser $args) {37$viewer = $this->getViewer();3839$is_force = $args->getArg('force');4041$log_id = $args->getArg('id');42$is_all = $args->getArg('all');4344if (!$is_all && !$log_id) {45throw new PhutilArgumentUsageException(46pht(47'Choose a build log to rebuild with "--id", or rebuild all '.48'logs with "--all".'));49}5051if ($is_all && $log_id) {52throw new PhutilArgumentUsageException(53pht(54'You can not specify both "--id" and "--all". Choose one or '.55'the other.'));56}5758if ($log_id) {59$log = id(new HarbormasterBuildLogQuery())60->setViewer($viewer)61->withIDs(array($log_id))62->executeOne();63if (!$log) {64throw new PhutilArgumentUsageException(65pht(66'Unable to load build log "%s".',67$log_id));68}69$logs = array($log);70} else {71$logs = new LiskMigrationIterator(new HarbormasterBuildLog());72}7374PhabricatorWorker::setRunAllTasksInProcess(true);7576foreach ($logs as $log) {77echo tsprintf(78"%s\n",79pht(80'Rebuilding log "%s"...',81pht('Build Log %d', $log->getID())));8283try {84$log->scheduleRebuild($is_force);85} catch (Exception $ex) {86if ($is_all) {87phlog($ex);88} else {89throw $ex;90}91}92}9394echo tsprintf(95"%s\n",96pht('Done.'));9798return 0;99}100101}102103104