@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class HarbormasterManagementRebuildLogWorkflow
4 extends HarbormasterManagementWorkflow {
5
6 protected function didConstruct() {
7 $this
8 ->setName('rebuild-log')
9 ->setExamples(
10 pht(
11 "**rebuild-log** --id __id__ [__options__]\n".
12 "**rebuild-log** --all"))
13 ->setSynopsis(
14 pht(
15 'Rebuild the file and summary for a log. This is primarily '.
16 'intended to make it easier to develop new log summarizers.'))
17 ->setArguments(
18 array(
19 array(
20 'name' => 'id',
21 'param' => 'id',
22 'help' => pht('Log to rebuild.'),
23 ),
24 array(
25 'name' => 'all',
26 'help' => pht('Rebuild all logs.'),
27 ),
28 array(
29 'name' => 'force',
30 'help' => pht(
31 'Force logs to rebuild even if they appear to be in good '.
32 'shape already.'),
33 ),
34 ));
35 }
36
37 public function execute(PhutilArgumentParser $args) {
38 $viewer = $this->getViewer();
39
40 $is_force = $args->getArg('force');
41
42 $log_id = $args->getArg('id');
43 $is_all = $args->getArg('all');
44
45 if (!$is_all && !$log_id) {
46 throw new PhutilArgumentUsageException(
47 pht(
48 'Choose a build log to rebuild with "--id", or rebuild all '.
49 'logs with "--all".'));
50 }
51
52 if ($is_all && $log_id) {
53 throw new PhutilArgumentUsageException(
54 pht(
55 'You can not specify both "--id" and "--all". Choose one or '.
56 'the other.'));
57 }
58
59 if ($log_id) {
60 $log = id(new HarbormasterBuildLogQuery())
61 ->setViewer($viewer)
62 ->withIDs(array($log_id))
63 ->executeOne();
64 if (!$log) {
65 throw new PhutilArgumentUsageException(
66 pht(
67 'Unable to load build log "%s".',
68 $log_id));
69 }
70 $logs = array($log);
71 } else {
72 $logs = new LiskMigrationIterator(new HarbormasterBuildLog());
73 }
74
75 PhabricatorWorker::setRunAllTasksInProcess(true);
76
77 foreach ($logs as $log) {
78 echo tsprintf(
79 "%s\n",
80 pht(
81 'Rebuilding log "%s"...',
82 pht('Build Log %d', $log->getID())));
83
84 try {
85 $log->scheduleRebuild($is_force);
86 } catch (Exception $ex) {
87 if ($is_all) {
88 phlog($ex);
89 } else {
90 throw $ex;
91 }
92 }
93 }
94
95 echo tsprintf(
96 "%s\n",
97 pht('Done.'));
98
99 return 0;
100 }
101
102}