mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 08:42: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:
parent
57e3d607f5
commit
46d735d312
1 changed files with 62 additions and 14 deletions
|
@ -6,7 +6,10 @@ final class HarbormasterManagementRebuildLogWorkflow
|
||||||
protected function didConstruct() {
|
protected function didConstruct() {
|
||||||
$this
|
$this
|
||||||
->setName('rebuild-log')
|
->setName('rebuild-log')
|
||||||
->setExamples('**rebuild-log** --id __id__ [__options__]')
|
->setExamples(
|
||||||
|
pht(
|
||||||
|
"**rebuild-log** --id __id__ [__options__]\n".
|
||||||
|
"**rebuild-log** --all"))
|
||||||
->setSynopsis(
|
->setSynopsis(
|
||||||
pht(
|
pht(
|
||||||
'Rebuild the file and summary for a log. This is primarily '.
|
'Rebuild the file and summary for a log. This is primarily '.
|
||||||
|
@ -18,31 +21,76 @@ final class HarbormasterManagementRebuildLogWorkflow
|
||||||
'param' => 'id',
|
'param' => 'id',
|
||||||
'help' => pht('Log to rebuild.'),
|
'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) {
|
public function execute(PhutilArgumentParser $args) {
|
||||||
$viewer = $this->getViewer();
|
$viewer = $this->getViewer();
|
||||||
|
|
||||||
$log_id = $args->getArg('id');
|
$is_force = $args->getArg('force');
|
||||||
if (!$log_id) {
|
|
||||||
throw new PhutilArgumentUsageException(
|
|
||||||
pht('Choose a build log to rebuild with "--id".'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$log = id(new HarbormasterBuildLogQuery())
|
$log_id = $args->getArg('id');
|
||||||
->setViewer($viewer)
|
$is_all = $args->getArg('all');
|
||||||
->withIDs(array($log_id))
|
|
||||||
->executeOne();
|
if (!$is_all && !$log_id) {
|
||||||
if (!$log) {
|
|
||||||
throw new PhutilArgumentUsageException(
|
throw new PhutilArgumentUsageException(
|
||||||
pht(
|
pht(
|
||||||
'Unable to load build log "%s".',
|
'Choose a build log to rebuild with "--id", or rebuild all '.
|
||||||
$log_id));
|
'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);
|
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(
|
echo tsprintf(
|
||||||
"%s\n",
|
"%s\n",
|
||||||
|
|
Loading…
Reference in a new issue