Commit f742d00c authored by epriestley's avatar epriestley
Browse files

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
parent 9404e2b3
......@@ -29,10 +29,11 @@ final class PhrictionDiffController extends PhrictionController {
list($l, $r) = explode(',', $ref);
}
$content = id(new PhrictionContent())->loadAllWhere(
'documentID = %d AND version IN (%Ld)',
$document->getID(),
array($l, $r));
$content = id(new PhrictionContentQuery())
->setViewer($viewer)
->withDocumentPHIDs(array($document->getPHID()))
->withVersions(array($l, $r))
->execute();
$content = mpull($content, null, 'getVersion');
$content_l = idx($content, $l, null);
......
......@@ -22,11 +22,6 @@ final class PhrictionDocumentController
require_celerity_resource('phriction-document-css');
$document = id(new PhrictionDocumentQuery())
->setViewer($viewer)
->withSlugs(array($slug))
->executeOne();
$version_note = null;
$core_content = '';
$move_notice = '';
......@@ -34,6 +29,11 @@ final class PhrictionDocumentController
$content = null;
$toc = null;
$document = id(new PhrictionDocumentQuery())
->setViewer($viewer)
->withSlugs(array($slug))
->needContent(true)
->executeOne();
if (!$document) {
$document = PhrictionDocument::initializeNewDocument($viewer, $slug);
......@@ -69,25 +69,28 @@ final class PhrictionDocumentController
$version = $request->getInt('v');
if ($version) {
$content = id(new PhrictionContent())->loadOneWhere(
'documentID = %d AND version = %d',
$document->getID(),
$version);
$content = id(new PhrictionContentQuery())
->setViewer($viewer)
->withDocumentPHIDs(array($document->getPHID()))
->withVersions(array($version))
->executeOne();
if (!$content) {
return new Aphront404Response();
}
if ($content->getID() != $document->getContentID()) {
$vdate = phabricator_datetime($content->getDateCreated(), $viewer);
$version_note = new PHUIInfoView();
$version_note->setSeverity(PHUIInfoView::SEVERITY_NOTICE);
$version_note->appendChild(
pht('You are viewing an older version of this document, as it '.
'appeared on %s.', $vdate));
$version_note = id(new PHUIInfoView())
->setSeverity(PHUIInfoView::SEVERITY_NOTICE)
->appendChild(
pht(
'You are viewing an older version of this document, as it '.
'appeared on %s.',
phabricator_datetime($content->getDateCreated(), $viewer)));
}
} else {
$content = id(new PhrictionContent())->load($document->getContentID());
$content = $document->getContent();
}
$page_title = $content->getTitle();
$properties = $this
->buildPropertyListView($document, $content, $slug);
......
......@@ -28,10 +28,11 @@ final class PhrictionEditController
$revert = $request->getInt('revert');
if ($revert) {
$content = id(new PhrictionContent())->loadOneWhere(
'documentID = %d AND version = %d',
$document->getID(),
$revert);
$content = id(new PhrictionContentQuery())
->setViewer($viewer)
->withDocumentPHIDs(array($document->getPHID()))
->withVersions(array($revert))
->executeOne();
if (!$content) {
return new Aphront404Response();
}
......
......@@ -6,6 +6,7 @@ final class PhrictionContentQuery
private $ids;
private $phids;
private $documentPHIDs;
private $versions;
public function withIDs(array $ids) {
$this->ids = $ids;
......@@ -22,6 +23,11 @@ final class PhrictionContentQuery
return $this;
}
public function withVersions(array $versions) {
$this->versions = $versions;
return $this;
}
public function newResultObject() {
return new PhrictionContent();
}
......@@ -47,6 +53,13 @@ final class PhrictionContentQuery
$this->phids);
}
if ($this->versions !== null) {
$where[] = qsprintf(
$conn,
'version IN (%Ld)',
$this->versions);
}
if ($this->documentPHIDs !== null) {
$where[] = qsprintf(
$conn,
......
......@@ -145,9 +145,12 @@ final class PhrictionDocumentQuery
}
if ($this->needContent) {
$contents = id(new PhrictionContent())->loadAllWhere(
'id IN (%Ld)',
mpull($documents, 'getContentID'));
$contents = id(new PhrictionContentQuery())
->setViewer($this->getViewer())
->setParentQuery($this)
->withIDs(mpull($documents, 'getContentID'))
->execute();
$contents = mpull($contents, null, 'getID');
foreach ($documents as $key => $document) {
$content_id = $document->getContentID();
......
......@@ -61,7 +61,7 @@ final class PhrictionDocument extends PhrictionDAO
$document = new PhrictionDocument();
$document->setSlug($slug);
$content = new PhrictionContent();
$content = new PhrictionContent();
$content->setSlug($slug);
$default_title = PhabricatorSlug::getDefaultTitle($slug);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment