Differential D19849 Diff 47415 src/applications/repository/management/PhabricatorRepositoryManagementThawWorkflow.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/repository/management/PhabricatorRepositoryManagementThawWorkflow.php
Show All 27 Lines | $this | ||||
'Resolves ambiguous leadership and recovers from demotion '. | 'Resolves ambiguous leadership and recovers from demotion '. | ||||
'mistakes.'), | 'mistakes.'), | ||||
), | ), | ||||
array( | array( | ||||
'name' => 'force', | 'name' => 'force', | ||||
'help' => pht('Run operations without asking for confirmation.'), | 'help' => pht('Run operations without asking for confirmation.'), | ||||
), | ), | ||||
array( | array( | ||||
'name' => 'all-repositories', | |||||
'help' => pht( | |||||
'Apply the promotion or demotion to all repositories hosted '. | |||||
'on the device.'), | |||||
), | |||||
array( | |||||
'name' => 'repositories', | 'name' => 'repositories', | ||||
'wildcard' => true, | 'wildcard' => true, | ||||
), | ), | ||||
)); | )); | ||||
} | } | ||||
public function execute(PhutilArgumentParser $args) { | public function execute(PhutilArgumentParser $args) { | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
$repositories = $this->loadRepositories($args, 'repositories'); | |||||
if (!$repositories) { | |||||
throw new PhutilArgumentUsageException( | |||||
pht('Specify one or more repositories to thaw.')); | |||||
} | |||||
$promote = $args->getArg('promote'); | $promote = $args->getArg('promote'); | ||||
$demote = $args->getArg('demote'); | $demote = $args->getArg('demote'); | ||||
if (!$promote && !$demote) { | if (!$promote && !$demote) { | ||||
throw new PhutilArgumentUsageException( | throw new PhutilArgumentUsageException( | ||||
pht('You must choose a device to --promote or --demote.')); | pht('You must choose a device to --promote or --demote.')); | ||||
} | } | ||||
if ($promote && $demote) { | if ($promote && $demote) { | ||||
throw new PhutilArgumentUsageException( | throw new PhutilArgumentUsageException( | ||||
pht('Specify either --promote or --demote, but not both.')); | pht('Specify either --promote or --demote, but not both.')); | ||||
} | } | ||||
$device_name = nonempty($promote, $demote); | $device_name = nonempty($promote, $demote); | ||||
$device = id(new AlmanacDeviceQuery()) | $device = id(new AlmanacDeviceQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withNames(array($device_name)) | ->withNames(array($device_name)) | ||||
->executeOne(); | ->executeOne(); | ||||
if (!$device) { | if (!$device) { | ||||
throw new PhutilArgumentUsageException( | throw new PhutilArgumentUsageException( | ||||
pht('No device "%s" exists.', $device_name)); | pht('No device "%s" exists.', $device_name)); | ||||
} | } | ||||
$repository_names = $args->getArg('repositories'); | |||||
$all_repositories = $args->getArg('all-repositories'); | |||||
if ($repository_names && $all_repositories) { | |||||
throw new PhutilArgumentUsageException( | |||||
pht( | |||||
'Specify a list of repositories or "--all-repositories", '. | |||||
'but not both.')); | |||||
} else if (!$repository_names && !$all_repositories) { | |||||
throw new PhutilArgumentUsageException( | |||||
pht( | |||||
'Select repositories to affect by providing a list of repositories '. | |||||
'or using the "--all-repositories" flag.')); | |||||
} | |||||
if ($repository_names) { | |||||
$repositories = $this->loadRepositories($args, 'repositories'); | |||||
if (!$repositories) { | |||||
throw new PhutilArgumentUsageException( | |||||
pht('Specify one or more repositories to thaw.')); | |||||
} | |||||
} else { | |||||
$repositories = array(); | |||||
$services = id(new AlmanacServiceQuery()) | |||||
->setViewer($viewer) | |||||
->withDevicePHIDs(array($device->getPHID())) | |||||
->execute(); | |||||
if ($services) { | |||||
$repositories = id(new PhabricatorRepositoryQuery()) | |||||
->setViewer($viewer) | |||||
->withAlmanacServicePHIDs(mpull($services, 'getPHID')) | |||||
->execute(); | |||||
} | |||||
if (!$repositories) { | |||||
throw new PhutilArgumentUsageException( | |||||
pht('There are no repositories on the selected device.')); | |||||
} | |||||
} | |||||
$display_list = new PhutilConsoleList(); | |||||
foreach ($repositories as $repository) { | |||||
$display_list->addItem( | |||||
pht( | |||||
'%s %s', | |||||
$repository->getMonogram(), | |||||
$repository->getName())); | |||||
} | |||||
echo tsprintf( | |||||
"%s\n\n%B\n", | |||||
pht('These repositories will be thawed:'), | |||||
$display_list->drawConsoleString()); | |||||
if ($promote) { | if ($promote) { | ||||
$risk_message = pht( | $risk_message = pht( | ||||
'Promoting a device can cause the loss of any repository data which '. | 'Promoting a device can cause the loss of any repository data which '. | ||||
'only exists on other devices. The version of the repository on the '. | 'only exists on other devices. The version of the repository on the '. | ||||
'promoted device will become authoritative.'); | 'promoted device will become authoritative.'); | ||||
} else { | } else { | ||||
$risk_message = pht( | $risk_message = pht( | ||||
'Demoting a device can cause the loss of any repository data which '. | 'Demoting a device can cause the loss of any repository data which '. | ||||
▲ Show 20 Lines • Show All 142 Lines • Show Last 20 Lines |