1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-21 04:50:55 +01:00

Use Application PHIDs in Projects

Summary: Ref T2715. Move Projects to the new stuff.

Test Plan: Used `phid.query` to load projects.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2715

Differential Revision: https://secure.phabricator.com/D6526
This commit is contained in:
epriestley 2013-07-22 09:26:26 -07:00
parent b574b3ff8e
commit 69d5a9af58
16 changed files with 71 additions and 49 deletions

View file

@ -1398,6 +1398,7 @@ phutil_register_library_map(array(
'PhabricatorProjectListController' => 'applications/project/controller/PhabricatorProjectListController.php',
'PhabricatorProjectMembersEditController' => 'applications/project/controller/PhabricatorProjectMembersEditController.php',
'PhabricatorProjectNameCollisionException' => 'applications/project/exception/PhabricatorProjectNameCollisionException.php',
'PhabricatorProjectPHIDTypeProject' => 'applications/project/phid/PhabricatorProjectPHIDTypeProject.php',
'PhabricatorProjectProfile' => 'applications/project/storage/PhabricatorProjectProfile.php',
'PhabricatorProjectProfileController' => 'applications/project/controller/PhabricatorProjectProfileController.php',
'PhabricatorProjectProfileEditController' => 'applications/project/controller/PhabricatorProjectProfileEditController.php',
@ -3402,6 +3403,7 @@ phutil_register_library_map(array(
),
'PhabricatorProjectMembersEditController' => 'PhabricatorProjectController',
'PhabricatorProjectNameCollisionException' => 'Exception',
'PhabricatorProjectPHIDTypeProject' => 'PhabricatorPHIDType',
'PhabricatorProjectProfile' => 'PhabricatorProjectDAO',
'PhabricatorProjectProfileController' => 'PhabricatorProjectController',
'PhabricatorProjectProfileEditController' => 'PhabricatorProjectController',

View file

@ -213,27 +213,29 @@ final class PhabricatorAuditListController extends PhabricatorAuditController {
}
private function validateHandle(PhabricatorObjectHandle $handle) {
$type = $handle->getType();
switch ($this->filter) {
case 'active':
case 'user':
case 'author':
if ($handle->getType() !== PhabricatorPHIDConstants::PHID_TYPE_USER) {
if ($type !== PhabricatorPHIDConstants::PHID_TYPE_USER) {
throw new Exception("PHID must be a user PHID!");
}
break;
case 'package':
case 'packagecommits':
if ($handle->getType() !== PhabricatorPHIDConstants::PHID_TYPE_OPKG) {
if ($type !== PhabricatorPHIDConstants::PHID_TYPE_OPKG) {
throw new Exception("PHID must be a package PHID!");
}
break;
case 'project':
if ($handle->getType() !== PhabricatorPHIDConstants::PHID_TYPE_PROJ) {
if ($type !== PhabricatorProjectPHIDTypeProject::TYPECONST) {
throw new Exception("PHID must be a project PHID!");
}
break;
case 'repository':
if ($handle->getType() !== PhabricatorPHIDConstants::PHID_TYPE_REPO) {
if ($type !== PhabricatorPHIDConstants::PHID_TYPE_REPO) {
throw new Exception("PHID must be a repository PHID!");
}
break;

View file

@ -121,7 +121,7 @@ abstract class ConduitAPI_maniphest_Method extends ConduitAPIMethod {
$project_phids = $request->getValue('projectPHIDs');
if ($project_phids !== null) {
$this->validatePHIDList($project_phids,
PhabricatorPHIDConstants::PHID_TYPE_PROJ,
PhabricatorProjectPHIDTypeProject::TYPECONST,
'projectPHIDS');
$changes[ManiphestTransactionType::TYPE_PROJECTS] = $project_phids;
}

View file

@ -80,7 +80,7 @@ final class ManiphestSearchIndexer
$doc->addRelationship(
PhabricatorSearchRelationship::RELATIONSHIP_PROJECT,
$phid,
PhabricatorPHIDConstants::PHID_TYPE_PROJ,
PhabricatorProjectPHIDTypeProject::TYPECONST,
$task->getDateModified()); // Bogus.
}

View file

@ -45,7 +45,7 @@ final class ConduitAPI_owners_query_Method
protected static function queryByOwner($owner) {
$is_valid_phid =
phid_get_type($owner) == PhabricatorPHIDConstants::PHID_TYPE_USER ||
phid_get_type($owner) == PhabricatorPHIDConstants::PHID_TYPE_PROJ;
phid_get_type($owner) == PhabricatorProjectPHIDTypeProject::TYPECONST;
if (!$is_valid_phid) {
throw id(new ConduitException('ERR-INVALID-PARAMETER'))

View file

@ -42,7 +42,9 @@ final class PhabricatorOwnersOwner extends PhabricatorOwnersDAO {
array());
$users_in_project_phids = array();
$project_phids = idx($all_phids, PhabricatorPHIDConstants::PHID_TYPE_PROJ);
$project_phids = idx(
$all_phids,
PhabricatorProjectPHIDTypeProject::TYPECONST);
if ($project_phids) {
$query = id(new PhabricatorEdgeQuery())
->withSourcePHIDs($project_phids)

View file

@ -117,7 +117,6 @@ final class PhabricatorObjectHandle
PhabricatorPHIDConstants::PHID_TYPE_QUES => 'Question',
PhabricatorPHIDConstants::PHID_TYPE_PVAR => 'Variable',
PhabricatorPHIDConstants::PHID_TYPE_PSTE => 'Paste',
PhabricatorPHIDConstants::PHID_TYPE_PROJ => 'Project',
PhabricatorPHIDConstants::PHID_TYPE_LEGD => 'Legalpad Document',
);

View file

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

View file

@ -56,13 +56,6 @@ final class PhabricatorObjectHandleData {
$phids);
return mpull($users, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_PROJ:
$projects = id(new PhabricatorProjectQuery())
->setViewer($this->viewer)
->withPHIDs($phids)
->execute();
return mpull($projects, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_REPO:
// TODO: Update this to PhabricatorRepositoryQuery
$object = new PhabricatorRepository();
@ -289,23 +282,6 @@ final class PhabricatorObjectHandleData {
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_PROJ:
foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle();
$handle->setPHID($phid);
$handle->setType($type);
if (empty($objects[$phid])) {
$handle->setName('Unknown Project');
} else {
$project = $objects[$phid];
$handle->setName($project->getName());
$handle->setURI('/project/view/'.$project->getID().'/');
$handle->setComplete(true);
}
$handles[$phid] = $handle;
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_REPO:
foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle();

View file

@ -16,14 +16,7 @@ function phid_get_type($phid) {
}
/**
* Group a list of phids by type. Given:
*
* phid_group_by_type([PHID-USER-1, PHID-USER-2, PHID-PROJ-3])
*
* phid_group_by_type would return:
*
* [PhabricatorPHIDConstants::PHID_TYPE_USER => [PHID-USER-1, PHID-USER-2],
* PhabricatorPHIDConstants::PHID_TYPE_PROJ => [PHID-PROJ-3]]
* Group a list of phids by type.
*
* @param phids array of phids
* @return map of phid type => list of phids

View file

@ -37,7 +37,7 @@ final class PhabricatorPolicy {
$phid_type = phid_get_type($policy_identifier);
switch ($phid_type) {
case PhabricatorPHIDConstants::PHID_TYPE_PROJ:
case PhabricatorProjectPHIDTypeProject::TYPECONST:
$policy->setType(PhabricatorPolicyType::TYPE_PROJECT);
$policy->setName($handle->getName());
break;

View file

@ -84,7 +84,7 @@ final class PhabricatorPolicyFilter {
$policy = $object->getPolicy($capability);
$type = phid_get_type($policy);
if ($type == PhabricatorPHIDConstants::PHID_TYPE_PROJ) {
if ($type == PhabricatorProjectPHIDTypeProject::TYPECONST) {
$need_projects[] = $policy;
}
}
@ -203,7 +203,7 @@ final class PhabricatorPolicyFilter {
break;
default:
$type = phid_get_type($policy);
if ($type == PhabricatorPHIDConstants::PHID_TYPE_PROJ) {
if ($type == PhabricatorProjectPHIDTypeProject::TYPECONST) {
if (isset($this->userProjects[$viewer->getPHID()][$policy])) {
return true;
} else {
@ -268,7 +268,7 @@ final class PhabricatorPolicyFilter {
$this->viewer);
$type = phid_get_type($policy);
if ($type == PhabricatorPHIDConstants::PHID_TYPE_PROJ) {
if ($type == PhabricatorProjectPHIDTypeProject::TYPECONST) {
$who = "To {$verb} this object, you must be a member of project ".
"'".$handle->getFullName()."'.";
} else if ($type == PhabricatorPHIDConstants::PHID_TYPE_USER) {

View file

@ -0,0 +1,50 @@
<?php
final class PhabricatorProjectPHIDTypeProject extends PhabricatorPHIDType {
const TYPECONST = 'PROJ';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Project');
}
public function newObject() {
return new PhabricatorProject();
}
public function loadObjects(
PhabricatorObjectQuery $query,
array $phids) {
return id(new PhabricatorProjectQuery())
->setViewer($query->getViewer())
->withPHIDs($phids)
->execute();
}
public function loadHandles(
PhabricatorHandleQuery $query,
array $handles,
array $objects) {
foreach ($handles as $phid => $handle) {
$project = $objects[$phid];
$name = $project->getName();
$id = $project->getID();
$handle->setName($name);
$handle->setURI("/project/view/{$id}/");
}
}
public function canLoadNamedObject($name) {
// TODO: We should be able to load named projects by hashtag, e.g. "#yolo".
return false;
}
}

View file

@ -84,7 +84,7 @@ final class PhabricatorProject extends PhabricatorProjectDAO
public function generatePHID() {
return PhabricatorPHID::generateNewPHID(
PhabricatorPHIDConstants::PHID_TYPE_PROJ);
PhabricatorProjectPHIDTypeProject::TYPECONST);
}
public function loadProfile() {

View file

@ -55,7 +55,7 @@ final class PhabricatorRepositoryCommitSearchIndexer
$doc->addRelationship(
PhabricatorSearchRelationship::RELATIONSHIP_PROJECT,
$project_phid,
PhabricatorPHIDConstants::PHID_TYPE_PROJ,
PhabricatorProjectPHIDTypeProject::TYPECONST,
$date_created);
}
}

View file

@ -155,7 +155,6 @@ final class PhabricatorEdgeConfig extends PhabricatorEdgeConstants {
static $class_map = array(
PhabricatorPHIDConstants::PHID_TYPE_USER => 'PhabricatorUser',
PhabricatorPHIDConstants::PHID_TYPE_PROJ => 'PhabricatorProject',
PhabricatorPHIDConstants::PHID_TYPE_TOBJ => 'HarbormasterObject',
PhabricatorPHIDConstants::PHID_TYPE_BLOG => 'PhameBlog',
PhabricatorPHIDConstants::PHID_TYPE_POST => 'PhamePost',