mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
Use application PHIDs in Phriction
Summary: Ref T2715. Moves Phriction to application PHIDs. Test Plan: Used `phid.query`; browsed Phriction. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2715 Differential Revision: https://secure.phabricator.com/D6553
This commit is contained in:
parent
af321df3c0
commit
cdbb1d5a03
12 changed files with 93 additions and 70 deletions
|
@ -1840,6 +1840,7 @@ phutil_register_library_map(array(
|
|||
'PhrictionListController' => 'applications/phriction/controller/PhrictionListController.php',
|
||||
'PhrictionMoveController' => 'applications/phriction/controller/PhrictionMoveController.php',
|
||||
'PhrictionNewController' => 'applications/phriction/controller/PhrictionNewController.php',
|
||||
'PhrictionPHIDTypeDocument' => 'applications/phriction/phid/PhrictionPHIDTypeDocument.php',
|
||||
'PhrictionRemarkupRule' => 'applications/phriction/remarkup/PhrictionRemarkupRule.php',
|
||||
'PhrictionSearchIndexer' => 'applications/phriction/search/PhrictionSearchIndexer.php',
|
||||
'PonderAddAnswerView' => 'applications/ponder/view/PonderAddAnswerView.php',
|
||||
|
@ -3912,6 +3913,7 @@ phutil_register_library_map(array(
|
|||
'PhrictionListController' => 'PhrictionController',
|
||||
'PhrictionMoveController' => 'PhrictionController',
|
||||
'PhrictionNewController' => 'PhrictionController',
|
||||
'PhrictionPHIDTypeDocument' => 'PhabricatorPHIDType',
|
||||
'PhrictionRemarkupRule' => 'PhutilRemarkupRule',
|
||||
'PhrictionSearchIndexer' => 'PhabricatorSearchDocumentIndexer',
|
||||
'PonderAddAnswerView' => 'AphrontView',
|
||||
|
|
|
@ -109,7 +109,6 @@ final class PhabricatorObjectHandle
|
|||
|
||||
static $map = array(
|
||||
PhabricatorPHIDConstants::PHID_TYPE_USER => 'User',
|
||||
PhabricatorPHIDConstants::PHID_TYPE_WIKI => 'Phriction Document',
|
||||
PhabricatorPHIDConstants::PHID_TYPE_MCRO => 'Image Macro',
|
||||
PhabricatorPHIDConstants::PHID_TYPE_PIMG => 'Pholio Image',
|
||||
PhabricatorPHIDConstants::PHID_TYPE_BLOG => 'Blog',
|
||||
|
|
|
@ -8,7 +8,6 @@ final class PhabricatorPHIDConstants {
|
|||
const PHID_TYPE_OPKG = 'OPKG';
|
||||
const PHID_TYPE_PSTE = 'PSTE';
|
||||
const PHID_TYPE_STRY = 'STRY';
|
||||
const PHID_TYPE_WIKI = 'WIKI';
|
||||
const PHID_TYPE_APRJ = 'APRJ';
|
||||
const PHID_TYPE_ACMT = 'ACMT';
|
||||
const PHID_TYPE_DRYR = 'DRYR';
|
||||
|
|
|
@ -68,15 +68,6 @@ final class PhabricatorObjectHandleData {
|
|||
$phids);
|
||||
return mpull($projects, null, 'getPHID');
|
||||
|
||||
case PhabricatorPHIDConstants::PHID_TYPE_WIKI:
|
||||
// TODO: Update this to PhrictionDocumentQuery, already pre-package
|
||||
// content DAO
|
||||
$document_dao = new PhrictionDocument();
|
||||
$documents = $document_dao->loadAllWhere(
|
||||
'phid IN (%Ls)',
|
||||
$phids);
|
||||
return mpull($documents, null, 'getPHID');
|
||||
|
||||
case PhabricatorPHIDConstants::PHID_TYPE_QUES:
|
||||
$questions = id(new PonderQuestionQuery())
|
||||
->setViewer($this->viewer)
|
||||
|
@ -309,43 +300,6 @@ final class PhabricatorObjectHandleData {
|
|||
}
|
||||
break;
|
||||
|
||||
case PhabricatorPHIDConstants::PHID_TYPE_WIKI:
|
||||
// TODO: Update this
|
||||
$document_dao = new PhrictionDocument();
|
||||
$content_dao = new PhrictionContent();
|
||||
|
||||
$conn = $document_dao->establishConnection('r');
|
||||
$documents = queryfx_all(
|
||||
$conn,
|
||||
'SELECT * FROM %T document JOIN %T content
|
||||
ON document.contentID = content.id
|
||||
WHERE document.phid IN (%Ls)',
|
||||
$document_dao->getTableName(),
|
||||
$content_dao->getTableName(),
|
||||
$phids);
|
||||
$documents = ipull($documents, null, 'phid');
|
||||
|
||||
foreach ($phids as $phid) {
|
||||
$handle = new PhabricatorObjectHandle();
|
||||
$handle->setPHID($phid);
|
||||
$handle->setType($type);
|
||||
if (empty($documents[$phid])) {
|
||||
$handle->setName('Unknown Document');
|
||||
} else {
|
||||
$info = $documents[$phid];
|
||||
$handle->setName($info['title']);
|
||||
$handle->setURI(PhrictionDocument::getSlugURI($info['slug']));
|
||||
$handle->setFullName($info['title']);
|
||||
$handle->setComplete(true);
|
||||
if ($info['status'] != PhrictionDocumentStatus::STATUS_EXISTS) {
|
||||
$closed = PhabricatorObjectHandleStatus::STATUS_CLOSED;
|
||||
$handle->setStatus($closed);
|
||||
}
|
||||
}
|
||||
$handles[$phid] = $handle;
|
||||
}
|
||||
break;
|
||||
|
||||
case PhabricatorPHIDConstants::PHID_TYPE_QUES:
|
||||
foreach ($phids as $phid) {
|
||||
$handle = new PhabricatorObjectHandle();
|
||||
|
|
|
@ -25,9 +25,10 @@ final class PhrictionDocumentController
|
|||
|
||||
require_celerity_resource('phriction-document-css');
|
||||
|
||||
$document = id(new PhrictionDocument())->loadOneWhere(
|
||||
'slug = %s',
|
||||
$slug);
|
||||
$document = id(new PhrictionDocumentQuery())
|
||||
->setViewer($user)
|
||||
->withSlugs(array($slug))
|
||||
->executeOne();
|
||||
|
||||
$version_note = null;
|
||||
$core_content = '';
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
final class PhrictionPHIDTypeDocument extends PhabricatorPHIDType {
|
||||
|
||||
const TYPECONST = 'WIKI';
|
||||
|
||||
public function getTypeConstant() {
|
||||
return self::TYPECONST;
|
||||
}
|
||||
|
||||
public function getTypeName() {
|
||||
return pht('Wiki Document');
|
||||
}
|
||||
|
||||
public function newObject() {
|
||||
return new PhrictionDocument();
|
||||
}
|
||||
|
||||
public function loadObjects(
|
||||
PhabricatorObjectQuery $query,
|
||||
array $phids) {
|
||||
|
||||
return id(new PhrictionDocumentQuery())
|
||||
->setViewer($query->getViewer())
|
||||
->withPHIDs($phids)
|
||||
->execute();
|
||||
}
|
||||
|
||||
public function loadHandles(
|
||||
PhabricatorHandleQuery $query,
|
||||
array $handles,
|
||||
array $objects) {
|
||||
|
||||
foreach ($handles as $phid => $handle) {
|
||||
$document = $objects[$phid];
|
||||
$content = $document->getContent();
|
||||
|
||||
$title = $content->getTitle();
|
||||
$slug = $document->getSlug();
|
||||
$status = $document->getStatus();
|
||||
|
||||
$handle->setName($title);
|
||||
$handle->setURI(PhrictionDocument::getSlugURI($slug));
|
||||
|
||||
if ($status != PhrictionDocumentStatus::STATUS_EXISTS) {
|
||||
$handle->setStatus(PhabricatorObjectHandleStatus::STATUS_CLOSED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function canLoadNamedObject($name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -8,6 +8,7 @@ final class PhrictionDocumentQuery
|
|||
|
||||
private $ids;
|
||||
private $phids;
|
||||
private $slugs;
|
||||
|
||||
private $status = 'status-any';
|
||||
const STATUS_ANY = 'status-any';
|
||||
|
@ -28,6 +29,11 @@ final class PhrictionDocumentQuery
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function withSlugs(array $slugs) {
|
||||
$this->slugs = $slugs;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withStatus($status) {
|
||||
$this->status = $status;
|
||||
return $this;
|
||||
|
@ -71,6 +77,10 @@ final class PhrictionDocumentQuery
|
|||
$document->attachContent($contents[$content_id]);
|
||||
}
|
||||
|
||||
foreach ($documents as $document) {
|
||||
$document->attachProject(null);
|
||||
}
|
||||
|
||||
$project_slugs = array();
|
||||
foreach ($documents as $key => $document) {
|
||||
$slug = $document->getSlug();
|
||||
|
@ -115,10 +125,17 @@ final class PhrictionDocumentQuery
|
|||
if ($this->phids) {
|
||||
$where[] = qsprintf(
|
||||
$conn,
|
||||
'id IN (%Ld)',
|
||||
'phid IN (%Ls)',
|
||||
$this->phids);
|
||||
}
|
||||
|
||||
if ($this->slugs) {
|
||||
$where[] = qsprintf(
|
||||
$conn,
|
||||
'slug IN (%Ls)',
|
||||
$this->slugs);
|
||||
}
|
||||
|
||||
switch ($this->status) {
|
||||
case self::STATUS_OPEN:
|
||||
$where[] = qsprintf(
|
||||
|
|
|
@ -20,7 +20,7 @@ final class PhrictionSearchIndexer
|
|||
|
||||
$doc = new PhabricatorSearchAbstractDocument();
|
||||
$doc->setPHID($document->getPHID());
|
||||
$doc->setDocumentType(PhabricatorPHIDConstants::PHID_TYPE_WIKI);
|
||||
$doc->setDocumentType(PhrictionPHIDTypeDocument::TYPECONST);
|
||||
$doc->setDocumentTitle($content->getTitle());
|
||||
|
||||
// TODO: This isn't precisely correct, denormalize into the Document table?
|
||||
|
@ -41,7 +41,7 @@ final class PhrictionSearchIndexer
|
|||
$doc->addRelationship(
|
||||
PhabricatorSearchRelationship::RELATIONSHIP_OPEN,
|
||||
$document->getPHID(),
|
||||
PhabricatorPHIDConstants::PHID_TYPE_WIKI,
|
||||
PhrictionPHIDTypeDocument::TYPECONST,
|
||||
time());
|
||||
}
|
||||
|
||||
|
|
|
@ -16,8 +16,11 @@ final class PhrictionDocument extends PhrictionDAO
|
|||
protected $contentID;
|
||||
protected $status;
|
||||
|
||||
private $contentObject;
|
||||
private $project;
|
||||
private $contentObject = self::ATTACHABLE;
|
||||
|
||||
// TODO: This should be `self::ATTACHABLE`, but there are still a lot of call
|
||||
// sites which load PhrictionDocuments directly.
|
||||
private $project = null;
|
||||
|
||||
public function getConfiguration() {
|
||||
return array(
|
||||
|
@ -28,7 +31,7 @@ final class PhrictionDocument extends PhrictionDAO
|
|||
|
||||
public function generatePHID() {
|
||||
return PhabricatorPHID::generateNewPHID(
|
||||
PhabricatorPHIDConstants::PHID_TYPE_WIKI);
|
||||
PhrictionPHIDTypeDocument::TYPECONST);
|
||||
}
|
||||
|
||||
public static function getSlugURI($slug, $type = 'document') {
|
||||
|
@ -66,26 +69,20 @@ final class PhrictionDocument extends PhrictionDAO
|
|||
}
|
||||
|
||||
public function getContent() {
|
||||
if (!$this->contentObject) {
|
||||
throw new Exception("Attach content with attachContent() first.");
|
||||
}
|
||||
return $this->contentObject;
|
||||
return $this->assertAttached($this->contentObject);
|
||||
}
|
||||
|
||||
public function getProject() {
|
||||
if ($this->project === null) {
|
||||
throw new Exception("Call attachProject() before getProject().");
|
||||
}
|
||||
return $this->project;
|
||||
return $this->assertAttached($this->project);
|
||||
}
|
||||
|
||||
public function attachProject(PhabricatorProject $project) {
|
||||
public function attachProject(PhabricatorProject $project = null) {
|
||||
$this->project = $project;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function hasProject() {
|
||||
return (bool)$this->project;
|
||||
return (bool)$this->getProject();
|
||||
}
|
||||
|
||||
public static function isProjectSlug($slug) {
|
||||
|
|
|
@ -58,7 +58,7 @@ final class PhabricatorSearchController
|
|||
case PhabricatorSearchScope::SCOPE_WIKI:
|
||||
$query->setParameter(
|
||||
'type',
|
||||
PhabricatorPHIDConstants::PHID_TYPE_WIKI);
|
||||
PhrictionPHIDTypeDocument::TYPECONST);
|
||||
break;
|
||||
case PhabricatorSearchScope::SCOPE_COMMITS:
|
||||
$query->setParameter(
|
||||
|
|
|
@ -18,7 +18,7 @@ final class PhabricatorSearchAbstractDocument {
|
|||
DifferentialPHIDTypeRevision::TYPECONST => 'Differential Revisions',
|
||||
PhabricatorRepositoryPHIDTypeCommit::TYPECONST => 'Repository Commits',
|
||||
ManiphestPHIDTypeTask::TYPECONST => 'Maniphest Tasks',
|
||||
PhabricatorPHIDConstants::PHID_TYPE_WIKI => 'Phriction Documents',
|
||||
PhrictionPHIDTypeDocument::TYPECONST => 'Phriction Documents',
|
||||
PhabricatorPHIDConstants::PHID_TYPE_USER => 'Phabricator Users',
|
||||
PhabricatorPHIDConstants::PHID_TYPE_QUES => 'Ponder Questions',
|
||||
);
|
||||
|
|
|
@ -162,7 +162,6 @@ final class PhabricatorEdgeConfig extends PhabricatorEdgeConstants {
|
|||
PhabricatorPHIDConstants::PHID_TYPE_ANSW => 'PonderAnswer',
|
||||
PhabricatorPHIDConstants::PHID_TYPE_MCRO => 'PhabricatorFileImageMacro',
|
||||
PhabricatorPHIDConstants::PHID_TYPE_CONP => 'ConpherenceThread',
|
||||
PhabricatorPHIDConstants::PHID_TYPE_WIKI => 'PhrictionDocument',
|
||||
PhabricatorPHIDConstants::PHID_TYPE_ACNT => 'PhortuneAccount',
|
||||
PhabricatorPHIDConstants::PHID_TYPE_PRCH => 'PhortunePurchase',
|
||||
PhabricatorPHIDConstants::PHID_TYPE_CHRG => 'PhortuneCharge',
|
||||
|
|
Loading…
Reference in a new issue