Use Application PHIDs in Files
Summary: Ref T2715. Move files to the new stuff. Test Plan: Used `phid.query`; `phid.lookup` to find files. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2715 Differential Revision: https://secure.phabricator.com/D6523
This commit is contained in:
76
src/applications/files/phid/PhabricatorFilePHIDTypeFile.php
Normal file
76
src/applications/files/phid/PhabricatorFilePHIDTypeFile.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
final class PhabricatorFilePHIDTypeFile extends PhabricatorPHIDType {
|
||||
|
||||
const TYPECONST = 'FILE';
|
||||
|
||||
public function getTypeConstant() {
|
||||
return self::TYPECONST;
|
||||
}
|
||||
|
||||
public function getTypeName() {
|
||||
return pht('File');
|
||||
}
|
||||
|
||||
public function newObject() {
|
||||
return new PhabricatorFile();
|
||||
}
|
||||
|
||||
public function loadObjects(
|
||||
PhabricatorObjectQuery $query,
|
||||
array $phids) {
|
||||
|
||||
return id(new PhabricatorFileQuery())
|
||||
->setViewer($query->getViewer())
|
||||
->withPHIDs($phids)
|
||||
->execute();
|
||||
}
|
||||
|
||||
public function loadHandles(
|
||||
PhabricatorHandleQuery $query,
|
||||
array $handles,
|
||||
array $objects) {
|
||||
|
||||
foreach ($handles as $phid => $handle) {
|
||||
$file = $objects[$phid];
|
||||
|
||||
$id = $file->getID();
|
||||
$name = $file->getName();
|
||||
$uri = $file->getBestURI();
|
||||
|
||||
$handle->setName("F{$id}");
|
||||
$handle->setFullName("F{$id}: {$name}");
|
||||
$handle->setURI($uri);
|
||||
}
|
||||
}
|
||||
|
||||
public function canLoadNamedObject($name) {
|
||||
return preg_match('/^F\d*[1-9]\d*$/', $name);
|
||||
}
|
||||
|
||||
public function loadNamedObjects(
|
||||
PhabricatorObjectQuery $query,
|
||||
array $names) {
|
||||
|
||||
$id_map = array();
|
||||
foreach ($names as $name) {
|
||||
$id = (int)substr($name, 1);
|
||||
$id_map[$id][] = $name;
|
||||
}
|
||||
|
||||
$objects = id(new PhabricatorFileQuery())
|
||||
->setViewer($query->getViewer())
|
||||
->withIDs(array_keys($id_map))
|
||||
->execute();
|
||||
|
||||
$results = array();
|
||||
foreach ($objects as $id => $object) {
|
||||
foreach (idx($id_map, $id, array()) as $name) {
|
||||
$results[$name] = $object;
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user