Path: blob/master/src/applications/files/management/PhabricatorFilesManagementWorkflow.php
13418 views
<?php12abstract class PhabricatorFilesManagementWorkflow3extends PhabricatorManagementWorkflow {45protected function newIteratorArguments() {6return array(7array(8'name' => 'all',9'help' => pht('Operate on all files.'),10),11array(12'name' => 'names',13'wildcard' => true,14),15array(16'name' => 'from-engine',17'param' => 'storage-engine',18'help' => pht('Operate on files stored in a specified engine.'),19),20);21}2223protected function buildIterator(PhutilArgumentParser $args) {24$viewer = $this->getViewer();2526$is_all = $args->getArg('all');2728$names = $args->getArg('names');29$from_engine = $args->getArg('from-engine');3031$any_constraint = ($from_engine || $names);3233if (!$is_all && !$any_constraint) {34throw new PhutilArgumentUsageException(35pht(36'Specify which files to operate on, or use "--all" to operate on '.37'all files.'));38}3940if ($is_all && $any_constraint) {41throw new PhutilArgumentUsageException(42pht(43'You can not operate on all files with "--all" and also operate '.44'on a subset of files by naming them explicitly or using '.45'constraint flags like "--from-engine".'));46}4748// If we're migrating specific named files, convert the names into IDs49// first.50$ids = null;51if ($names) {52$files = $this->loadFilesWithNames($names);53$ids = mpull($files, 'getID');54}5556$query = id(new PhabricatorFileQuery())57->setViewer($viewer);5859if ($ids) {60$query->withIDs($ids);61}6263if ($from_engine) {64$query->withStorageEngines(array($from_engine));65}6667return new PhabricatorQueryIterator($query);68}6970protected function loadFilesWithNames(array $names) {71$query = id(new PhabricatorObjectQuery())72->setViewer($this->getViewer())73->withNames($names)74->withTypes(array(PhabricatorFileFilePHIDType::TYPECONST));7576$query->execute();77$files = $query->getNamedResults();7879foreach ($names as $name) {80if (empty($files[$name])) {81throw new PhutilArgumentUsageException(82pht(83'No file "%s" exists.',84$name));85}86}8788return array_values($files);89}9091}929394