Differential D19793 Diff 47278 src/applications/repository/management/PhabricatorRepositoryManagementThawWorkflow.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/repository/management/PhabricatorRepositoryManagementThawWorkflow.php
| Show First 20 Lines • Show All 114 Lines • ▼ Show 20 Lines | foreach ($repositories as $repository) { | ||||
| if (!$service) { | if (!$service) { | ||||
| throw new PhutilArgumentUsageException( | throw new PhutilArgumentUsageException( | ||||
| pht( | pht( | ||||
| 'Repository "%s" is not a cluster repository: it is not '. | 'Repository "%s" is not a cluster repository: it is not '. | ||||
| 'bound to an Almanac service.', | 'bound to an Almanac service.', | ||||
| $repository->getDisplayName())); | $repository->getDisplayName())); | ||||
| } | } | ||||
| if ($promote) { | |||||
| // You can only promote active devices. (You may demote active or | |||||
| // inactive devices.) | |||||
| $bindings = $service->getActiveBindings(); | $bindings = $service->getActiveBindings(); | ||||
| $bindings = mpull($bindings, null, 'getDevicePHID'); | $bindings = mpull($bindings, null, 'getDevicePHID'); | ||||
| if (empty($bindings[$device->getPHID()])) { | if (empty($bindings[$device->getPHID()])) { | ||||
| throw new PhutilArgumentUsageException( | throw new PhutilArgumentUsageException( | ||||
| pht( | pht( | ||||
| 'Repository "%s" has no active binding to device "%s". Only '. | 'Repository "%s" has no active binding to device "%s". Only '. | ||||
| 'actively bound devices can be promoted or demoted.', | 'actively bound devices can be promoted.', | ||||
| $repository->getDisplayName(), | $repository->getDisplayName(), | ||||
| $device->getName())); | $device->getName())); | ||||
| } | } | ||||
| $versions = PhabricatorRepositoryWorkingCopyVersion::loadVersions( | $versions = PhabricatorRepositoryWorkingCopyVersion::loadVersions( | ||||
| $repository->getPHID()); | $repository->getPHID()); | ||||
| $versions = mpull($versions, null, 'getDevicePHID'); | $versions = mpull($versions, null, 'getDevicePHID'); | ||||
| $versions = array_select_keys($versions, array_keys($bindings)); | |||||
| if ($versions && $promote) { | // Before we promote, make sure there are no outstanding versions on | ||||
| // devices with inactive bindings. If there are, you need to demote | |||||
| // these first. | |||||
| $inactive = array(); | |||||
| foreach ($versions as $device_phid => $version) { | |||||
| if (isset($bindings[$device_phid])) { | |||||
| continue; | |||||
| } | |||||
| $inactive[$device_phid] = $version; | |||||
| } | |||||
| if ($inactive) { | |||||
| $handles = $viewer->loadHandles(array_keys($inactive)); | |||||
| $handle_list = iterator_to_array($handles); | |||||
| $handle_list = mpull($handle_list, 'getName'); | |||||
| $handle_list = implode(', ', $handle_list); | |||||
| throw new PhutilArgumentUsageException( | throw new PhutilArgumentUsageException( | ||||
| pht( | pht( | ||||
| 'Unable to promote "%s" for repository "%s": the leaders for '. | 'Repository "%s" has versions on inactive devices. Demote '. | ||||
| 'this cluster are not ambiguous.', | '(or reactivate) these devices before promoting a new '. | ||||
| 'leader: %s.', | |||||
| $repository->getDisplayName(), | |||||
| $handle_list)); | |||||
| } | |||||
| // Now, make sure there are no outstanding versions on devices with | |||||
| // active bindings. These also need to be demoted (or promoting is a | |||||
| // mistake or already happened). | |||||
| $active = array_select_keys($versions, array_keys($bindings)); | |||||
| if ($active) { | |||||
| $handles = $viewer->loadHandles(array_keys($active)); | |||||
| $handle_list = iterator_to_array($handles); | |||||
| $handle_list = mpull($handle_list, 'getName'); | |||||
| $handle_list = implode(', ', $handle_list); | |||||
| throw new PhutilArgumentUsageException( | |||||
| pht( | |||||
| 'Unable to promote "%s" for repository "%s" because this '. | |||||
| 'cluster already has one or more unambiguous leaders: %s.', | |||||
| $device->getName(), | $device->getName(), | ||||
| $repository->getDisplayName())); | $repository->getDisplayName(), | ||||
| $handle_list)); | |||||
| } | } | ||||
| if ($promote) { | |||||
| PhabricatorRepositoryWorkingCopyVersion::updateVersion( | PhabricatorRepositoryWorkingCopyVersion::updateVersion( | ||||
| $repository->getPHID(), | $repository->getPHID(), | ||||
| $device->getPHID(), | $device->getPHID(), | ||||
| 0); | 0); | ||||
| echo tsprintf( | echo tsprintf( | ||||
| "%s\n", | "%s\n", | ||||
| pht( | pht( | ||||
| Show All 29 Lines | |||||