@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class PhrictionDocumentPublishTransaction
4 extends PhrictionDocumentTransactionType {
5
6 const TRANSACTIONTYPE = 'publish';
7
8 public function generateOldValue($object) {
9 return $object->getContentPHID();
10 }
11
12 public function applyInternalEffects($object, $value) {
13 $object->setContentPHID($value);
14 }
15
16 public function getActionName() {
17 return pht('Published');
18 }
19
20 public function getTitle() {
21 return pht(
22 '%s published a new version of this document.',
23 $this->renderAuthor());
24 }
25
26 public function getTitleForFeed() {
27 return pht(
28 '%s published a new version of %s.',
29 $this->renderAuthor(),
30 $this->renderObject());
31 }
32
33 public function validateTransactions($object, array $xactions) {
34 $actor = $this->getActor();
35 $errors = array();
36
37 foreach ($xactions as $xaction) {
38 $content_phid = $xaction->getNewValue();
39
40 // If this isn't changing anything, skip it.
41 if ($content_phid === $object->getContentPHID()) {
42 continue;
43 }
44
45 $content = id(new PhrictionContentQuery())
46 ->setViewer($actor)
47 ->withPHIDs(array($content_phid))
48 ->executeOne();
49 if (!$content) {
50 $errors[] = $this->newInvalidError(
51 pht(
52 'Unable to load Content object with PHID "%s".',
53 $content_phid),
54 $xaction);
55 continue;
56 }
57
58 if ($content->getDocumentPHID() !== $object->getPHID()) {
59 $errors[] = $this->newInvalidError(
60 pht(
61 'Content object "%s" can not be published because it belongs '.
62 'to a different document.',
63 $content_phid));
64 continue;
65 }
66 }
67
68 return $errors;
69 }
70
71}