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:
parent
69d5a9af58
commit
d3cf7874ed
8 changed files with 83 additions and 30 deletions
|
@ -1458,6 +1458,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorRepositoryMercurialCommitChangeParserWorker' => 'applications/repository/worker/commitchangeparser/PhabricatorRepositoryMercurialCommitChangeParserWorker.php',
|
||||
'PhabricatorRepositoryMercurialCommitMessageParserWorker' => 'applications/repository/worker/commitmessageparser/PhabricatorRepositoryMercurialCommitMessageParserWorker.php',
|
||||
'PhabricatorRepositoryPHIDTypeCommit' => 'applications/repository/phid/PhabricatorRepositoryPHIDTypeCommit.php',
|
||||
'PhabricatorRepositoryPHIDTypeRepository' => 'applications/repository/phid/PhabricatorRepositoryPHIDTypeRepository.php',
|
||||
'PhabricatorRepositoryPullEngine' => 'applications/repository/engine/PhabricatorRepositoryPullEngine.php',
|
||||
'PhabricatorRepositoryPullLocalDaemon' => 'applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php',
|
||||
'PhabricatorRepositoryQuery' => 'applications/repository/query/PhabricatorRepositoryQuery.php',
|
||||
|
@ -3469,6 +3470,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorRepositoryMercurialCommitChangeParserWorker' => 'PhabricatorRepositoryCommitChangeParserWorker',
|
||||
'PhabricatorRepositoryMercurialCommitMessageParserWorker' => 'PhabricatorRepositoryCommitMessageParserWorker',
|
||||
'PhabricatorRepositoryPHIDTypeCommit' => 'PhabricatorPHIDType',
|
||||
'PhabricatorRepositoryPHIDTypeRepository' => 'PhabricatorPHIDType',
|
||||
'PhabricatorRepositoryPullEngine' => 'PhabricatorRepositoryEngine',
|
||||
'PhabricatorRepositoryPullLocalDaemon' => 'PhabricatorDaemon',
|
||||
'PhabricatorRepositoryQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
|
|
|
@ -235,7 +235,7 @@ final class PhabricatorAuditListController extends PhabricatorAuditController {
|
|||
}
|
||||
break;
|
||||
case 'repository':
|
||||
if ($type !== PhabricatorPHIDConstants::PHID_TYPE_REPO) {
|
||||
if ($type !== PhabricatorRepositoryPHIDTypeRepository::TYPECONST) {
|
||||
throw new Exception("PHID must be a repository PHID!");
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -5,7 +5,6 @@ final class PhabricatorPHIDConstants {
|
|||
const PHID_TYPE_USER = 'USER';
|
||||
const PHID_TYPE_UNKNOWN = '????';
|
||||
const PHID_TYPE_MAGIC = '!!!!';
|
||||
const PHID_TYPE_REPO = 'REPO';
|
||||
const PHID_TYPE_OPKG = 'OPKG';
|
||||
const PHID_TYPE_PSTE = 'PSTE';
|
||||
const PHID_TYPE_STRY = 'STRY';
|
||||
|
|
|
@ -56,12 +56,6 @@ final class PhabricatorObjectHandleData {
|
|||
$phids);
|
||||
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:
|
||||
$object = new PhabricatorOwnersPackage();
|
||||
$packages = $object->loadAllWhere('phid in (%Ls)', $phids);
|
||||
|
@ -282,25 +276,6 @@ final class PhabricatorObjectHandleData {
|
|||
}
|
||||
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:
|
||||
foreach ($phids as $phid) {
|
||||
$handle = new PhabricatorObjectHandle();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -63,7 +63,7 @@ final class PhabricatorRepositoryCommitSearchIndexer
|
|||
$doc->addRelationship(
|
||||
PhabricatorSearchRelationship::RELATIONSHIP_REPOSITORY,
|
||||
$repository->getPHID(),
|
||||
PhabricatorPHIDConstants::PHID_TYPE_REPO,
|
||||
PhabricatorRepositoryPHIDTypeRepository::TYPECONST,
|
||||
$date_created);
|
||||
|
||||
$comments = id(new PhabricatorAuditComment())->loadAllWhere(
|
||||
|
|
|
@ -46,7 +46,7 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
|
|||
|
||||
public function generatePHID() {
|
||||
return PhabricatorPHID::generateNewPHID(
|
||||
PhabricatorPHIDConstants::PHID_TYPE_REPO);
|
||||
PhabricatorRepositoryPHIDTypeRepository::TYPECONST);
|
||||
}
|
||||
|
||||
public function toDictionary() {
|
||||
|
|
|
@ -12,7 +12,7 @@ final class PhabricatorRepositoryTransaction
|
|||
}
|
||||
|
||||
public function getApplicationTransactionType() {
|
||||
return PhabricatorPHIDConstants::PHID_TYPE_REPO;
|
||||
return PhabricatorRepositoryPHIDTypeRepository::TYPECONST;
|
||||
}
|
||||
|
||||
public function getApplicationTransactionCommentObject() {
|
||||
|
|
Loading…
Reference in a new issue