From 3fcd9c93f186abe7dcfd29f8639ba18205e24462 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 22 Jul 2013 08:02:56 -0700 Subject: [PATCH] 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 --- src/__phutil_library_map__.php | 2 + .../phid/PhabricatorFilePHIDTypeFile.php | 76 +++++++++++++++++++ .../files/storage/PhabricatorFile.php | 2 +- .../conduit/ConduitAPI_maniphest_Method.php | 4 +- .../ManiphestTaskDetailController.php | 2 +- .../ManiphestTaskEditController.php | 2 +- .../ManiphestTransactionSaveController.php | 6 +- .../view/ManiphestTransactionDetailView.php | 8 +- .../phid/PhabricatorObjectHandle.php | 1 - .../phid/PhabricatorPHIDConstants.php | 1 - .../conduit/ConduitAPI_phid_lookup_Method.php | 2 +- .../handle/PhabricatorObjectHandleData.php | 24 ------ .../edges/constants/PhabricatorEdgeConfig.php | 1 - 13 files changed, 91 insertions(+), 40 deletions(-) create mode 100644 src/applications/files/phid/PhabricatorFilePHIDTypeFile.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index fffe2cfac6..90d0f49f78 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -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', diff --git a/src/applications/files/phid/PhabricatorFilePHIDTypeFile.php b/src/applications/files/phid/PhabricatorFilePHIDTypeFile.php new file mode 100644 index 0000000000..04c11128e5 --- /dev/null +++ b/src/applications/files/phid/PhabricatorFilePHIDTypeFile.php @@ -0,0 +1,76 @@ +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; + } + +} diff --git a/src/applications/files/storage/PhabricatorFile.php b/src/applications/files/storage/PhabricatorFile.php index 52e1f7db03..ea8d951b40 100644 --- a/src/applications/files/storage/PhabricatorFile.php +++ b/src/applications/files/storage/PhabricatorFile.php @@ -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) { diff --git a/src/applications/maniphest/conduit/ConduitAPI_maniphest_Method.php b/src/applications/maniphest/conduit/ConduitAPI_maniphest_Method.php index a4551668ce..140c232ddf 100644 --- a/src/applications/maniphest/conduit/ConduitAPI_maniphest_Method.php +++ b/src/applications/maniphest/conduit/ConduitAPI_maniphest_Method.php @@ -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; } diff --git a/src/applications/maniphest/controller/ManiphestTaskDetailController.php b/src/applications/maniphest/controller/ManiphestTaskDetailController.php index cd4450f0c7..d5bf49249f 100644 --- a/src/applications/maniphest/controller/ManiphestTaskDetailController.php +++ b/src/applications/maniphest/controller/ManiphestTaskDetailController.php @@ -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); diff --git a/src/applications/maniphest/controller/ManiphestTaskEditController.php b/src/applications/maniphest/controller/ManiphestTaskEditController.php index f578e37e0b..4a476f75e7 100644 --- a/src/applications/maniphest/controller/ManiphestTaskEditController.php +++ b/src/applications/maniphest/controller/ManiphestTaskEditController.php @@ -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, ); } diff --git a/src/applications/maniphest/controller/ManiphestTransactionSaveController.php b/src/applications/maniphest/controller/ManiphestTransactionSaveController.php index c3b3823a3d..596e57f84e 100644 --- a/src/applications/maniphest/controller/ManiphestTransactionSaveController.php +++ b/src/applications/maniphest/controller/ManiphestTransactionSaveController.php @@ -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 diff --git a/src/applications/maniphest/view/ManiphestTransactionDetailView.php b/src/applications/maniphest/view/ManiphestTransactionDetailView.php index 374ba285cc..24eaee9795 100644 --- a/src/applications/maniphest/view/ManiphestTransactionDetailView.php +++ b/src/applications/maniphest/view/ManiphestTransactionDetailView.php @@ -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); diff --git a/src/applications/phid/PhabricatorObjectHandle.php b/src/applications/phid/PhabricatorObjectHandle.php index 015e3408f9..3bdf678687 100644 --- a/src/applications/phid/PhabricatorObjectHandle.php +++ b/src/applications/phid/PhabricatorObjectHandle.php @@ -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', diff --git a/src/applications/phid/PhabricatorPHIDConstants.php b/src/applications/phid/PhabricatorPHIDConstants.php index 24f9303733..2cbab1af6c 100644 --- a/src/applications/phid/PhabricatorPHIDConstants.php +++ b/src/applications/phid/PhabricatorPHIDConstants.php @@ -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 = '!!!!'; diff --git a/src/applications/phid/conduit/ConduitAPI_phid_lookup_Method.php b/src/applications/phid/conduit/ConduitAPI_phid_lookup_Method.php index 9fd73e7d31..6d6aaae24d 100644 --- a/src/applications/phid/conduit/ConduitAPI_phid_lookup_Method.php +++ b/src/applications/phid/conduit/ConduitAPI_phid_lookup_Method.php @@ -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; diff --git a/src/applications/phid/handle/PhabricatorObjectHandleData.php b/src/applications/phid/handle/PhabricatorObjectHandleData.php index 51f152c919..c3571ba735 100644 --- a/src/applications/phid/handle/PhabricatorObjectHandleData.php +++ b/src/applications/phid/handle/PhabricatorObjectHandleData.php @@ -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(); diff --git a/src/infrastructure/edges/constants/PhabricatorEdgeConfig.php b/src/infrastructure/edges/constants/PhabricatorEdgeConfig.php index 09a15ebae8..fafe53c624 100644 --- a/src/infrastructure/edges/constants/PhabricatorEdgeConfig.php +++ b/src/infrastructure/edges/constants/PhabricatorEdgeConfig.php @@ -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',