1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-20 20:40:56 +01:00

Use Application PHIDs in Ponder

Summary: Ref T2715. Switch Ponder to the new IDs.

Test Plan: Ran `phid.lookup`; `phid.query`. Grepped for old constant

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2715

Differential Revision: https://secure.phabricator.com/D6554
This commit is contained in:
epriestley 2013-07-24 11:32:31 -07:00
parent cdbb1d5a03
commit f29861713e
9 changed files with 80 additions and 33 deletions

View file

@ -1864,6 +1864,7 @@ phutil_register_library_map(array(
'PonderDAO' => 'applications/ponder/storage/PonderDAO.php',
'PonderMail' => 'applications/ponder/mail/PonderMail.php',
'PonderMentionMail' => 'applications/ponder/mail/PonderMentionMail.php',
'PonderPHIDTypeQuestion' => 'applications/ponder/phid/PonderPHIDTypeQuestion.php',
'PonderPostBodyView' => 'applications/ponder/view/PonderPostBodyView.php',
'PonderQuestion' => 'applications/ponder/storage/PonderQuestion.php',
'PonderQuestionAskController' => 'applications/ponder/controller/PonderQuestionAskController.php',
@ -3945,6 +3946,7 @@ phutil_register_library_map(array(
'PonderDAO' => 'PhabricatorLiskDAO',
'PonderMail' => 'PhabricatorMail',
'PonderMentionMail' => 'PonderMail',
'PonderPHIDTypeQuestion' => 'PhabricatorPHIDType',
'PonderPostBodyView' => 'AphrontView',
'PonderQuestion' =>
array(

View file

@ -113,7 +113,6 @@ final class PhabricatorObjectHandle
PhabricatorPHIDConstants::PHID_TYPE_PIMG => 'Pholio Image',
PhabricatorPHIDConstants::PHID_TYPE_BLOG => 'Blog',
PhabricatorPHIDConstants::PHID_TYPE_POST => 'Post',
PhabricatorPHIDConstants::PHID_TYPE_QUES => 'Question',
PhabricatorPHIDConstants::PHID_TYPE_PVAR => 'Variable',
PhabricatorPHIDConstants::PHID_TYPE_PSTE => 'Paste',
PhabricatorPHIDConstants::PHID_TYPE_LEGD => 'Legalpad Document',

View file

@ -17,7 +17,6 @@ final class PhabricatorPHIDConstants {
const PHID_TYPE_POST = 'POST';
const PHID_TYPE_TOBJ = 'TOBJ';
const PHID_TYPE_BLOG = 'BLOG';
const PHID_TYPE_QUES = 'QUES';
const PHID_TYPE_ANSW = 'ANSW';
const PHID_TYPE_PIMG = 'PIMG';
const PHID_TYPE_MCRO = 'MCRO';

View file

@ -68,13 +68,6 @@ final class PhabricatorObjectHandleData {
$phids);
return mpull($projects, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_QUES:
$questions = id(new PonderQuestionQuery())
->setViewer($this->viewer)
->withPHIDs($phids)
->execute();
return mpull($questions, null, 'getPHID');
case PhabricatorPHIDConstants::PHID_TYPE_PIMG:
$images = id(new PholioImage())
->loadAllWhere('phid IN (%Ls)', $phids);
@ -300,25 +293,6 @@ final class PhabricatorObjectHandleData {
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_QUES:
foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle();
$handle->setPHID($phid);
$handle->setType($type);
if (empty($objects[$phid])) {
$handle->setName('Unknown Ponder Question');
} else {
$question = $objects[$phid];
$handle->setName('Q' . $question->getID());
$handle->setFullName(
phutil_utf8_shorten($question->getTitle(), 60));
$handle->setURI(new PhutilURI('/Q' . $question->getID()));
$handle->setComplete(true);
}
$handles[$phid] = $handle;
}
break;
case PhabricatorPHIDConstants::PHID_TYPE_PSTE:
foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle();

View file

@ -0,0 +1,75 @@
<?php
final class PonderPHIDTypeQuestion extends PhabricatorPHIDType {
const TYPECONST = 'QUES';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Question');
}
public function newObject() {
return new PonderQuestion();
}
public function loadObjects(
PhabricatorObjectQuery $query,
array $phids) {
return id(new PonderQuestionQuery())
->setViewer($query->getViewer())
->withPHIDs($phids)
->execute();
}
public function loadHandles(
PhabricatorHandleQuery $query,
array $handles,
array $objects) {
foreach ($handles as $phid => $handle) {
$question = $objects[$phid];
$id = $question->getID();
$title = $question->getTitle();
$handle->setName("Q{$id}");
$handle->setURI("/Q{$id}");
$handle->setFullName("Q{$id}: {$title}");
}
}
public function canLoadNamedObject($name) {
return preg_match('/^Q\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 PonderQuestionQuery())
->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

@ -14,7 +14,7 @@ final class PonderSearchIndexer
$doc = new PhabricatorSearchAbstractDocument();
$doc->setPHID($question->getPHID());
$doc->setDocumentType(PhabricatorPHIDConstants::PHID_TYPE_QUES);
$doc->setDocumentType(PonderPHIDTypeQuestion::TYPECONST);
$doc->setDocumentTitle($question->getTitle());
$doc->setDocumentCreated($question->getDateCreated());
$doc->setDocumentModified($question->getDateModified());

View file

@ -33,8 +33,7 @@ final class PonderQuestion extends PonderDAO
}
public function generatePHID() {
return PhabricatorPHID::generateNewPHID(
PhabricatorPHIDConstants::PHID_TYPE_QUES);
return PhabricatorPHID::generateNewPHID(PonderPHIDTypeQuestion::TYPECONST);
}
public function setContentSource(PhabricatorContentSource $content_source) {

View file

@ -20,7 +20,7 @@ final class PhabricatorSearchAbstractDocument {
ManiphestPHIDTypeTask::TYPECONST => 'Maniphest Tasks',
PhrictionPHIDTypeDocument::TYPECONST => 'Phriction Documents',
PhabricatorPHIDConstants::PHID_TYPE_USER => 'Phabricator Users',
PhabricatorPHIDConstants::PHID_TYPE_QUES => 'Ponder Questions',
PonderPHIDTypeQuestion::TYPECONST => 'Ponder Questions',
);
}

View file

@ -158,7 +158,6 @@ final class PhabricatorEdgeConfig extends PhabricatorEdgeConstants {
PhabricatorPHIDConstants::PHID_TYPE_TOBJ => 'HarbormasterObject',
PhabricatorPHIDConstants::PHID_TYPE_BLOG => 'PhameBlog',
PhabricatorPHIDConstants::PHID_TYPE_POST => 'PhamePost',
PhabricatorPHIDConstants::PHID_TYPE_QUES => 'PonderQuestion',
PhabricatorPHIDConstants::PHID_TYPE_ANSW => 'PonderAnswer',
PhabricatorPHIDConstants::PHID_TYPE_MCRO => 'PhabricatorFileImageMacro',
PhabricatorPHIDConstants::PHID_TYPE_CONP => 'ConpherenceThread',