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 Paste

Summary: Ref T2715. Switch Paste to application PHIDs.

Test Plan: Used `conduit.query`; `conduit.lookup`; grepped for constants.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2715

Differential Revision: https://secure.phabricator.com/D6555
This commit is contained in:
epriestley 2013-07-24 11:32:49 -07:00
parent f29861713e
commit f1cd3bc359
7 changed files with 79 additions and 29 deletions

View file

@ -1353,6 +1353,7 @@ phutil_register_library_map(array(
'PhabricatorPasteDAO' => 'applications/paste/storage/PhabricatorPasteDAO.php',
'PhabricatorPasteEditController' => 'applications/paste/controller/PhabricatorPasteEditController.php',
'PhabricatorPasteListController' => 'applications/paste/controller/PhabricatorPasteListController.php',
'PhabricatorPastePHIDTypePaste' => 'applications/paste/phid/PhabricatorPastePHIDTypePaste.php',
'PhabricatorPasteQuery' => 'applications/paste/query/PhabricatorPasteQuery.php',
'PhabricatorPasteRemarkupRule' => 'applications/paste/remarkup/PhabricatorPasteRemarkupRule.php',
'PhabricatorPasteSearchEngine' => 'applications/paste/query/PhabricatorPasteSearchEngine.php',
@ -3367,6 +3368,7 @@ phutil_register_library_map(array(
0 => 'PhabricatorPasteController',
1 => 'PhabricatorApplicationSearchResultsControllerInterface',
),
'PhabricatorPastePHIDTypePaste' => 'PhabricatorPHIDType',
'PhabricatorPasteQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorPasteRemarkupRule' => 'PhabricatorRemarkupRuleObject',
'PhabricatorPasteSearchEngine' => 'PhabricatorApplicationSearchEngine',

View file

@ -0,0 +1,75 @@
<?php
final class PhabricatorPastePHIDTypePaste extends PhabricatorPHIDType {
const TYPECONST = 'PSTE';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Paste');
}
public function newObject() {
return new PhabricatorPaste();
}
public function loadObjects(
PhabricatorObjectQuery $query,
array $phids) {
return id(new PhabricatorPasteQuery())
->setViewer($query->getViewer())
->withPHIDs($phids)
->execute();
}
public function loadHandles(
PhabricatorHandleQuery $query,
array $handles,
array $objects) {
foreach ($handles as $phid => $handle) {
$paste = $objects[$phid];
$id = $paste->getID();
$name = $paste->getFullName();
$handle->setName("P{$id}");
$handle->setFullName("P{$id}: {$name}");
$handle->setURI("/P{$id}");
}
}
public function canLoadNamedObject($name) {
return preg_match('/^P\d*[1-9]\d*$/i', $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 PhabricatorPasteQuery())
->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;
}
}

View file

@ -26,7 +26,7 @@ final class PhabricatorPaste extends PhabricatorPasteDAO
public function generatePHID() {
return PhabricatorPHID::generateNewPHID(
PhabricatorPHIDConstants::PHID_TYPE_PSTE);
PhabricatorPastePHIDTypePaste::TYPECONST);
}
public function getCapabilities() {

View file

@ -114,7 +114,6 @@ final class PhabricatorObjectHandle
PhabricatorPHIDConstants::PHID_TYPE_BLOG => 'Blog',
PhabricatorPHIDConstants::PHID_TYPE_POST => 'Post',
PhabricatorPHIDConstants::PHID_TYPE_PVAR => 'Variable',
PhabricatorPHIDConstants::PHID_TYPE_PSTE => 'Paste',
PhabricatorPHIDConstants::PHID_TYPE_LEGD => 'Legalpad Document',
);

View file

@ -6,7 +6,6 @@ final class PhabricatorPHIDConstants {
const PHID_TYPE_UNKNOWN = '????';
const PHID_TYPE_MAGIC = '!!!!';
const PHID_TYPE_OPKG = 'OPKG';
const PHID_TYPE_PSTE = 'PSTE';
const PHID_TYPE_STRY = 'STRY';
const PHID_TYPE_APRJ = 'APRJ';
const PHID_TYPE_ACMT = 'ACMT';

View file

@ -107,13 +107,6 @@ final class PhabricatorObjectHandleData {
->execute();
return mpull($macros, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_PSTE:
$pastes = id(new PhabricatorPasteQuery())
->withPHIDs($phids)
->setViewer($this->viewer)
->execute();
return mpull($pastes, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_BLOG:
$blogs = id(new PhameBlogQuery())
->withPHIDs($phids)
@ -293,24 +286,6 @@ final class PhabricatorObjectHandleData {
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_PSTE:
foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle();
$handle->setPHID($phid);
$handle->setType($type);
if (empty($objects[$phid])) {
$handle->setName('Unknown Paste');
} else {
$paste = $objects[$phid];
$handle->setName('P'.$paste->getID());
$handle->setFullName($paste->getFullName());
$handle->setURI('/P'.$paste->getID());
$handle->setComplete(true);
}
$handles[$phid] = $handle;
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_BLOG:
foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle();

View file

@ -44,7 +44,7 @@ final class PonderPHIDTypeQuestion extends PhabricatorPHIDType {
}
public function canLoadNamedObject($name) {
return preg_match('/^Q\d*[1-9]\d*$/', $name);
return preg_match('/^Q\d*[1-9]\d*$/i', $name);
}
public function loadNamedObjects(