2014-03-11 23:51:53 +01:00
|
|
|
<?php
|
|
|
|
|
Rename Conduit classes
Summary: Ref T5655. Rename Conduit classes and provide a `getAPIMethodName` method to declare the API method.
Test Plan:
```
> echo '{}' | arc --conduit-uri='http://phabricator.joshuaspence.com' call-conduit user.whoami
Waiting for JSON parameters on stdin...
{"error":null,"errorMessage":null,"response":{"phid":"PHID-USER-lioqffnwn6y475mu5ndb","userName":"josh","realName":"Joshua Spence","image":"http:\/\/phabricator.joshuaspence.com\/res\/1404425321T\/phabricator\/3eb28cd9\/rsrc\/image\/avatar.png","uri":"http:\/\/phabricator.joshuaspence.com\/p\/josh\/","roles":["admin","verified","approved","activated"]}}
```
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley, #blessed_reviewers
Subscribers: epriestley, Korvin, hach-que
Maniphest Tasks: T5655
Differential Revision: https://secure.phabricator.com/D9991
2014-07-25 02:54:15 +02:00
|
|
|
final class PhameCreatePostConduitAPIMethod extends PhameConduitAPIMethod {
|
|
|
|
|
|
|
|
public function getAPIMethodName() {
|
|
|
|
return 'phame.createpost';
|
|
|
|
}
|
2014-03-11 23:51:53 +01:00
|
|
|
|
|
|
|
public function getMethodDescription() {
|
|
|
|
return pht('Create a phame post.');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getMethodStatus() {
|
|
|
|
return self::METHOD_STATUS_UNSTABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function defineParamTypes() {
|
|
|
|
return array(
|
|
|
|
'blogPHID' => 'required phid',
|
|
|
|
'title' => 'required string',
|
|
|
|
'body' => 'required string',
|
|
|
|
'phameTitle' => 'optional string',
|
|
|
|
'bloggerPHID' => 'optional phid',
|
|
|
|
'isDraft' => 'optional bool',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function defineReturnType() {
|
|
|
|
return 'list<dict>';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function defineErrorTypes() {
|
|
|
|
return array(
|
|
|
|
'ERR-INVALID-PARAMETER' =>
|
|
|
|
pht('Missing or malformed parameter.'),
|
|
|
|
'ERR-INVALID-BLOG' =>
|
|
|
|
pht('Invalid blog PHID or user can not post to blog.'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function execute(ConduitAPIRequest $request) {
|
|
|
|
$user = $request->getUser();
|
|
|
|
$blog_phid = $request->getValue('blogPHID');
|
|
|
|
$title = $request->getValue('title');
|
|
|
|
$body = $request->getValue('body');
|
|
|
|
$exception_description = array();
|
|
|
|
if (!$blog_phid) {
|
|
|
|
$exception_description[] = pht('No blog phid.');
|
|
|
|
}
|
|
|
|
if (!strlen($title)) {
|
|
|
|
$exception_description[] = pht('No post title.');
|
|
|
|
}
|
|
|
|
if (!strlen($body)) {
|
|
|
|
$exception_description[] = pht('No post body.');
|
|
|
|
}
|
|
|
|
if ($exception_description) {
|
|
|
|
throw id(new ConduitException('ERR-INVALID-PARAMETER'))
|
|
|
|
->setErrorDescription(implode("\n", $exception_description));
|
|
|
|
}
|
|
|
|
|
|
|
|
$blogger_phid = $request->getValue('bloggerPHID');
|
|
|
|
if ($blogger_phid) {
|
|
|
|
$blogger = id(new PhabricatorPeopleQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withPHIDs(array($blogger_phid))
|
|
|
|
->executeOne();
|
|
|
|
} else {
|
|
|
|
$blogger = $user;
|
|
|
|
}
|
|
|
|
|
|
|
|
$blog = id(new PhameBlogQuery())
|
|
|
|
->setViewer($blogger)
|
|
|
|
->withPHIDs(array($blog_phid))
|
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_JOIN,
|
|
|
|
))
|
|
|
|
->executeOne();
|
|
|
|
|
|
|
|
if (!$blog) {
|
|
|
|
throw new ConduitException('ERR-INVALID-BLOG');
|
|
|
|
}
|
|
|
|
|
|
|
|
$post = PhamePost::initializePost($blogger, $blog);
|
|
|
|
$is_draft = $request->getValue('isDraft', false);
|
|
|
|
if (!$is_draft) {
|
|
|
|
$post->setDatePublished(time());
|
|
|
|
$post->setVisibility(PhamePost::VISIBILITY_PUBLISHED);
|
|
|
|
}
|
|
|
|
$post->setTitle($title);
|
|
|
|
$phame_title = $request->getValue(
|
|
|
|
'phameTitle',
|
|
|
|
phutil_utf8_shorten($title, 64));
|
|
|
|
$post->setPhameTitle(PhabricatorSlug::normalize($phame_title));
|
|
|
|
$post->setBody($body);
|
|
|
|
$post->save();
|
|
|
|
|
|
|
|
return $post->toDictionary();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|