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:
		| @@ -1131,6 +1131,7 @@ phutil_register_library_map(array( | |||||||
|     'PhabricatorFileLinkListView' => 'view/layout/PhabricatorFileLinkListView.php', |     'PhabricatorFileLinkListView' => 'view/layout/PhabricatorFileLinkListView.php', | ||||||
|     'PhabricatorFileLinkView' => 'view/layout/PhabricatorFileLinkView.php', |     'PhabricatorFileLinkView' => 'view/layout/PhabricatorFileLinkView.php', | ||||||
|     'PhabricatorFileListController' => 'applications/files/controller/PhabricatorFileListController.php', |     'PhabricatorFileListController' => 'applications/files/controller/PhabricatorFileListController.php', | ||||||
|  |     'PhabricatorFilePHIDTypeFile' => 'applications/files/phid/PhabricatorFilePHIDTypeFile.php', | ||||||
|     'PhabricatorFileQuery' => 'applications/files/query/PhabricatorFileQuery.php', |     'PhabricatorFileQuery' => 'applications/files/query/PhabricatorFileQuery.php', | ||||||
|     'PhabricatorFileSearchEngine' => 'applications/files/query/PhabricatorFileSearchEngine.php', |     'PhabricatorFileSearchEngine' => 'applications/files/query/PhabricatorFileSearchEngine.php', | ||||||
|     'PhabricatorFileShortcutController' => 'applications/files/controller/PhabricatorFileShortcutController.php', |     'PhabricatorFileShortcutController' => 'applications/files/controller/PhabricatorFileShortcutController.php', | ||||||
| @@ -3129,6 +3130,7 @@ phutil_register_library_map(array( | |||||||
|       0 => 'PhabricatorFileController', |       0 => 'PhabricatorFileController', | ||||||
|       1 => 'PhabricatorApplicationSearchResultsControllerInterface', |       1 => 'PhabricatorApplicationSearchResultsControllerInterface', | ||||||
|     ), |     ), | ||||||
|  |     'PhabricatorFilePHIDTypeFile' => 'PhabricatorPHIDType', | ||||||
|     'PhabricatorFileQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', |     'PhabricatorFileQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', | ||||||
|     'PhabricatorFileSearchEngine' => 'PhabricatorApplicationSearchEngine', |     'PhabricatorFileSearchEngine' => 'PhabricatorApplicationSearchEngine', | ||||||
|     'PhabricatorFileShortcutController' => 'PhabricatorFileController', |     'PhabricatorFileShortcutController' => 'PhabricatorFileController', | ||||||
|   | |||||||
							
								
								
									
										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; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  | } | ||||||
| @@ -35,7 +35,7 @@ final class PhabricatorFile extends PhabricatorFileDAO | |||||||
|  |  | ||||||
|   public function generatePHID() { |   public function generatePHID() { | ||||||
|     return PhabricatorPHID::generateNewPHID( |     return PhabricatorPHID::generateNewPHID( | ||||||
|       PhabricatorPHIDConstants::PHID_TYPE_FILE); |       PhabricatorFilePHIDTypeFile::TYPECONST); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   public static function readUploadedFileData($spec) { |   public static function readUploadedFileData($spec) { | ||||||
|   | |||||||
| @@ -129,11 +129,11 @@ abstract class ConduitAPI_maniphest_Method extends ConduitAPIMethod { | |||||||
|     $file_phids = $request->getValue('filePHIDs'); |     $file_phids = $request->getValue('filePHIDs'); | ||||||
|     if ($file_phids !== null) { |     if ($file_phids !== null) { | ||||||
|       $this->validatePHIDList($file_phids, |       $this->validatePHIDList($file_phids, | ||||||
|                               PhabricatorPHIDConstants::PHID_TYPE_FILE, |                               PhabricatorFilePHIDTypeFile::TYPECONST, | ||||||
|                               'filePHIDS'); |                               'filePHIDS'); | ||||||
|       $file_map = array_fill_keys($file_phids, true); |       $file_map = array_fill_keys($file_phids, true); | ||||||
|       $attached = $task->getAttached(); |       $attached = $task->getAttached(); | ||||||
|       $attached[PhabricatorPHIDConstants::PHID_TYPE_FILE] = $file_map; |       $attached[PhabricatorFilePHIDTypeFile::TYPECONST] = $file_map; | ||||||
|  |  | ||||||
|       $changes[ManiphestTransactionType::TYPE_ATTACH] = $attached; |       $changes[ManiphestTransactionType::TYPE_ATTACH] = $attached; | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -566,7 +566,7 @@ final class ManiphestTaskDetailController extends ManiphestController { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     $attached = $task->getAttached(); |     $attached = $task->getAttached(); | ||||||
|     $file_infos = idx($attached, PhabricatorPHIDConstants::PHID_TYPE_FILE); |     $file_infos = idx($attached, PhabricatorFilePHIDTypeFile::TYPECONST); | ||||||
|     if ($file_infos) { |     if ($file_infos) { | ||||||
|       $file_phids = array_keys($file_infos); |       $file_phids = array_keys($file_infos); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -181,7 +181,7 @@ final class ManiphestTaskEditController extends ManiphestController { | |||||||
|           $file_map = mpull($files, 'getPHID'); |           $file_map = mpull($files, 'getPHID'); | ||||||
|           $file_map = array_fill_keys($file_map, array()); |           $file_map = array_fill_keys($file_map, array()); | ||||||
|           $changes[ManiphestTransactionType::TYPE_ATTACH] = array( |           $changes[ManiphestTransactionType::TYPE_ATTACH] = array( | ||||||
|             PhabricatorPHIDConstants::PHID_TYPE_FILE => $file_map, |             PhabricatorFilePHIDTypeFile::TYPECONST => $file_map, | ||||||
|           ); |           ); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -54,10 +54,10 @@ final class ManiphestTransactionSaveController extends ManiphestController { | |||||||
|       $files = mpull($files, 'getPHID', 'getPHID'); |       $files = mpull($files, 'getPHID', 'getPHID'); | ||||||
|       $new = $task->getAttached(); |       $new = $task->getAttached(); | ||||||
|       foreach ($files as $phid) { |       foreach ($files as $phid) { | ||||||
|         if (empty($new[PhabricatorPHIDConstants::PHID_TYPE_FILE])) { |         if (empty($new[PhabricatorFilePHIDTypeFile::TYPECONST])) { | ||||||
|           $new[PhabricatorPHIDConstants::PHID_TYPE_FILE] = array(); |           $new[PhabricatorFilePHIDTypeFile::TYPECONST] = array(); | ||||||
|         } |         } | ||||||
|         $new[PhabricatorPHIDConstants::PHID_TYPE_FILE][$phid] = array(); |         $new[PhabricatorFilePHIDTypeFile::TYPECONST][$phid] = array(); | ||||||
|       } |       } | ||||||
|       $transaction = new ManiphestTransaction(); |       $transaction = new ManiphestTransaction(); | ||||||
|       $transaction |       $transaction | ||||||
|   | |||||||
| @@ -242,7 +242,7 @@ final class ManiphestTransactionDetailView extends ManiphestView { | |||||||
|  |  | ||||||
|         $attach_types = array( |         $attach_types = array( | ||||||
|           DifferentialPHIDTypeRevision::TYPECONST, |           DifferentialPHIDTypeRevision::TYPECONST, | ||||||
|           PhabricatorPHIDConstants::PHID_TYPE_FILE, |           PhabricatorFilePHIDTypeFile::TYPECONST, | ||||||
|         ); |         ); | ||||||
|  |  | ||||||
|         foreach ($attach_types as $attach_type) { |         foreach ($attach_types as $attach_type) { | ||||||
| @@ -268,7 +268,7 @@ final class ManiphestTransactionDetailView extends ManiphestView { | |||||||
|           case DifferentialPHIDTypeRevision::TYPECONST: |           case DifferentialPHIDTypeRevision::TYPECONST: | ||||||
|             $title = 'ATTACHED REVISIONS'; |             $title = 'ATTACHED REVISIONS'; | ||||||
|             break; |             break; | ||||||
|           case PhabricatorPHIDConstants::PHID_TYPE_FILE: |           case PhabricatorFilePHIDTypeFile::TYPECONST: | ||||||
|             $title = 'ATTACHED FILES'; |             $title = 'ATTACHED FILES'; | ||||||
|             break; |             break; | ||||||
|         } |         } | ||||||
| @@ -484,7 +484,7 @@ final class ManiphestTransactionDetailView extends ManiphestView { | |||||||
|         foreach (array( |         foreach (array( | ||||||
|           DifferentialPHIDTypeRevision::TYPECONST, |           DifferentialPHIDTypeRevision::TYPECONST, | ||||||
|           ManiphestPHIDTypeTask::TYPECONST, |           ManiphestPHIDTypeTask::TYPECONST, | ||||||
|           PhabricatorPHIDConstants::PHID_TYPE_FILE) as $attach_type) { |           PhabricatorFilePHIDTypeFile::TYPECONST) as $attach_type) { | ||||||
|           $old = array_keys(idx($old_raw, $attach_type, array())); |           $old = array_keys(idx($old_raw, $attach_type, array())); | ||||||
|           $new = array_keys(idx($new_raw, $attach_type, array())); |           $new = array_keys(idx($new_raw, $attach_type, array())); | ||||||
|           if ($old != $new) { |           if ($old != $new) { | ||||||
| @@ -652,7 +652,7 @@ final class ManiphestTransactionDetailView extends ManiphestView { | |||||||
|     switch ($attach_type) { |     switch ($attach_type) { | ||||||
|       case DifferentialPHIDTypeRevision::TYPECONST: |       case DifferentialPHIDTypeRevision::TYPECONST: | ||||||
|         return pht('Differential Revision(s)', $count); |         return pht('Differential Revision(s)', $count); | ||||||
|       case PhabricatorPHIDConstants::PHID_TYPE_FILE: |       case PhabricatorFilePHIDTypeFile::TYPECONST: | ||||||
|         return pht('file(s)', $count); |         return pht('file(s)', $count); | ||||||
|       case ManiphestPHIDTypeTask::TYPECONST: |       case ManiphestPHIDTypeTask::TYPECONST: | ||||||
|         return pht('Maniphest Task(s)', $count); |         return pht('Maniphest Task(s)', $count); | ||||||
|   | |||||||
| @@ -112,7 +112,6 @@ final class PhabricatorObjectHandle | |||||||
|       PhabricatorPHIDConstants::PHID_TYPE_WIKI => 'Phriction Document', |       PhabricatorPHIDConstants::PHID_TYPE_WIKI => 'Phriction Document', | ||||||
|       PhabricatorPHIDConstants::PHID_TYPE_MCRO => 'Image Macro', |       PhabricatorPHIDConstants::PHID_TYPE_MCRO => 'Image Macro', | ||||||
|       PhabricatorPHIDConstants::PHID_TYPE_PIMG => 'Pholio Image', |       PhabricatorPHIDConstants::PHID_TYPE_PIMG => 'Pholio Image', | ||||||
|       PhabricatorPHIDConstants::PHID_TYPE_FILE => 'File', |  | ||||||
|       PhabricatorPHIDConstants::PHID_TYPE_BLOG => 'Blog', |       PhabricatorPHIDConstants::PHID_TYPE_BLOG => 'Blog', | ||||||
|       PhabricatorPHIDConstants::PHID_TYPE_POST => 'Post', |       PhabricatorPHIDConstants::PHID_TYPE_POST => 'Post', | ||||||
|       PhabricatorPHIDConstants::PHID_TYPE_QUES => 'Question', |       PhabricatorPHIDConstants::PHID_TYPE_QUES => 'Question', | ||||||
|   | |||||||
| @@ -3,7 +3,6 @@ | |||||||
| final class PhabricatorPHIDConstants { | final class PhabricatorPHIDConstants { | ||||||
|  |  | ||||||
|   const PHID_TYPE_USER    = 'USER'; |   const PHID_TYPE_USER    = 'USER'; | ||||||
|   const PHID_TYPE_FILE    = 'FILE'; |  | ||||||
|   const PHID_TYPE_PROJ    = 'PROJ'; |   const PHID_TYPE_PROJ    = 'PROJ'; | ||||||
|   const PHID_TYPE_UNKNOWN = '????'; |   const PHID_TYPE_UNKNOWN = '????'; | ||||||
|   const PHID_TYPE_MAGIC   = '!!!!'; |   const PHID_TYPE_MAGIC   = '!!!!'; | ||||||
|   | |||||||
| @@ -41,7 +41,7 @@ final class ConduitAPI_phid_lookup_Method | |||||||
|     foreach ($name_map as $name => $object) { |     foreach ($name_map as $name => $object) { | ||||||
|       $phid = $object->getPHID(); |       $phid = $object->getPHID(); | ||||||
|       $handle = $handles[$phid]; |       $handle = $handles[$phid]; | ||||||
|       $result[$phid] = $this->buildHandleInformationDictionary($handle); |       $result[$name] = $this->buildHandleInformationDictionary($handle); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     return $result; |     return $result; | ||||||
|   | |||||||
| @@ -56,12 +56,6 @@ final class PhabricatorObjectHandleData { | |||||||
|           $phids); |           $phids); | ||||||
|         return mpull($users, null, 'getPHID'); |         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: |       case PhabricatorPHIDConstants::PHID_TYPE_PROJ: | ||||||
|         $projects = id(new PhabricatorProjectQuery()) |         $projects = id(new PhabricatorProjectQuery()) | ||||||
|           ->setViewer($this->viewer) |           ->setViewer($this->viewer) | ||||||
| @@ -295,24 +289,6 @@ final class PhabricatorObjectHandleData { | |||||||
|           } |           } | ||||||
|           break; |           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: |         case PhabricatorPHIDConstants::PHID_TYPE_PROJ: | ||||||
|           foreach ($phids as $phid) { |           foreach ($phids as $phid) { | ||||||
|             $handle = new PhabricatorObjectHandle(); |             $handle = new PhabricatorObjectHandle(); | ||||||
|   | |||||||
| @@ -154,7 +154,6 @@ final class PhabricatorEdgeConfig extends PhabricatorEdgeConstants { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     static $class_map = array( |     static $class_map = array( | ||||||
|       PhabricatorPHIDConstants::PHID_TYPE_FILE  => 'PhabricatorFile', |  | ||||||
|       PhabricatorPHIDConstants::PHID_TYPE_USER  => 'PhabricatorUser', |       PhabricatorPHIDConstants::PHID_TYPE_USER  => 'PhabricatorUser', | ||||||
|       PhabricatorPHIDConstants::PHID_TYPE_PROJ  => 'PhabricatorProject', |       PhabricatorPHIDConstants::PHID_TYPE_PROJ  => 'PhabricatorProject', | ||||||
|       PhabricatorPHIDConstants::PHID_TYPE_TOBJ  => 'HarbormasterObject', |       PhabricatorPHIDConstants::PHID_TYPE_TOBJ  => 'HarbormasterObject', | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 epriestley
					epriestley