1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-30 01:10:58 +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', 'PonderDAO' => 'applications/ponder/storage/PonderDAO.php',
'PonderMail' => 'applications/ponder/mail/PonderMail.php', 'PonderMail' => 'applications/ponder/mail/PonderMail.php',
'PonderMentionMail' => 'applications/ponder/mail/PonderMentionMail.php', 'PonderMentionMail' => 'applications/ponder/mail/PonderMentionMail.php',
'PonderPHIDTypeQuestion' => 'applications/ponder/phid/PonderPHIDTypeQuestion.php',
'PonderPostBodyView' => 'applications/ponder/view/PonderPostBodyView.php', 'PonderPostBodyView' => 'applications/ponder/view/PonderPostBodyView.php',
'PonderQuestion' => 'applications/ponder/storage/PonderQuestion.php', 'PonderQuestion' => 'applications/ponder/storage/PonderQuestion.php',
'PonderQuestionAskController' => 'applications/ponder/controller/PonderQuestionAskController.php', 'PonderQuestionAskController' => 'applications/ponder/controller/PonderQuestionAskController.php',
@ -3945,6 +3946,7 @@ phutil_register_library_map(array(
'PonderDAO' => 'PhabricatorLiskDAO', 'PonderDAO' => 'PhabricatorLiskDAO',
'PonderMail' => 'PhabricatorMail', 'PonderMail' => 'PhabricatorMail',
'PonderMentionMail' => 'PonderMail', 'PonderMentionMail' => 'PonderMail',
'PonderPHIDTypeQuestion' => 'PhabricatorPHIDType',
'PonderPostBodyView' => 'AphrontView', 'PonderPostBodyView' => 'AphrontView',
'PonderQuestion' => 'PonderQuestion' =>
array( array(

View file

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

View file

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

View file

@ -68,13 +68,6 @@ final class PhabricatorObjectHandleData {
$phids); $phids);
return mpull($projects, null, 'getPHID'); 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: case PhabricatorPHIDConstants::PHID_TYPE_PIMG:
$images = id(new PholioImage()) $images = id(new PholioImage())
->loadAllWhere('phid IN (%Ls)', $phids); ->loadAllWhere('phid IN (%Ls)', $phids);
@ -300,25 +293,6 @@ final class PhabricatorObjectHandleData {
} }
break; 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: case PhabricatorPHIDConstants::PHID_TYPE_PSTE:
foreach ($phids as $phid) { foreach ($phids as $phid) {
$handle = new PhabricatorObjectHandle(); $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 = new PhabricatorSearchAbstractDocument();
$doc->setPHID($question->getPHID()); $doc->setPHID($question->getPHID());
$doc->setDocumentType(PhabricatorPHIDConstants::PHID_TYPE_QUES); $doc->setDocumentType(PonderPHIDTypeQuestion::TYPECONST);
$doc->setDocumentTitle($question->getTitle()); $doc->setDocumentTitle($question->getTitle());
$doc->setDocumentCreated($question->getDateCreated()); $doc->setDocumentCreated($question->getDateCreated());
$doc->setDocumentModified($question->getDateModified()); $doc->setDocumentModified($question->getDateModified());

View file

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

View file

@ -20,7 +20,7 @@ final class PhabricatorSearchAbstractDocument {
ManiphestPHIDTypeTask::TYPECONST => 'Maniphest Tasks', ManiphestPHIDTypeTask::TYPECONST => 'Maniphest Tasks',
PhrictionPHIDTypeDocument::TYPECONST => 'Phriction Documents', PhrictionPHIDTypeDocument::TYPECONST => 'Phriction Documents',
PhabricatorPHIDConstants::PHID_TYPE_USER => 'Phabricator Users', 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_TOBJ => 'HarbormasterObject',
PhabricatorPHIDConstants::PHID_TYPE_BLOG => 'PhameBlog', PhabricatorPHIDConstants::PHID_TYPE_BLOG => 'PhameBlog',
PhabricatorPHIDConstants::PHID_TYPE_POST => 'PhamePost', PhabricatorPHIDConstants::PHID_TYPE_POST => 'PhamePost',
PhabricatorPHIDConstants::PHID_TYPE_QUES => 'PonderQuestion',
PhabricatorPHIDConstants::PHID_TYPE_ANSW => 'PonderAnswer', PhabricatorPHIDConstants::PHID_TYPE_ANSW => 'PonderAnswer',
PhabricatorPHIDConstants::PHID_TYPE_MCRO => 'PhabricatorFileImageMacro', PhabricatorPHIDConstants::PHID_TYPE_MCRO => 'PhabricatorFileImageMacro',
PhabricatorPHIDConstants::PHID_TYPE_CONP => 'ConpherenceThread', PhabricatorPHIDConstants::PHID_TYPE_CONP => 'ConpherenceThread',