Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phriction/controller/PhrictionEditController.php
<?php | <?php | ||||
/** | |||||
* @group phriction | |||||
*/ | |||||
final class PhrictionEditController | final class PhrictionEditController | ||||
extends PhrictionController { | extends PhrictionController { | ||||
private $id; | private $id; | ||||
public function willProcessRequest(array $data) { | public function willProcessRequest(array $data) { | ||||
$this->id = idx($data, 'id'); | $this->id = idx($data, 'id'); | ||||
} | } | ||||
public function processRequest() { | public function processRequest() { | ||||
$request = $this->getRequest(); | $request = $this->getRequest(); | ||||
$user = $request->getUser(); | $user = $request->getUser(); | ||||
if ($this->id) { | if ($this->id) { | ||||
$document = id(new PhrictionDocument())->load($this->id); | $document = id(new PhrictionDocumentQuery()) | ||||
->setViewer($user) | |||||
->withIDs(array($this->id)) | |||||
->requireCapabilities( | |||||
array( | |||||
PhabricatorPolicyCapability::CAN_VIEW, | |||||
PhabricatorPolicyCapability::CAN_EDIT, | |||||
)) | |||||
->executeOne(); | |||||
if (!$document) { | if (!$document) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
$revert = $request->getInt('revert'); | $revert = $request->getInt('revert'); | ||||
if ($revert) { | if ($revert) { | ||||
$content = id(new PhrictionContent())->loadOneWhere( | $content = id(new PhrictionContent())->loadOneWhere( | ||||
'documentID = %d AND version = %d', | 'documentID = %d AND version = %d', | ||||
$document->getID(), | $document->getID(), | ||||
$revert); | $revert); | ||||
if (!$content) { | if (!$content) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
} else { | } else { | ||||
$content = id(new PhrictionContent())->load($document->getContentID()); | $content = id(new PhrictionContent())->load($document->getContentID()); | ||||
} | } | ||||
} else { | } else { | ||||
$slug = $request->getStr('slug'); | $slug = $request->getStr('slug'); | ||||
$slug = PhabricatorSlug::normalize($slug); | $slug = PhabricatorSlug::normalize($slug); | ||||
if (!$slug) { | if (!$slug) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
$document = id(new PhrictionDocument())->loadOneWhere( | $document = id(new PhrictionDocumentQuery()) | ||||
'slug = %s', | ->setViewer($user) | ||||
$slug); | ->withSlugs(array($slug)) | ||||
->needContent(true) | |||||
->executeOne(); | |||||
if ($document) { | if ($document) { | ||||
$content = id(new PhrictionContent())->load($document->getContentID()); | $content = $document->getContent(); | ||||
} else { | } else { | ||||
if (PhrictionDocument::isProjectSlug($slug)) { | if (PhrictionDocument::isProjectSlug($slug)) { | ||||
$project = id(new PhabricatorProjectQuery()) | $project = id(new PhabricatorProjectQuery()) | ||||
->setViewer($user) | ->setViewer($user) | ||||
->withPhrictionSlugs(array( | ->withPhrictionSlugs(array( | ||||
PhrictionDocument::getProjectSlugIdentifier($slug))) | PhrictionDocument::getProjectSlugIdentifier($slug))) | ||||
->executeOne(); | ->executeOne(); | ||||
if (!$project) { | if (!$project) { | ||||
▲ Show 20 Lines • Show All 230 Lines • Show Last 20 Lines |