Give Phame blogs mutable interact policies
[phabricator.git] / src / applications / phame / xaction / PhamePostBlogTransaction.php
blobcfe335a6ce5a59dda876d3c272f07cd7319b951d
1 <?php
3 final class PhamePostBlogTransaction
4 extends PhamePostTransactionType {
6 const TRANSACTIONTYPE = 'phame.post.blog';
8 public function generateOldValue($object) {
9 return $object->getBlogPHID();
12 public function applyInternalEffects($object, $value) {
13 $object->setBlogPHID($value);
16 public function getTitle() {
17 return pht(
18 '%s changed the blog for this post.',
19 $this->renderAuthor());
22 public function getTitleForFeed() {
23 return pht(
24 '%s changed the blog for post %s.',
25 $this->renderAuthor(),
26 $this->renderObject());
29 public function validateTransactions($object, array $xactions) {
30 $errors = array();
32 if ($this->isEmptyTextTransaction($object->getBlogPHID(), $xactions)) {
33 $errors[] = $this->newRequiredError(
34 pht('Posts must be attached to a blog.'));
37 foreach ($xactions as $xaction) {
38 $new_phid = $xaction->getNewValue();
40 $blog = id(new PhameBlogQuery())
41 ->setViewer($this->getActor())
42 ->withPHIDs(array($new_phid))
43 ->requireCapabilities(
44 array(
45 PhabricatorPolicyCapability::CAN_VIEW,
46 PhabricatorPolicyCapability::CAN_EDIT,
48 ->execute();
50 if ($blog) {
51 continue;
54 $errors[] = $this->newInvalidError(
55 pht('The specified blog PHID ("%s") is not valid. You can only '.
56 'create a post on (or move a post into) a blog which you '.
57 'have permission to see and edit.',
58 $new_phid));
61 return $errors;