1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 14:52:41 +01:00

Add "--all" and an explicit "--force" flag to bin/harbormaster rebuild-log

Summary: Depends on D19136. Ref T13088. Since it's probably impractical to do all the migrations these changes imply during `bin/storage upgrade`, provide some support for performing them online.

Test Plan: Ran `bin/harbormaster rebuild-log` with `--all`, `--id`, and with and without `--force`.

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13088

Differential Revision: https://secure.phabricator.com/D19137
This commit is contained in:
epriestley 2018-02-23 05:55:52 -08:00
parent 57e3d607f5
commit 46d735d312

View file

@ -6,7 +6,10 @@ final class HarbormasterManagementRebuildLogWorkflow
protected function didConstruct() {
$this
->setName('rebuild-log')
->setExamples('**rebuild-log** --id __id__ [__options__]')
->setExamples(
pht(
"**rebuild-log** --id __id__ [__options__]\n".
"**rebuild-log** --all"))
->setSynopsis(
pht(
'Rebuild the file and summary for a log. This is primarily '.
@ -18,31 +21,76 @@ final class HarbormasterManagementRebuildLogWorkflow
'param' => 'id',
'help' => pht('Log to rebuild.'),
),
array(
'name' => 'all',
'help' => pht('Rebuild all logs.'),
),
array(
'name' => 'force',
'help' => pht(
'Force logs to rebuild even if they appear to be in good '.
'shape already.'),
),
));
}
public function execute(PhutilArgumentParser $args) {
$viewer = $this->getViewer();
$log_id = $args->getArg('id');
if (!$log_id) {
throw new PhutilArgumentUsageException(
pht('Choose a build log to rebuild with "--id".'));
}
$is_force = $args->getArg('force');
$log = id(new HarbormasterBuildLogQuery())
->setViewer($viewer)
->withIDs(array($log_id))
->executeOne();
if (!$log) {
$log_id = $args->getArg('id');
$is_all = $args->getArg('all');
if (!$is_all && !$log_id) {
throw new PhutilArgumentUsageException(
pht(
'Unable to load build log "%s".',
$log_id));
'Choose a build log to rebuild with "--id", or rebuild all '.
'logs with "--all".'));
}
if ($is_all && $log_id) {
throw new PhutilArgumentUsageException(
pht(
'You can not specify both "--id" and "--all". Choose one or '.
'the other.'));
}
if ($log_id) {
$log = id(new HarbormasterBuildLogQuery())
->setViewer($viewer)
->withIDs(array($log_id))
->executeOne();
if (!$log) {
throw new PhutilArgumentUsageException(
pht(
'Unable to load build log "%s".',
$log_id));
}
$logs = array($log);
} else {
$logs = new LiskMigrationIterator(new HarbormasterBuildLog());
}
PhabricatorWorker::setRunAllTasksInProcess(true);
$log->scheduleRebuild(true);
foreach ($logs as $log) {
echo tsprintf(
"%s\n",
pht(
'Rebuilding log "%s"...',
pht('Build Log %d', $log->getID())));
try {
$log->scheduleRebuild($is_force);
} catch (Exception $ex) {
if ($is_all) {
phlog($ex);
} else {
throw $ex;
}
}
}
echo tsprintf(
"%s\n",