Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / repository / management / PhabricatorRepositoryManagementMaintenanceWorkflow.php
blob65fe0adaad7499b7b6de36a7c68bd773422e3ff3
1 <?php
3 final class PhabricatorRepositoryManagementMaintenanceWorkflow
4 extends PhabricatorRepositoryManagementWorkflow {
6 protected function didConstruct() {
7 $this
8 ->setName('maintenance')
9 ->setExamples(
10 "**maintenance** --start __message__ __repository__ ...\n".
11 "**maintenance** --stop __repository__")
12 ->setSynopsis(
13 pht('Set or clear read-only mode for repository maintenance.'))
14 ->setArguments(
15 array(
16 array(
17 'name' => 'start',
18 'param' => 'message',
19 'help' => pht(
20 'Put repositories into maintenance mode.'),
22 array(
23 'name' => 'stop',
24 'help' => pht(
25 'Take repositories out of maintenance mode, returning them '.
26 'to normal serice.'),
28 array(
29 'name' => 'repositories',
30 'wildcard' => true,
32 ));
35 public function execute(PhutilArgumentParser $args) {
36 $viewer = $this->getViewer();
38 $repositories = $this->loadRepositories($args, 'repositories');
39 if (!$repositories) {
40 throw new PhutilArgumentUsageException(
41 pht('Specify one or more repositories to act on.'));
44 $message = $args->getArg('start');
45 $is_start = (bool)strlen($message);
46 $is_stop = $args->getArg('stop');
48 if (!$is_start && !$is_stop) {
49 throw new PhutilArgumentUsageException(
50 pht(
51 'Use "--start <message>" to put repositories into maintenance '.
52 'mode, or "--stop" to take them out of maintenance mode.'));
55 if ($is_start && $is_stop) {
56 throw new PhutilArgumentUsageException(
57 pht(
58 'Specify either "--start" or "--stop", but not both.'));
61 $content_source = $this->newContentSource();
62 $diffusion_phid = id(new PhabricatorDiffusionApplication())->getPHID();
64 if ($is_start) {
65 $new_value = $message;
66 } else {
67 $new_value = null;
70 foreach ($repositories as $repository) {
71 $xactions = array();
73 $xactions[] = $repository->getApplicationTransactionTemplate()
74 ->setTransactionType(
75 PhabricatorRepositoryMaintenanceTransaction::TRANSACTIONTYPE)
76 ->setNewValue($new_value);
78 $repository->getApplicationTransactionEditor()
79 ->setActor($viewer)
80 ->setActingAsPHID($diffusion_phid)
81 ->setContentSource($content_source)
82 ->setContinueOnNoEffect(true)
83 ->setContinueOnMissingFields(true)
84 ->applyTransactions($repository, $xactions);
86 if ($is_start) {
87 echo tsprintf(
88 "%s\n",
89 pht(
90 'Put repository "%s" into maintenance mode.',
91 $repository->getDisplayName()));
92 } else {
93 echo tsprintf(
94 "%s\n",
95 pht(
96 'Took repository "%s" out of maintenance mode.',
97 $repository->getDisplayName()));
101 return 0;