Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / phriction / xaction / PhrictionDocumentTitleTransaction.php
blob134a4540eedb1d284666ce1efcfbccb7e66e5dfb
1 <?php
3 final class PhrictionDocumentTitleTransaction
4 extends PhrictionDocumentVersionTransaction {
6 const TRANSACTIONTYPE = 'title';
8 public function generateOldValue($object) {
9 if ($this->isNewObject()) {
10 return null;
12 return $this->getEditor()->getOldContent()->getTitle();
15 public function applyInternalEffects($object, $value) {
16 $object->setStatus(PhrictionDocumentStatus::STATUS_EXISTS);
18 $content = $this->getNewDocumentContent($object);
20 $content->setTitle($value);
23 public function getActionStrength() {
24 return 140;
27 public function getActionName() {
28 $old = $this->getOldValue();
29 $new = $this->getNewValue();
31 if ($old === null) {
32 if ($this->getMetadataValue('stub:create:phid')) {
33 return pht('Stubbed');
34 } else {
35 return pht('Created');
38 return pht('Retitled');
41 public function getTitle() {
42 $old = $this->getOldValue();
43 $new = $this->getNewValue();
45 if ($old === null) {
46 if ($this->getMetadataValue('stub:create:phid')) {
47 return pht(
48 '%s stubbed out this document when creating %s.',
49 $this->renderAuthor(),
50 $this->renderHandleLink(
51 $this->getMetadataValue('stub:create:phid')));
52 } else {
53 return pht(
54 '%s created this document.',
55 $this->renderAuthor());
59 return pht(
60 '%s changed the title from %s to %s.',
61 $this->renderAuthor(),
62 $this->renderOldValue(),
63 $this->renderNewValue());
66 public function getTitleForFeed() {
67 $old = $this->getOldValue();
68 $new = $this->getNewValue();
70 if ($old === null) {
71 return pht(
72 '%s created %s.',
73 $this->renderAuthor(),
74 $this->renderObject());
77 return pht(
78 '%s renamed %s from %s to %s.',
79 $this->renderAuthor(),
80 $this->renderObject(),
81 $this->renderOldValue(),
82 $this->renderNewValue());
85 public function validateTransactions($object, array $xactions) {
86 $errors = array();
88 $title = $object->getContent()->getTitle();
89 if ($this->isEmptyTextTransaction($title, $xactions)) {
90 $errors[] = $this->newRequiredError(
91 pht('Documents must have a title.'));
94 if ($this->isNewObject()) {
95 // No ancestral slugs is "/". No ancestry checks apply when creating the
96 // root document.
97 $ancestral_slugs = PhabricatorSlug::getAncestry($object->getSlug());
98 if ($ancestral_slugs) {
99 // You must be able to view and edit the parent document to create a new
100 // child.
101 $parent_document = id(new PhrictionDocumentQuery())
102 ->setViewer($this->getActor())
103 ->withSlugs(array(last($ancestral_slugs)))
104 ->requireCapabilities(
105 array(
106 PhabricatorPolicyCapability::CAN_VIEW,
107 PhabricatorPolicyCapability::CAN_EDIT,
109 ->executeOne();
110 if (!$parent_document) {
111 $errors[] = $this->newInvalidError(
112 pht('You can not create a document which does not have a parent.'));
117 return $errors;