mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-11 17:32:41 +01:00
e397103bf2
Summary: Ref T2015. Not directly related to Drydock, but I've wanted to do this for a bit. Introduce a common base class for all the workflows in the scripts in `bin/*`. This slightly reduces code duplication by moving `isExecutable()` to the base, but also provides `getViewer()`. This is a little nicer than `PhabricatorUser::getOmnipotentUser()` and gives us a layer of indirection if we ever want to introduce more general viewer mechanisms in scripts. Test Plan: Lint; ran some of the scripts. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2015 Differential Revision: https://secure.phabricator.com/D7838
40 lines
971 B
PHP
40 lines
971 B
PHP
<?php
|
|
|
|
abstract class PhabricatorFilesManagementWorkflow
|
|
extends PhabricatorManagementWorkflow {
|
|
|
|
protected function buildIterator(PhutilArgumentParser $args) {
|
|
$names = $args->getArg('names');
|
|
|
|
if ($args->getArg('all')) {
|
|
if ($names) {
|
|
throw new PhutilArgumentUsageException(
|
|
"Specify either a list of files or `--all`, but not both.");
|
|
}
|
|
return new LiskMigrationIterator(new PhabricatorFile());
|
|
}
|
|
|
|
if ($names) {
|
|
$query = id(new PhabricatorObjectQuery())
|
|
->setViewer($this->getViewer())
|
|
->withNames($names)
|
|
->withTypes(array(PhabricatorFilePHIDTypeFile::TYPECONST));
|
|
|
|
$query->execute();
|
|
$files = $query->getNamedResults();
|
|
|
|
foreach ($names as $name) {
|
|
if (empty($files[$name])) {
|
|
throw new PhutilArgumentUsageException(
|
|
"No file '{$name}' exists!");
|
|
}
|
|
}
|
|
|
|
return array_values($files);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
|
|
}
|