mirror of
https://we.phorge.it/source/phorge.git
synced 2025-04-08 18:38:35 +02: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) {
|
protected function buildIterator(PhutilArgumentParser $args) {
|
||||||
|
$names = $args->getArg('names');
|
||||||
|
|
||||||
if ($args->getArg('all')) {
|
if ($args->getArg('all')) {
|
||||||
if ($args->getArg('names')) {
|
if ($names) {
|
||||||
throw new PhutilArgumentUsageException(
|
throw new PhutilArgumentUsageException(
|
||||||
"Specify either a list of files or `--all`, but not both.");
|
"Specify either a list of files or `--all`, but not both.");
|
||||||
}
|
}
|
||||||
return new LiskMigrationIterator(new PhabricatorFile());
|
return new LiskMigrationIterator(new PhabricatorFile());
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($args->getArg('names')) {
|
if ($names) {
|
||||||
$iterator = array();
|
$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) {
|
foreach ($names as $name) {
|
||||||
$name = trim($name);
|
if (empty($files[$name])) {
|
||||||
|
|
||||||
$id = preg_replace('/^F/i', '', $name);
|
|
||||||
if (ctype_digit($id)) {
|
|
||||||
$file = id(new PhabricatorFile())->loadOneWhere(
|
|
||||||
'id = %d',
|
|
||||||
$id);
|
|
||||||
if (!$file) {
|
|
||||||
throw new PhutilArgumentUsageException(
|
throw new PhutilArgumentUsageException(
|
||||||
"No file exists with ID '{$name}'.");
|
"No file '{$name}' exists!");
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
$file = id(new PhabricatorFile())->loadOneWhere(
|
|
||||||
'phid = %s',
|
|
||||||
$name);
|
|
||||||
if (!$file) {
|
|
||||||
throw new PhutilArgumentUsageException(
|
|
||||||
"No file exists with PHID '{$name}'.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$iterator[] = $file;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $iterator;
|
return array_values($files);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -5,6 +5,7 @@ final class PhabricatorObjectQuery
|
||||||
|
|
||||||
private $phids = array();
|
private $phids = array();
|
||||||
private $names = array();
|
private $names = array();
|
||||||
|
private $types;
|
||||||
|
|
||||||
private $namedResults;
|
private $namedResults;
|
||||||
|
|
||||||
|
@ -18,12 +19,20 @@ final class PhabricatorObjectQuery
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function withTypes(array $types) {
|
||||||
|
$this->types = $types;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function loadPage() {
|
public function loadPage() {
|
||||||
if ($this->namedResults === null) {
|
if ($this->namedResults === null) {
|
||||||
$this->namedResults = array();
|
$this->namedResults = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
$types = PhabricatorPHIDType::getAllTypes();
|
$types = PhabricatorPHIDType::getAllTypes();
|
||||||
|
if ($this->types) {
|
||||||
|
$types = array_select_keys($types, $this->types);
|
||||||
|
}
|
||||||
|
|
||||||
$names = array_unique($this->names);
|
$names = array_unique($this->names);
|
||||||
$phids = $this->phids;
|
$phids = $this->phids;
|
||||||
|
|
Loading…
Add table
Reference in a new issue