From cdbb1d5a0311a625e6814db9e6161dba2ac3a56c Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 24 Jul 2013 11:32:13 -0700 Subject: [PATCH] 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 --- src/__phutil_library_map__.php | 2 + .../phid/PhabricatorObjectHandle.php | 1 - .../phid/PhabricatorPHIDConstants.php | 1 - .../handle/PhabricatorObjectHandleData.php | 46 ---------------- .../PhrictionDocumentController.php | 7 ++- .../phid/PhrictionPHIDTypeDocument.php | 55 +++++++++++++++++++ .../query/PhrictionDocumentQuery.php | 19 ++++++- .../search/PhrictionSearchIndexer.php | 4 +- .../phriction/storage/PhrictionDocument.php | 23 ++++---- .../PhabricatorSearchController.php | 2 +- .../PhabricatorSearchAbstractDocument.php | 2 +- .../edges/constants/PhabricatorEdgeConfig.php | 1 - 12 files changed, 93 insertions(+), 70 deletions(-) create mode 100644 src/applications/phriction/phid/PhrictionPHIDTypeDocument.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 46e0abe0b8..48ccd5ffc8 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -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', diff --git a/src/applications/phid/PhabricatorObjectHandle.php b/src/applications/phid/PhabricatorObjectHandle.php index 0583f5ba0e..3c25cb1fe2 100644 --- a/src/applications/phid/PhabricatorObjectHandle.php +++ b/src/applications/phid/PhabricatorObjectHandle.php @@ -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', diff --git a/src/applications/phid/PhabricatorPHIDConstants.php b/src/applications/phid/PhabricatorPHIDConstants.php index 4d5ff468bf..bb7992f510 100644 --- a/src/applications/phid/PhabricatorPHIDConstants.php +++ b/src/applications/phid/PhabricatorPHIDConstants.php @@ -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'; diff --git a/src/applications/phid/handle/PhabricatorObjectHandleData.php b/src/applications/phid/handle/PhabricatorObjectHandleData.php index 2dec8b4fb3..c2e4fb10f0 100644 --- a/src/applications/phid/handle/PhabricatorObjectHandleData.php +++ b/src/applications/phid/handle/PhabricatorObjectHandleData.php @@ -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(); diff --git a/src/applications/phriction/controller/PhrictionDocumentController.php b/src/applications/phriction/controller/PhrictionDocumentController.php index edbd38a9a6..22eb0eb2f6 100644 --- a/src/applications/phriction/controller/PhrictionDocumentController.php +++ b/src/applications/phriction/controller/PhrictionDocumentController.php @@ -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 = ''; diff --git a/src/applications/phriction/phid/PhrictionPHIDTypeDocument.php b/src/applications/phriction/phid/PhrictionPHIDTypeDocument.php new file mode 100644 index 0000000000..3f357d9f68 --- /dev/null +++ b/src/applications/phriction/phid/PhrictionPHIDTypeDocument.php @@ -0,0 +1,55 @@ +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; + } + +} diff --git a/src/applications/phriction/query/PhrictionDocumentQuery.php b/src/applications/phriction/query/PhrictionDocumentQuery.php index 3cdd0e2abf..449e5a9a31 100644 --- a/src/applications/phriction/query/PhrictionDocumentQuery.php +++ b/src/applications/phriction/query/PhrictionDocumentQuery.php @@ -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( diff --git a/src/applications/phriction/search/PhrictionSearchIndexer.php b/src/applications/phriction/search/PhrictionSearchIndexer.php index 5786e05a4f..c56cf89043 100644 --- a/src/applications/phriction/search/PhrictionSearchIndexer.php +++ b/src/applications/phriction/search/PhrictionSearchIndexer.php @@ -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()); } diff --git a/src/applications/phriction/storage/PhrictionDocument.php b/src/applications/phriction/storage/PhrictionDocument.php index af74769f29..c7b5bd7c0d 100644 --- a/src/applications/phriction/storage/PhrictionDocument.php +++ b/src/applications/phriction/storage/PhrictionDocument.php @@ -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) { diff --git a/src/applications/search/controller/PhabricatorSearchController.php b/src/applications/search/controller/PhabricatorSearchController.php index 5dd0efd05b..7312ade9b3 100644 --- a/src/applications/search/controller/PhabricatorSearchController.php +++ b/src/applications/search/controller/PhabricatorSearchController.php @@ -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( diff --git a/src/applications/search/index/PhabricatorSearchAbstractDocument.php b/src/applications/search/index/PhabricatorSearchAbstractDocument.php index 24f4357702..e339730904 100644 --- a/src/applications/search/index/PhabricatorSearchAbstractDocument.php +++ b/src/applications/search/index/PhabricatorSearchAbstractDocument.php @@ -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', ); diff --git a/src/infrastructure/edges/constants/PhabricatorEdgeConfig.php b/src/infrastructure/edges/constants/PhabricatorEdgeConfig.php index a932ccb1fc..c0c56ed61e 100644 --- a/src/infrastructure/edges/constants/PhabricatorEdgeConfig.php +++ b/src/infrastructure/edges/constants/PhabricatorEdgeConfig.php @@ -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',