mirror of
https://we.phorge.it/source/phorge.git
synced 2025-03-01 23:19:15 +01:00
Summary: Ref T7803. Ref T5873. I want to drive Conduit through more shared infrastructure, but can't currently add parameters automatically. Put a `getX()` around the `defineX()` methods so the parent can provide default behaviors. Also like 60% of methods don't define any special error types; don't require them to implement this method. I want to move away from this in general. Test Plan: - Ran `arc unit --everything`. - Called `conduit.query`. - Browsed Conduit UI. Reviewers: btrahan Reviewed By: btrahan Subscribers: hach-que, epriestley Maniphest Tasks: T5873, T7803 Differential Revision: https://secure.phabricator.com/D12380
71 lines
2.1 KiB
PHP
71 lines
2.1 KiB
PHP
<?php
|
|
|
|
final class PhrictionCreateConduitAPIMethod extends PhrictionConduitAPIMethod {
|
|
|
|
public function getAPIMethodName() {
|
|
return 'phriction.create';
|
|
}
|
|
|
|
public function getMethodDescription() {
|
|
return pht('Create a Phriction document.');
|
|
}
|
|
|
|
protected function defineParamTypes() {
|
|
return array(
|
|
'slug' => 'required string',
|
|
'title' => 'required string',
|
|
'content' => 'required string',
|
|
'description' => 'optional string',
|
|
);
|
|
}
|
|
|
|
protected function defineReturnType() {
|
|
return 'nonempty dict';
|
|
}
|
|
|
|
protected function execute(ConduitAPIRequest $request) {
|
|
$slug = $request->getValue('slug');
|
|
if (!strlen($slug)) {
|
|
throw new Exception(pht('No such document.'));
|
|
}
|
|
$doc = id(new PhrictionDocumentQuery())
|
|
->setViewer($request->getUser())
|
|
->withSlugs(array(PhabricatorSlug::normalize($slug)))
|
|
->requireCapabilities(
|
|
array(
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
))
|
|
->executeOne();
|
|
if ($doc) {
|
|
throw new Exception(pht('Document already exists!'));
|
|
}
|
|
|
|
$doc = PhrictionDocument::initializeNewDocument(
|
|
$request->getUser(),
|
|
$slug);
|
|
|
|
$xactions = array();
|
|
$xactions[] = id(new PhrictionTransaction())
|
|
->setTransactionType(PhrictionTransaction::TYPE_TITLE)
|
|
->setNewValue($request->getValue('title'));
|
|
$xactions[] = id(new PhrictionTransaction())
|
|
->setTransactionType(PhrictionTransaction::TYPE_CONTENT)
|
|
->setNewValue($request->getValue('content'));
|
|
|
|
$editor = id(new PhrictionTransactionEditor())
|
|
->setActor($request->getUser())
|
|
->setContentSourceFromConduitRequest($request)
|
|
->setContinueOnNoEffect(true)
|
|
->setDescription($request->getValue('description'));
|
|
|
|
try {
|
|
$editor->applyTransactions($doc, $xactions);
|
|
} catch (PhabricatorApplicationTransactionValidationException $ex) {
|
|
// TODO - some magical hotness via T5873
|
|
throw $ex;
|
|
}
|
|
|
|
return $this->buildDocumentInfoDictionary($doc);
|
|
}
|
|
}
|