mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-23 12:09:12 +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',
|
'PhrictionListController' => 'applications/phriction/controller/PhrictionListController.php',
|
||||||
'PhrictionMoveController' => 'applications/phriction/controller/PhrictionMoveController.php',
|
'PhrictionMoveController' => 'applications/phriction/controller/PhrictionMoveController.php',
|
||||||
'PhrictionNewController' => 'applications/phriction/controller/PhrictionNewController.php',
|
'PhrictionNewController' => 'applications/phriction/controller/PhrictionNewController.php',
|
||||||
|
'PhrictionPHIDTypeDocument' => 'applications/phriction/phid/PhrictionPHIDTypeDocument.php',
|
||||||
'PhrictionRemarkupRule' => 'applications/phriction/remarkup/PhrictionRemarkupRule.php',
|
'PhrictionRemarkupRule' => 'applications/phriction/remarkup/PhrictionRemarkupRule.php',
|
||||||
'PhrictionSearchIndexer' => 'applications/phriction/search/PhrictionSearchIndexer.php',
|
'PhrictionSearchIndexer' => 'applications/phriction/search/PhrictionSearchIndexer.php',
|
||||||
'PonderAddAnswerView' => 'applications/ponder/view/PonderAddAnswerView.php',
|
'PonderAddAnswerView' => 'applications/ponder/view/PonderAddAnswerView.php',
|
||||||
|
@ -3912,6 +3913,7 @@ phutil_register_library_map(array(
|
||||||
'PhrictionListController' => 'PhrictionController',
|
'PhrictionListController' => 'PhrictionController',
|
||||||
'PhrictionMoveController' => 'PhrictionController',
|
'PhrictionMoveController' => 'PhrictionController',
|
||||||
'PhrictionNewController' => 'PhrictionController',
|
'PhrictionNewController' => 'PhrictionController',
|
||||||
|
'PhrictionPHIDTypeDocument' => 'PhabricatorPHIDType',
|
||||||
'PhrictionRemarkupRule' => 'PhutilRemarkupRule',
|
'PhrictionRemarkupRule' => 'PhutilRemarkupRule',
|
||||||
'PhrictionSearchIndexer' => 'PhabricatorSearchDocumentIndexer',
|
'PhrictionSearchIndexer' => 'PhabricatorSearchDocumentIndexer',
|
||||||
'PonderAddAnswerView' => 'AphrontView',
|
'PonderAddAnswerView' => 'AphrontView',
|
||||||
|
|
|
@ -109,7 +109,6 @@ final class PhabricatorObjectHandle
|
||||||
|
|
||||||
static $map = array(
|
static $map = array(
|
||||||
PhabricatorPHIDConstants::PHID_TYPE_USER => 'User',
|
PhabricatorPHIDConstants::PHID_TYPE_USER => 'User',
|
||||||
PhabricatorPHIDConstants::PHID_TYPE_WIKI => 'Phriction Document',
|
|
||||||
PhabricatorPHIDConstants::PHID_TYPE_MCRO => 'Image Macro',
|
PhabricatorPHIDConstants::PHID_TYPE_MCRO => 'Image Macro',
|
||||||
PhabricatorPHIDConstants::PHID_TYPE_PIMG => 'Pholio Image',
|
PhabricatorPHIDConstants::PHID_TYPE_PIMG => 'Pholio Image',
|
||||||
PhabricatorPHIDConstants::PHID_TYPE_BLOG => 'Blog',
|
PhabricatorPHIDConstants::PHID_TYPE_BLOG => 'Blog',
|
||||||
|
|
|
@ -8,7 +8,6 @@ final class PhabricatorPHIDConstants {
|
||||||
const PHID_TYPE_OPKG = 'OPKG';
|
const PHID_TYPE_OPKG = 'OPKG';
|
||||||
const PHID_TYPE_PSTE = 'PSTE';
|
const PHID_TYPE_PSTE = 'PSTE';
|
||||||
const PHID_TYPE_STRY = 'STRY';
|
const PHID_TYPE_STRY = 'STRY';
|
||||||
const PHID_TYPE_WIKI = 'WIKI';
|
|
||||||
const PHID_TYPE_APRJ = 'APRJ';
|
const PHID_TYPE_APRJ = 'APRJ';
|
||||||
const PHID_TYPE_ACMT = 'ACMT';
|
const PHID_TYPE_ACMT = 'ACMT';
|
||||||
const PHID_TYPE_DRYR = 'DRYR';
|
const PHID_TYPE_DRYR = 'DRYR';
|
||||||
|
|
|
@ -68,15 +68,6 @@ final class PhabricatorObjectHandleData {
|
||||||
$phids);
|
$phids);
|
||||||
return mpull($projects, null, 'getPHID');
|
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:
|
case PhabricatorPHIDConstants::PHID_TYPE_QUES:
|
||||||
$questions = id(new PonderQuestionQuery())
|
$questions = id(new PonderQuestionQuery())
|
||||||
->setViewer($this->viewer)
|
->setViewer($this->viewer)
|
||||||
|
@ -309,43 +300,6 @@ final class PhabricatorObjectHandleData {
|
||||||
}
|
}
|
||||||
break;
|
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:
|
case PhabricatorPHIDConstants::PHID_TYPE_QUES:
|
||||||
foreach ($phids as $phid) {
|
foreach ($phids as $phid) {
|
||||||
$handle = new PhabricatorObjectHandle();
|
$handle = new PhabricatorObjectHandle();
|
||||||
|
|
|
@ -25,9 +25,10 @@ final class PhrictionDocumentController
|
||||||
|
|
||||||
require_celerity_resource('phriction-document-css');
|
require_celerity_resource('phriction-document-css');
|
||||||
|
|
||||||
$document = id(new PhrictionDocument())->loadOneWhere(
|
$document = id(new PhrictionDocumentQuery())
|
||||||
'slug = %s',
|
->setViewer($user)
|
||||||
$slug);
|
->withSlugs(array($slug))
|
||||||
|
->executeOne();
|
||||||
|
|
||||||
$version_note = null;
|
$version_note = null;
|
||||||
$core_content = '';
|
$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 $ids;
|
||||||
private $phids;
|
private $phids;
|
||||||
|
private $slugs;
|
||||||
|
|
||||||
private $status = 'status-any';
|
private $status = 'status-any';
|
||||||
const STATUS_ANY = 'status-any';
|
const STATUS_ANY = 'status-any';
|
||||||
|
@ -28,6 +29,11 @@ final class PhrictionDocumentQuery
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function withSlugs(array $slugs) {
|
||||||
|
$this->slugs = $slugs;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function withStatus($status) {
|
public function withStatus($status) {
|
||||||
$this->status = $status;
|
$this->status = $status;
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -71,6 +77,10 @@ final class PhrictionDocumentQuery
|
||||||
$document->attachContent($contents[$content_id]);
|
$document->attachContent($contents[$content_id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach ($documents as $document) {
|
||||||
|
$document->attachProject(null);
|
||||||
|
}
|
||||||
|
|
||||||
$project_slugs = array();
|
$project_slugs = array();
|
||||||
foreach ($documents as $key => $document) {
|
foreach ($documents as $key => $document) {
|
||||||
$slug = $document->getSlug();
|
$slug = $document->getSlug();
|
||||||
|
@ -115,10 +125,17 @@ final class PhrictionDocumentQuery
|
||||||
if ($this->phids) {
|
if ($this->phids) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn,
|
$conn,
|
||||||
'id IN (%Ld)',
|
'phid IN (%Ls)',
|
||||||
$this->phids);
|
$this->phids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->slugs) {
|
||||||
|
$where[] = qsprintf(
|
||||||
|
$conn,
|
||||||
|
'slug IN (%Ls)',
|
||||||
|
$this->slugs);
|
||||||
|
}
|
||||||
|
|
||||||
switch ($this->status) {
|
switch ($this->status) {
|
||||||
case self::STATUS_OPEN:
|
case self::STATUS_OPEN:
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
|
|
|
@ -20,7 +20,7 @@ final class PhrictionSearchIndexer
|
||||||
|
|
||||||
$doc = new PhabricatorSearchAbstractDocument();
|
$doc = new PhabricatorSearchAbstractDocument();
|
||||||
$doc->setPHID($document->getPHID());
|
$doc->setPHID($document->getPHID());
|
||||||
$doc->setDocumentType(PhabricatorPHIDConstants::PHID_TYPE_WIKI);
|
$doc->setDocumentType(PhrictionPHIDTypeDocument::TYPECONST);
|
||||||
$doc->setDocumentTitle($content->getTitle());
|
$doc->setDocumentTitle($content->getTitle());
|
||||||
|
|
||||||
// TODO: This isn't precisely correct, denormalize into the Document table?
|
// TODO: This isn't precisely correct, denormalize into the Document table?
|
||||||
|
@ -41,7 +41,7 @@ final class PhrictionSearchIndexer
|
||||||
$doc->addRelationship(
|
$doc->addRelationship(
|
||||||
PhabricatorSearchRelationship::RELATIONSHIP_OPEN,
|
PhabricatorSearchRelationship::RELATIONSHIP_OPEN,
|
||||||
$document->getPHID(),
|
$document->getPHID(),
|
||||||
PhabricatorPHIDConstants::PHID_TYPE_WIKI,
|
PhrictionPHIDTypeDocument::TYPECONST,
|
||||||
time());
|
time());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,11 @@ final class PhrictionDocument extends PhrictionDAO
|
||||||
protected $contentID;
|
protected $contentID;
|
||||||
protected $status;
|
protected $status;
|
||||||
|
|
||||||
private $contentObject;
|
private $contentObject = self::ATTACHABLE;
|
||||||
private $project;
|
|
||||||
|
// 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() {
|
public function getConfiguration() {
|
||||||
return array(
|
return array(
|
||||||
|
@ -28,7 +31,7 @@ final class PhrictionDocument extends PhrictionDAO
|
||||||
|
|
||||||
public function generatePHID() {
|
public function generatePHID() {
|
||||||
return PhabricatorPHID::generateNewPHID(
|
return PhabricatorPHID::generateNewPHID(
|
||||||
PhabricatorPHIDConstants::PHID_TYPE_WIKI);
|
PhrictionPHIDTypeDocument::TYPECONST);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getSlugURI($slug, $type = 'document') {
|
public static function getSlugURI($slug, $type = 'document') {
|
||||||
|
@ -66,26 +69,20 @@ final class PhrictionDocument extends PhrictionDAO
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getContent() {
|
public function getContent() {
|
||||||
if (!$this->contentObject) {
|
return $this->assertAttached($this->contentObject);
|
||||||
throw new Exception("Attach content with attachContent() first.");
|
|
||||||
}
|
|
||||||
return $this->contentObject;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getProject() {
|
public function getProject() {
|
||||||
if ($this->project === null) {
|
return $this->assertAttached($this->project);
|
||||||
throw new Exception("Call attachProject() before getProject().");
|
|
||||||
}
|
|
||||||
return $this->project;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function attachProject(PhabricatorProject $project) {
|
public function attachProject(PhabricatorProject $project = null) {
|
||||||
$this->project = $project;
|
$this->project = $project;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasProject() {
|
public function hasProject() {
|
||||||
return (bool)$this->project;
|
return (bool)$this->getProject();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function isProjectSlug($slug) {
|
public static function isProjectSlug($slug) {
|
||||||
|
|
|
@ -58,7 +58,7 @@ final class PhabricatorSearchController
|
||||||
case PhabricatorSearchScope::SCOPE_WIKI:
|
case PhabricatorSearchScope::SCOPE_WIKI:
|
||||||
$query->setParameter(
|
$query->setParameter(
|
||||||
'type',
|
'type',
|
||||||
PhabricatorPHIDConstants::PHID_TYPE_WIKI);
|
PhrictionPHIDTypeDocument::TYPECONST);
|
||||||
break;
|
break;
|
||||||
case PhabricatorSearchScope::SCOPE_COMMITS:
|
case PhabricatorSearchScope::SCOPE_COMMITS:
|
||||||
$query->setParameter(
|
$query->setParameter(
|
||||||
|
|
|
@ -18,7 +18,7 @@ final class PhabricatorSearchAbstractDocument {
|
||||||
DifferentialPHIDTypeRevision::TYPECONST => 'Differential Revisions',
|
DifferentialPHIDTypeRevision::TYPECONST => 'Differential Revisions',
|
||||||
PhabricatorRepositoryPHIDTypeCommit::TYPECONST => 'Repository Commits',
|
PhabricatorRepositoryPHIDTypeCommit::TYPECONST => 'Repository Commits',
|
||||||
ManiphestPHIDTypeTask::TYPECONST => 'Maniphest Tasks',
|
ManiphestPHIDTypeTask::TYPECONST => 'Maniphest Tasks',
|
||||||
PhabricatorPHIDConstants::PHID_TYPE_WIKI => 'Phriction Documents',
|
PhrictionPHIDTypeDocument::TYPECONST => 'Phriction Documents',
|
||||||
PhabricatorPHIDConstants::PHID_TYPE_USER => 'Phabricator Users',
|
PhabricatorPHIDConstants::PHID_TYPE_USER => 'Phabricator Users',
|
||||||
PhabricatorPHIDConstants::PHID_TYPE_QUES => 'Ponder Questions',
|
PhabricatorPHIDConstants::PHID_TYPE_QUES => 'Ponder Questions',
|
||||||
);
|
);
|
||||||
|
|
|
@ -162,7 +162,6 @@ final class PhabricatorEdgeConfig extends PhabricatorEdgeConstants {
|
||||||
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',
|
||||||
PhabricatorPHIDConstants::PHID_TYPE_WIKI => 'PhrictionDocument',
|
|
||||||
PhabricatorPHIDConstants::PHID_TYPE_ACNT => 'PhortuneAccount',
|
PhabricatorPHIDConstants::PHID_TYPE_ACNT => 'PhortuneAccount',
|
||||||
PhabricatorPHIDConstants::PHID_TYPE_PRCH => 'PhortunePurchase',
|
PhabricatorPHIDConstants::PHID_TYPE_PRCH => 'PhortunePurchase',
|
||||||
PhabricatorPHIDConstants::PHID_TYPE_CHRG => 'PhortuneCharge',
|
PhabricatorPHIDConstants::PHID_TYPE_CHRG => 'PhortuneCharge',
|
||||||
|
|
Loading…
Add table
Reference in a new issue