3 final class PhabricatorRepositoryManagementLockWorkflow
4 extends PhabricatorRepositoryManagementWorkflow
{
6 protected function didConstruct() {
9 ->setExamples('**lock** [options] __repository__ ...')
12 'Temporarily lock clustered repositories to perform maintenance.'))
16 'name' => 'repositories',
22 public function execute(PhutilArgumentParser
$args) {
23 $viewer = $this->getViewer();
25 $repositories = $this->loadRepositories($args, '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(
37 'Unable to lock repository "%s": only hosted repositories may be '.
42 if (!$repository->supportsSynchronization()) {
43 throw new PhutilArgumentUsageException(
45 'Unable to lock repository "%s": only repositories that support '.
46 'clustering may be locked.',
50 if (!$repository->getAlmanacServicePHID()) {
51 throw new PhutilArgumentUsageException(
53 'Unable to lock repository "%s": only clustered repositories '.
59 $diffusion_phid = id(new PhabricatorDiffusionApplication())
63 foreach ($repositories as $repository) {
64 $engine = id(new DiffusionRepositoryClusterEngine())
66 ->setActingAsPHID($diffusion_phid)
67 ->setRepository($repository);
69 $event = $engine->newMaintenanceEvent();
72 $logs[] = $engine->newMaintenanceLog();
75 'repository' => $repository,
82 $display_list = new PhutilConsoleList();
83 foreach ($repositories as $repository) {
84 $display_list->addItem(
87 $repository->getMonogram(),
88 $repository->getName()));
93 pht('These repositories will be locked:'),
94 $display_list->drawConsoleString());
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();
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();