1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01:00

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:
epriestley 2013-07-22 08:02:56 -07:00
parent 911aaee89c
commit 3fcd9c93f1
13 changed files with 91 additions and 40 deletions

View file

@ -1131,6 +1131,7 @@ phutil_register_library_map(array(
'PhabricatorFileLinkListView' => 'view/layout/PhabricatorFileLinkListView.php',
'PhabricatorFileLinkView' => 'view/layout/PhabricatorFileLinkView.php',
'PhabricatorFileListController' => 'applications/files/controller/PhabricatorFileListController.php',
'PhabricatorFilePHIDTypeFile' => 'applications/files/phid/PhabricatorFilePHIDTypeFile.php',
'PhabricatorFileQuery' => 'applications/files/query/PhabricatorFileQuery.php',
'PhabricatorFileSearchEngine' => 'applications/files/query/PhabricatorFileSearchEngine.php',
'PhabricatorFileShortcutController' => 'applications/files/controller/PhabricatorFileShortcutController.php',
@ -3129,6 +3130,7 @@ phutil_register_library_map(array(
0 => 'PhabricatorFileController',
1 => 'PhabricatorApplicationSearchResultsControllerInterface',
),
'PhabricatorFilePHIDTypeFile' => 'PhabricatorPHIDType',
'PhabricatorFileQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorFileSearchEngine' => 'PhabricatorApplicationSearchEngine',
'PhabricatorFileShortcutController' => 'PhabricatorFileController',

View 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;
}
}

View file

@ -35,7 +35,7 @@ final class PhabricatorFile extends PhabricatorFileDAO
public function generatePHID() {
return PhabricatorPHID::generateNewPHID(
PhabricatorPHIDConstants::PHID_TYPE_FILE);
PhabricatorFilePHIDTypeFile::TYPECONST);
}
public static function readUploadedFileData($spec) {

View file

@ -129,11 +129,11 @@ abstract class ConduitAPI_maniphest_Method extends ConduitAPIMethod {
$file_phids = $request->getValue('filePHIDs');
if ($file_phids !== null) {
$this->validatePHIDList($file_phids,
PhabricatorPHIDConstants::PHID_TYPE_FILE,
PhabricatorFilePHIDTypeFile::TYPECONST,
'filePHIDS');
$file_map = array_fill_keys($file_phids, true);
$attached = $task->getAttached();
$attached[PhabricatorPHIDConstants::PHID_TYPE_FILE] = $file_map;
$attached[PhabricatorFilePHIDTypeFile::TYPECONST] = $file_map;
$changes[ManiphestTransactionType::TYPE_ATTACH] = $attached;
}

View file

@ -566,7 +566,7 @@ final class ManiphestTaskDetailController extends ManiphestController {
}
$attached = $task->getAttached();
$file_infos = idx($attached, PhabricatorPHIDConstants::PHID_TYPE_FILE);
$file_infos = idx($attached, PhabricatorFilePHIDTypeFile::TYPECONST);
if ($file_infos) {
$file_phids = array_keys($file_infos);

View file

@ -181,7 +181,7 @@ final class ManiphestTaskEditController extends ManiphestController {
$file_map = mpull($files, 'getPHID');
$file_map = array_fill_keys($file_map, array());
$changes[ManiphestTransactionType::TYPE_ATTACH] = array(
PhabricatorPHIDConstants::PHID_TYPE_FILE => $file_map,
PhabricatorFilePHIDTypeFile::TYPECONST => $file_map,
);
}

View file

@ -54,10 +54,10 @@ final class ManiphestTransactionSaveController extends ManiphestController {
$files = mpull($files, 'getPHID', 'getPHID');
$new = $task->getAttached();
foreach ($files as $phid) {
if (empty($new[PhabricatorPHIDConstants::PHID_TYPE_FILE])) {
$new[PhabricatorPHIDConstants::PHID_TYPE_FILE] = array();
if (empty($new[PhabricatorFilePHIDTypeFile::TYPECONST])) {
$new[PhabricatorFilePHIDTypeFile::TYPECONST] = array();
}
$new[PhabricatorPHIDConstants::PHID_TYPE_FILE][$phid] = array();
$new[PhabricatorFilePHIDTypeFile::TYPECONST][$phid] = array();
}
$transaction = new ManiphestTransaction();
$transaction

View file

@ -242,7 +242,7 @@ final class ManiphestTransactionDetailView extends ManiphestView {
$attach_types = array(
DifferentialPHIDTypeRevision::TYPECONST,
PhabricatorPHIDConstants::PHID_TYPE_FILE,
PhabricatorFilePHIDTypeFile::TYPECONST,
);
foreach ($attach_types as $attach_type) {
@ -268,7 +268,7 @@ final class ManiphestTransactionDetailView extends ManiphestView {
case DifferentialPHIDTypeRevision::TYPECONST:
$title = 'ATTACHED REVISIONS';
break;
case PhabricatorPHIDConstants::PHID_TYPE_FILE:
case PhabricatorFilePHIDTypeFile::TYPECONST:
$title = 'ATTACHED FILES';
break;
}
@ -484,7 +484,7 @@ final class ManiphestTransactionDetailView extends ManiphestView {
foreach (array(
DifferentialPHIDTypeRevision::TYPECONST,
ManiphestPHIDTypeTask::TYPECONST,
PhabricatorPHIDConstants::PHID_TYPE_FILE) as $attach_type) {
PhabricatorFilePHIDTypeFile::TYPECONST) as $attach_type) {
$old = array_keys(idx($old_raw, $attach_type, array()));
$new = array_keys(idx($new_raw, $attach_type, array()));
if ($old != $new) {
@ -652,7 +652,7 @@ final class ManiphestTransactionDetailView extends ManiphestView {
switch ($attach_type) {
case DifferentialPHIDTypeRevision::TYPECONST:
return pht('Differential Revision(s)', $count);
case PhabricatorPHIDConstants::PHID_TYPE_FILE:
case PhabricatorFilePHIDTypeFile::TYPECONST:
return pht('file(s)', $count);
case ManiphestPHIDTypeTask::TYPECONST:
return pht('Maniphest Task(s)', $count);

View file

@ -112,7 +112,6 @@ final class PhabricatorObjectHandle
PhabricatorPHIDConstants::PHID_TYPE_WIKI => 'Phriction Document',
PhabricatorPHIDConstants::PHID_TYPE_MCRO => 'Image Macro',
PhabricatorPHIDConstants::PHID_TYPE_PIMG => 'Pholio Image',
PhabricatorPHIDConstants::PHID_TYPE_FILE => 'File',
PhabricatorPHIDConstants::PHID_TYPE_BLOG => 'Blog',
PhabricatorPHIDConstants::PHID_TYPE_POST => 'Post',
PhabricatorPHIDConstants::PHID_TYPE_QUES => 'Question',

View file

@ -3,7 +3,6 @@
final class PhabricatorPHIDConstants {
const PHID_TYPE_USER = 'USER';
const PHID_TYPE_FILE = 'FILE';
const PHID_TYPE_PROJ = 'PROJ';
const PHID_TYPE_UNKNOWN = '????';
const PHID_TYPE_MAGIC = '!!!!';

View file

@ -41,7 +41,7 @@ final class ConduitAPI_phid_lookup_Method
foreach ($name_map as $name => $object) {
$phid = $object->getPHID();
$handle = $handles[$phid];
$result[$phid] = $this->buildHandleInformationDictionary($handle);
$result[$name] = $this->buildHandleInformationDictionary($handle);
}
return $result;

View file

@ -56,12 +56,6 @@ final class PhabricatorObjectHandleData {
$phids);
return mpull($users, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_FILE:
// TODO: Update this to PhabricatorFileQuery
$object = new PhabricatorFile();
$files = $object->loadAllWhere('phid IN (%Ls)', $phids);
return mpull($files, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_PROJ:
$projects = id(new PhabricatorProjectQuery())
->setViewer($this->viewer)
@ -295,24 +289,6 @@ final class PhabricatorObjectHandleData {
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_FILE:
foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle();
$handle->setPHID($phid);
$handle->setType($type);
if (empty($objects[$phid])) {
$handle->setName('Unknown File');
} else {
$file = $objects[$phid];
$handle->setName('F'.$file->getID());
$handle->setFullName('F'.$file->getID().' '.$file->getName());
$handle->setURI($file->getBestURI());
$handle->setComplete(true);
}
$handles[$phid] = $handle;
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_PROJ:
foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle();

View file

@ -154,7 +154,6 @@ final class PhabricatorEdgeConfig extends PhabricatorEdgeConstants {
}
static $class_map = array(
PhabricatorPHIDConstants::PHID_TYPE_FILE => 'PhabricatorFile',
PhabricatorPHIDConstants::PHID_TYPE_USER => 'PhabricatorUser',
PhabricatorPHIDConstants::PHID_TYPE_PROJ => 'PhabricatorProject',
PhabricatorPHIDConstants::PHID_TYPE_TOBJ => 'HarbormasterObject',