1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-02 02:40:58 +01:00

Use application PHIDs in Repositories

Summary: Ref T2715. Move repositories to new app PHIDs.

Test Plan: Used `phid.lookup`; `phid.query`; browsed Diffusion.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2715

Differential Revision: https://secure.phabricator.com/D6529
This commit is contained in:
epriestley 2013-07-22 10:45:12 -07:00
parent 69d5a9af58
commit d3cf7874ed
8 changed files with 83 additions and 30 deletions

View file

@ -1458,6 +1458,7 @@ phutil_register_library_map(array(
'PhabricatorRepositoryMercurialCommitChangeParserWorker' => 'applications/repository/worker/commitchangeparser/PhabricatorRepositoryMercurialCommitChangeParserWorker.php', 'PhabricatorRepositoryMercurialCommitChangeParserWorker' => 'applications/repository/worker/commitchangeparser/PhabricatorRepositoryMercurialCommitChangeParserWorker.php',
'PhabricatorRepositoryMercurialCommitMessageParserWorker' => 'applications/repository/worker/commitmessageparser/PhabricatorRepositoryMercurialCommitMessageParserWorker.php', 'PhabricatorRepositoryMercurialCommitMessageParserWorker' => 'applications/repository/worker/commitmessageparser/PhabricatorRepositoryMercurialCommitMessageParserWorker.php',
'PhabricatorRepositoryPHIDTypeCommit' => 'applications/repository/phid/PhabricatorRepositoryPHIDTypeCommit.php', 'PhabricatorRepositoryPHIDTypeCommit' => 'applications/repository/phid/PhabricatorRepositoryPHIDTypeCommit.php',
'PhabricatorRepositoryPHIDTypeRepository' => 'applications/repository/phid/PhabricatorRepositoryPHIDTypeRepository.php',
'PhabricatorRepositoryPullEngine' => 'applications/repository/engine/PhabricatorRepositoryPullEngine.php', 'PhabricatorRepositoryPullEngine' => 'applications/repository/engine/PhabricatorRepositoryPullEngine.php',
'PhabricatorRepositoryPullLocalDaemon' => 'applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php', 'PhabricatorRepositoryPullLocalDaemon' => 'applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php',
'PhabricatorRepositoryQuery' => 'applications/repository/query/PhabricatorRepositoryQuery.php', 'PhabricatorRepositoryQuery' => 'applications/repository/query/PhabricatorRepositoryQuery.php',
@ -3469,6 +3470,7 @@ phutil_register_library_map(array(
'PhabricatorRepositoryMercurialCommitChangeParserWorker' => 'PhabricatorRepositoryCommitChangeParserWorker', 'PhabricatorRepositoryMercurialCommitChangeParserWorker' => 'PhabricatorRepositoryCommitChangeParserWorker',
'PhabricatorRepositoryMercurialCommitMessageParserWorker' => 'PhabricatorRepositoryCommitMessageParserWorker', 'PhabricatorRepositoryMercurialCommitMessageParserWorker' => 'PhabricatorRepositoryCommitMessageParserWorker',
'PhabricatorRepositoryPHIDTypeCommit' => 'PhabricatorPHIDType', 'PhabricatorRepositoryPHIDTypeCommit' => 'PhabricatorPHIDType',
'PhabricatorRepositoryPHIDTypeRepository' => 'PhabricatorPHIDType',
'PhabricatorRepositoryPullEngine' => 'PhabricatorRepositoryEngine', 'PhabricatorRepositoryPullEngine' => 'PhabricatorRepositoryEngine',
'PhabricatorRepositoryPullLocalDaemon' => 'PhabricatorDaemon', 'PhabricatorRepositoryPullLocalDaemon' => 'PhabricatorDaemon',
'PhabricatorRepositoryQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhabricatorRepositoryQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',

View file

@ -235,7 +235,7 @@ final class PhabricatorAuditListController extends PhabricatorAuditController {
} }
break; break;
case 'repository': case 'repository':
if ($type !== PhabricatorPHIDConstants::PHID_TYPE_REPO) { if ($type !== PhabricatorRepositoryPHIDTypeRepository::TYPECONST) {
throw new Exception("PHID must be a repository PHID!"); throw new Exception("PHID must be a repository PHID!");
} }
break; break;

View file

@ -5,7 +5,6 @@ final class PhabricatorPHIDConstants {
const PHID_TYPE_USER = 'USER'; const PHID_TYPE_USER = 'USER';
const PHID_TYPE_UNKNOWN = '????'; const PHID_TYPE_UNKNOWN = '????';
const PHID_TYPE_MAGIC = '!!!!'; const PHID_TYPE_MAGIC = '!!!!';
const PHID_TYPE_REPO = 'REPO';
const PHID_TYPE_OPKG = 'OPKG'; const PHID_TYPE_OPKG = 'OPKG';
const PHID_TYPE_PSTE = 'PSTE'; const PHID_TYPE_PSTE = 'PSTE';
const PHID_TYPE_STRY = 'STRY'; const PHID_TYPE_STRY = 'STRY';

View file

@ -56,12 +56,6 @@ final class PhabricatorObjectHandleData {
$phids); $phids);
return mpull($users, null, 'getPHID'); return mpull($users, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_REPO:
// TODO: Update this to PhabricatorRepositoryQuery
$object = new PhabricatorRepository();
$repositories = $object->loadAllWhere('phid in (%Ls)', $phids);
return mpull($repositories, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_OPKG: case PhabricatorPHIDConstants::PHID_TYPE_OPKG:
$object = new PhabricatorOwnersPackage(); $object = new PhabricatorOwnersPackage();
$packages = $object->loadAllWhere('phid in (%Ls)', $phids); $packages = $object->loadAllWhere('phid in (%Ls)', $phids);
@ -282,25 +276,6 @@ final class PhabricatorObjectHandleData {
} }
break; break;
case PhabricatorPHIDConstants::PHID_TYPE_REPO:
foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle();
$handle->setPHID($phid);
$handle->setType($type);
if (empty($objects[$phid])) {
$handle->setName('Unknown Repository');
} else {
$repository = $objects[$phid];
$handle->setName('r'.$repository->getCallsign());
$handle->setFullName("r" . $repository->getCallsign() .
" (" . $repository->getName() . ")");
$handle->setURI('/diffusion/'.$repository->getCallsign().'/');
$handle->setComplete(true);
}
$handles[$phid] = $handle;
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_OPKG: case PhabricatorPHIDConstants::PHID_TYPE_OPKG:
foreach ($phids as $phid) { foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle(); $handle = new PhabricatorObjectHandle();

View file

@ -0,0 +1,77 @@
<?php
final class PhabricatorRepositoryPHIDTypeRepository
extends PhabricatorPHIDType {
const TYPECONST = 'REPO';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Repository');
}
public function newObject() {
return new PhabricatorRepository();
}
public function loadObjects(
PhabricatorObjectQuery $query,
array $phids) {
return id(new PhabricatorRepositoryQuery())
->setViewer($query->getViewer())
->withPHIDs($phids)
->execute();
}
public function loadHandles(
PhabricatorHandleQuery $query,
array $handles,
array $objects) {
foreach ($handles as $phid => $handle) {
$repository = $objects[$phid];
$callsign = $repository->getCallsign();
$name = $repository->getName();
$handle->setName("r{$callsign}");
$handle->setFullName("r{$callsign} ({$name})");
$handle->setURI("/diffusion/{$callsign}/");
}
}
public function canLoadNamedObject($name) {
return preg_match('/^r[A-Z]+$/', $name);
}
public function loadNamedObjects(
PhabricatorObjectQuery $query,
array $names) {
$id_map = array();
foreach ($names as $name) {
$id = substr($name, 1);
$id_map[$id][] = $name;
}
$objects = id(new PhabricatorRepositoryQuery())
->setViewer($query->getViewer())
->withCallsigns(array_keys($id_map))
->execute();
$results = array();
foreach ($objects as $object) {
$callsign = $object->getCallsign();
foreach (idx($id_map, $callsign, array()) as $name) {
$results[$name] = $object;
}
}
return $results;
}
}

View file

@ -63,7 +63,7 @@ final class PhabricatorRepositoryCommitSearchIndexer
$doc->addRelationship( $doc->addRelationship(
PhabricatorSearchRelationship::RELATIONSHIP_REPOSITORY, PhabricatorSearchRelationship::RELATIONSHIP_REPOSITORY,
$repository->getPHID(), $repository->getPHID(),
PhabricatorPHIDConstants::PHID_TYPE_REPO, PhabricatorRepositoryPHIDTypeRepository::TYPECONST,
$date_created); $date_created);
$comments = id(new PhabricatorAuditComment())->loadAllWhere( $comments = id(new PhabricatorAuditComment())->loadAllWhere(

View file

@ -46,7 +46,7 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
public function generatePHID() { public function generatePHID() {
return PhabricatorPHID::generateNewPHID( return PhabricatorPHID::generateNewPHID(
PhabricatorPHIDConstants::PHID_TYPE_REPO); PhabricatorRepositoryPHIDTypeRepository::TYPECONST);
} }
public function toDictionary() { public function toDictionary() {

View file

@ -12,7 +12,7 @@ final class PhabricatorRepositoryTransaction
} }
public function getApplicationTransactionType() { public function getApplicationTransactionType() {
return PhabricatorPHIDConstants::PHID_TYPE_REPO; return PhabricatorRepositoryPHIDTypeRepository::TYPECONST;
} }
public function getApplicationTransactionCommentObject() { public function getApplicationTransactionCommentObject() {