3 final class PhrictionDocumentTitleTransaction
4 extends PhrictionDocumentVersionTransaction
{
6 const TRANSACTIONTYPE
= 'title';
8 public function generateOldValue($object) {
9 if ($this->isNewObject()) {
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() {
27 public function getActionName() {
28 $old = $this->getOldValue();
29 $new = $this->getNewValue();
32 if ($this->getMetadataValue('stub:create:phid')) {
33 return pht('Stubbed');
35 return pht('Created');
38 return pht('Retitled');
41 public function getTitle() {
42 $old = $this->getOldValue();
43 $new = $this->getNewValue();
46 if ($this->getMetadataValue('stub:create:phid')) {
48 '%s stubbed out this document when creating %s.',
49 $this->renderAuthor(),
50 $this->renderHandleLink(
51 $this->getMetadataValue('stub:create:phid')));
54 '%s created this document.',
55 $this->renderAuthor());
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();
73 $this->renderAuthor(),
74 $this->renderObject());
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) {
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
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
101 $parent_document = id(new PhrictionDocumentQuery())
102 ->setViewer($this->getActor())
103 ->withSlugs(array(last($ancestral_slugs)))
104 ->requireCapabilities(
106 PhabricatorPolicyCapability
::CAN_VIEW
,
107 PhabricatorPolicyCapability
::CAN_EDIT
,
110 if (!$parent_document) {
111 $errors[] = $this->newInvalidError(
112 pht('You can not create a document which does not have a parent.'));