1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-23 13:08:18 +01:00

Mostly use PhrictionContentQuery to load PhrictionContent objects

Summary: Depends on D19094. Ref T13077. Use modern infrastructure to perform these loads. I left a couple of calls in the older API methods unconverted.

Test Plan: Viewed documents. Viewed older versions. Viewed diffs. Did revert edits to older versions.

Maniphest Tasks: T13077

Differential Revision: https://secure.phabricator.com/D19095
This commit is contained in:
epriestley 2018-02-15 05:22:16 -08:00
parent 9404e2b3d4
commit f742d00c28
6 changed files with 49 additions and 28 deletions

View file

@ -29,10 +29,11 @@ final class PhrictionDiffController extends PhrictionController {
list($l, $r) = explode(',', $ref); list($l, $r) = explode(',', $ref);
} }
$content = id(new PhrictionContent())->loadAllWhere( $content = id(new PhrictionContentQuery())
'documentID = %d AND version IN (%Ld)', ->setViewer($viewer)
$document->getID(), ->withDocumentPHIDs(array($document->getPHID()))
array($l, $r)); ->withVersions(array($l, $r))
->execute();
$content = mpull($content, null, 'getVersion'); $content = mpull($content, null, 'getVersion');
$content_l = idx($content, $l, null); $content_l = idx($content, $l, null);

View file

@ -22,11 +22,6 @@ final class PhrictionDocumentController
require_celerity_resource('phriction-document-css'); require_celerity_resource('phriction-document-css');
$document = id(new PhrictionDocumentQuery())
->setViewer($viewer)
->withSlugs(array($slug))
->executeOne();
$version_note = null; $version_note = null;
$core_content = ''; $core_content = '';
$move_notice = ''; $move_notice = '';
@ -34,6 +29,11 @@ final class PhrictionDocumentController
$content = null; $content = null;
$toc = null; $toc = null;
$document = id(new PhrictionDocumentQuery())
->setViewer($viewer)
->withSlugs(array($slug))
->needContent(true)
->executeOne();
if (!$document) { if (!$document) {
$document = PhrictionDocument::initializeNewDocument($viewer, $slug); $document = PhrictionDocument::initializeNewDocument($viewer, $slug);
@ -69,25 +69,28 @@ final class PhrictionDocumentController
$version = $request->getInt('v'); $version = $request->getInt('v');
if ($version) { if ($version) {
$content = id(new PhrictionContent())->loadOneWhere( $content = id(new PhrictionContentQuery())
'documentID = %d AND version = %d', ->setViewer($viewer)
$document->getID(), ->withDocumentPHIDs(array($document->getPHID()))
$version); ->withVersions(array($version))
->executeOne();
if (!$content) { if (!$content) {
return new Aphront404Response(); return new Aphront404Response();
} }
if ($content->getID() != $document->getContentID()) { if ($content->getID() != $document->getContentID()) {
$vdate = phabricator_datetime($content->getDateCreated(), $viewer); $version_note = id(new PHUIInfoView())
$version_note = new PHUIInfoView(); ->setSeverity(PHUIInfoView::SEVERITY_NOTICE)
$version_note->setSeverity(PHUIInfoView::SEVERITY_NOTICE); ->appendChild(
$version_note->appendChild( pht(
pht('You are viewing an older version of this document, as it '. 'You are viewing an older version of this document, as it '.
'appeared on %s.', $vdate)); 'appeared on %s.',
phabricator_datetime($content->getDateCreated(), $viewer)));
} }
} else { } else {
$content = id(new PhrictionContent())->load($document->getContentID()); $content = $document->getContent();
} }
$page_title = $content->getTitle(); $page_title = $content->getTitle();
$properties = $this $properties = $this
->buildPropertyListView($document, $content, $slug); ->buildPropertyListView($document, $content, $slug);

View file

@ -28,10 +28,11 @@ final class PhrictionEditController
$revert = $request->getInt('revert'); $revert = $request->getInt('revert');
if ($revert) { if ($revert) {
$content = id(new PhrictionContent())->loadOneWhere( $content = id(new PhrictionContentQuery())
'documentID = %d AND version = %d', ->setViewer($viewer)
$document->getID(), ->withDocumentPHIDs(array($document->getPHID()))
$revert); ->withVersions(array($revert))
->executeOne();
if (!$content) { if (!$content) {
return new Aphront404Response(); return new Aphront404Response();
} }

View file

@ -6,6 +6,7 @@ final class PhrictionContentQuery
private $ids; private $ids;
private $phids; private $phids;
private $documentPHIDs; private $documentPHIDs;
private $versions;
public function withIDs(array $ids) { public function withIDs(array $ids) {
$this->ids = $ids; $this->ids = $ids;
@ -22,6 +23,11 @@ final class PhrictionContentQuery
return $this; return $this;
} }
public function withVersions(array $versions) {
$this->versions = $versions;
return $this;
}
public function newResultObject() { public function newResultObject() {
return new PhrictionContent(); return new PhrictionContent();
} }
@ -47,6 +53,13 @@ final class PhrictionContentQuery
$this->phids); $this->phids);
} }
if ($this->versions !== null) {
$where[] = qsprintf(
$conn,
'version IN (%Ld)',
$this->versions);
}
if ($this->documentPHIDs !== null) { if ($this->documentPHIDs !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,

View file

@ -145,9 +145,12 @@ final class PhrictionDocumentQuery
} }
if ($this->needContent) { if ($this->needContent) {
$contents = id(new PhrictionContent())->loadAllWhere( $contents = id(new PhrictionContentQuery())
'id IN (%Ld)', ->setViewer($this->getViewer())
mpull($documents, 'getContentID')); ->setParentQuery($this)
->withIDs(mpull($documents, 'getContentID'))
->execute();
$contents = mpull($contents, null, 'getID');
foreach ($documents as $key => $document) { foreach ($documents as $key => $document) {
$content_id = $document->getContentID(); $content_id = $document->getContentID();