mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-21 03:08:40 +01:00
Convert bin/files
to ObjectQuery
Summary: Ref T603. This has some custom logic which ObjectQuery can now perform more simply and more correctly. Test Plan: Ran `bin/files purge F1`, `bin/files purge D1`, `bin/files purge --all`. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T603 Differential Revision: https://secure.phabricator.com/D7180
This commit is contained in:
parent
dd206a5b69
commit
ca7a792794
2 changed files with 24 additions and 26 deletions
|
@ -8,44 +8,33 @@ abstract class PhabricatorFilesManagementWorkflow
|
|||
}
|
||||
|
||||
protected function buildIterator(PhutilArgumentParser $args) {
|
||||
$names = $args->getArg('names');
|
||||
|
||||
if ($args->getArg('all')) {
|
||||
if ($args->getArg('names')) {
|
||||
if ($names) {
|
||||
throw new PhutilArgumentUsageException(
|
||||
"Specify either a list of files or `--all`, but not both.");
|
||||
}
|
||||
return new LiskMigrationIterator(new PhabricatorFile());
|
||||
}
|
||||
|
||||
if ($args->getArg('names')) {
|
||||
$iterator = array();
|
||||
if ($names) {
|
||||
$query = id(new PhabricatorObjectQuery())
|
||||
->setViewer(PhabricatorUser::getOmnipotentUser())
|
||||
->withNames($names)
|
||||
->withTypes(array(PhabricatorFilePHIDTypeFile::TYPECONST));
|
||||
|
||||
// TODO: (T603) Convert this to ObjectNameQuery.
|
||||
$query->execute();
|
||||
$files = $query->getNamedResults();
|
||||
|
||||
foreach ($args->getArg('names') as $name) {
|
||||
$name = trim($name);
|
||||
|
||||
$id = preg_replace('/^F/i', '', $name);
|
||||
if (ctype_digit($id)) {
|
||||
$file = id(new PhabricatorFile())->loadOneWhere(
|
||||
'id = %d',
|
||||
$id);
|
||||
if (!$file) {
|
||||
throw new PhutilArgumentUsageException(
|
||||
"No file exists with ID '{$name}'.");
|
||||
}
|
||||
} else {
|
||||
$file = id(new PhabricatorFile())->loadOneWhere(
|
||||
'phid = %s',
|
||||
$name);
|
||||
if (!$file) {
|
||||
throw new PhutilArgumentUsageException(
|
||||
"No file exists with PHID '{$name}'.");
|
||||
}
|
||||
foreach ($names as $name) {
|
||||
if (empty($files[$name])) {
|
||||
throw new PhutilArgumentUsageException(
|
||||
"No file '{$name}' exists!");
|
||||
}
|
||||
$iterator[] = $file;
|
||||
}
|
||||
|
||||
return $iterator;
|
||||
return array_values($files);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
@ -5,6 +5,7 @@ final class PhabricatorObjectQuery
|
|||
|
||||
private $phids = array();
|
||||
private $names = array();
|
||||
private $types;
|
||||
|
||||
private $namedResults;
|
||||
|
||||
|
@ -18,12 +19,20 @@ final class PhabricatorObjectQuery
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function withTypes(array $types) {
|
||||
$this->types = $types;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function loadPage() {
|
||||
if ($this->namedResults === null) {
|
||||
$this->namedResults = array();
|
||||
}
|
||||
|
||||
$types = PhabricatorPHIDType::getAllTypes();
|
||||
if ($this->types) {
|
||||
$types = array_select_keys($types, $this->types);
|
||||
}
|
||||
|
||||
$names = array_unique($this->names);
|
||||
$phids = $this->phids;
|
||||
|
|
Loading…
Add table
Reference in a new issue