Differential D20571 Diff 49083 src/applications/files/management/PhabricatorFilesManagementWorkflow.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/files/management/PhabricatorFilesManagementWorkflow.php
| <?php | <?php | ||||
| abstract class PhabricatorFilesManagementWorkflow | abstract class PhabricatorFilesManagementWorkflow | ||||
| extends PhabricatorManagementWorkflow { | extends PhabricatorManagementWorkflow { | ||||
| protected function buildIterator(PhutilArgumentParser $args) { | protected function buildIterator(PhutilArgumentParser $args) { | ||||
| $viewer = $this->getViewer(); | |||||
| $names = $args->getArg('names'); | $names = $args->getArg('names'); | ||||
| if ($args->getArg('all')) { | $is_all = $args->getArg('all'); | ||||
| if ($names) { | $from_engine = $args->getArg('from-engine'); | ||||
| $any_constraint = ($from_engine || $names); | |||||
| if (!$is_all && !$any_constraint) { | |||||
| throw new PhutilArgumentUsageException( | throw new PhutilArgumentUsageException( | ||||
| pht( | pht( | ||||
| 'Specify either a list of files or `%s`, but not both.', | 'Use "--all" to migrate all files, or choose files to migrate '. | ||||
| '--all')); | 'with "--names" or "--from-engine".')); | ||||
| } | } | ||||
| return new LiskMigrationIterator(new PhabricatorFile()); | |||||
| if ($is_all && $any_constraint) { | |||||
| throw new PhutilArgumentUsageException( | |||||
| pht( | |||||
| 'You can not migrate all files with "--all" and also migrate only '. | |||||
| 'a subset of files with "--from-engine" or "--names".')); | |||||
| } | } | ||||
| // If we're migrating specific named files, convert the names into IDs | |||||
| // first. | |||||
| $ids = null; | |||||
| if ($names) { | if ($names) { | ||||
| return $this->loadFilesWithNames($names); | $files = $this->loadFilesWithNames($names); | ||||
| $ids = mpull($files, 'getID'); | |||||
| } | |||||
| $query = id(new PhabricatorFileQuery()) | |||||
| ->setViewer($viewer); | |||||
| if ($ids) { | |||||
| $query->withIDs($ids); | |||||
| } | |||||
| if ($from_engine) { | |||||
| $query->withStorageEngines(array($from_engine)); | |||||
| } | } | ||||
| return null; | return new PhabricatorQueryIterator($query); | ||||
| } | } | ||||
| protected function loadFilesWithNames(array $names) { | protected function loadFilesWithNames(array $names) { | ||||
| $query = id(new PhabricatorObjectQuery()) | $query = id(new PhabricatorObjectQuery()) | ||||
| ->setViewer($this->getViewer()) | ->setViewer($this->getViewer()) | ||||
| ->withNames($names) | ->withNames($names) | ||||
| ->withTypes(array(PhabricatorFileFilePHIDType::TYPECONST)); | ->withTypes(array(PhabricatorFileFilePHIDType::TYPECONST)); | ||||
| $query->execute(); | $query->execute(); | ||||
| $files = $query->getNamedResults(); | $files = $query->getNamedResults(); | ||||
| foreach ($names as $name) { | foreach ($names as $name) { | ||||
| if (empty($files[$name])) { | if (empty($files[$name])) { | ||||
| throw new PhutilArgumentUsageException( | throw new PhutilArgumentUsageException( | ||||
| pht( | pht( | ||||
| "No file '%s' exists!", | 'No file "%s" exists.', | ||||
| $name)); | $name)); | ||||
| } | } | ||||
| } | } | ||||
| return array_values($files); | return array_values($files); | ||||
| } | } | ||||
| } | } | ||||