Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / repository / management / PhabricatorRepositoryManagementLockWorkflow.php
blob289e8d73ee323fce73e7e67791b7da5fe25459e2
1 <?php
3 final class PhabricatorRepositoryManagementLockWorkflow
4 extends PhabricatorRepositoryManagementWorkflow {
6 protected function didConstruct() {
7 $this
8 ->setName('lock')
9 ->setExamples('**lock** [options] __repository__ ...')
10 ->setSynopsis(
11 pht(
12 'Temporarily lock clustered repositories to perform maintenance.'))
13 ->setArguments(
14 array(
15 array(
16 'name' => 'repositories',
17 'wildcard' => true,
19 ));
22 public function execute(PhutilArgumentParser $args) {
23 $viewer = $this->getViewer();
25 $repositories = $this->loadRepositories($args, 'repositories');
26 if (!$repositories) {
27 throw new PhutilArgumentUsageException(
28 pht('Specify one or more repositories to lock.'));
31 foreach ($repositories as $repository) {
32 $display_name = $repository->getDisplayName();
34 if (!$repository->isHosted()) {
35 throw new PhutilArgumentUsageException(
36 pht(
37 'Unable to lock repository "%s": only hosted repositories may be '.
38 'locked.',
39 $display_name));
42 if (!$repository->supportsSynchronization()) {
43 throw new PhutilArgumentUsageException(
44 pht(
45 'Unable to lock repository "%s": only repositories that support '.
46 'clustering may be locked.',
47 $display_name));
50 if (!$repository->getAlmanacServicePHID()) {
51 throw new PhutilArgumentUsageException(
52 pht(
53 'Unable to lock repository "%s": only clustered repositories '.
54 'may be locked.',
55 $display_name));
59 $diffusion_phid = id(new PhabricatorDiffusionApplication())
60 ->getPHID();
62 $locks = array();
63 foreach ($repositories as $repository) {
64 $engine = id(new DiffusionRepositoryClusterEngine())
65 ->setViewer($viewer)
66 ->setActingAsPHID($diffusion_phid)
67 ->setRepository($repository);
69 $event = $engine->newMaintenanceEvent();
71 $logs = array();
72 $logs[] = $engine->newMaintenanceLog();
74 $locks[] = array(
75 'repository' => $repository,
76 'engine' => $engine,
77 'event' => $event,
78 'logs' => $logs,
82 $display_list = new PhutilConsoleList();
83 foreach ($repositories as $repository) {
84 $display_list->addItem(
85 pht(
86 '%s %s',
87 $repository->getMonogram(),
88 $repository->getName()));
91 echo tsprintf(
92 "%s\n\n%B\n",
93 pht('These repositories will be locked:'),
94 $display_list->drawConsoleString());
96 echo tsprintf(
97 "%s\n",
98 pht(
99 'While the lock is held: users will be unable to write to this '.
100 'repository, and you may safely perform working copy maintenance '.
101 'on this node in another terminal window.'));
103 $query = pht('Lock repositories and begin maintenance?');
104 if (!phutil_console_confirm($query)) {
105 throw new ArcanistUserAbortException();
108 foreach ($locks as $key => $lock) {
109 $engine = $lock['engine'];
110 $engine->synchronizeWorkingCopyBeforeWrite();
113 echo tsprintf(
114 "%s\n",
115 pht(
116 'Repositories are now locked. You may begin maintenance in '.
117 'another terminal window. Keep this process running until '.
118 'you complete the maintenance, then confirm that you are ready to '.
119 'release the locks.'));
121 while (!phutil_console_confirm('Ready to release the locks?')) {
122 // Wait for the user to confirm that they're ready.
125 foreach ($locks as $key => $lock) {
126 $lock['event']->saveWithLogs($lock['logs']);
128 $engine = $lock['engine'];
129 $engine->synchronizeWorkingCopyAfterWrite();
132 echo tsprintf(
133 "%s\n",
134 pht('Done.'));
136 return 0;