3 abstract class PhabricatorFilesManagementWorkflow
4 extends PhabricatorManagementWorkflow
{
6 protected function newIteratorArguments() {
10 'help' => pht('Operate on all files.'),
17 'name' => 'from-engine',
18 'param' => 'storage-engine',
19 'help' => pht('Operate on files stored in a specified engine.'),
24 protected function buildIterator(PhutilArgumentParser
$args) {
25 $viewer = $this->getViewer();
27 $is_all = $args->getArg('all');
29 $names = $args->getArg('names');
30 $from_engine = $args->getArg('from-engine');
32 $any_constraint = ($from_engine ||
$names);
34 if (!$is_all && !$any_constraint) {
35 throw new PhutilArgumentUsageException(
37 'Specify which files to operate on, or use "--all" to operate on '.
41 if ($is_all && $any_constraint) {
42 throw new PhutilArgumentUsageException(
44 'You can not operate on all files with "--all" and also operate '.
45 'on a subset of files by naming them explicitly or using '.
46 'constraint flags like "--from-engine".'));
49 // If we're migrating specific named files, convert the names into IDs
53 $files = $this->loadFilesWithNames($names);
54 $ids = mpull($files, 'getID');
57 $query = id(new PhabricatorFileQuery())
61 $query->withIDs($ids);
65 $query->withStorageEngines(array($from_engine));
68 return new PhabricatorQueryIterator($query);
71 protected function loadFilesWithNames(array $names) {
72 $query = id(new PhabricatorObjectQuery())
73 ->setViewer($this->getViewer())
75 ->withTypes(array(PhabricatorFileFilePHIDType
::TYPECONST
));
78 $files = $query->getNamedResults();
80 foreach ($names as $name) {
81 if (empty($files[$name])) {
82 throw new PhutilArgumentUsageException(
84 'No file "%s" exists.',
89 return array_values($files);