@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 PhrictionDocumentDeleteTransaction
4 extends PhrictionDocumentVersionTransaction {
5
6 const TRANSACTIONTYPE = 'delete';
7
8 public function generateOldValue($object) {
9 return null;
10 }
11
12 public function applyInternalEffects($object, $value) {
13 $object->setStatus(PhrictionDocumentStatus::STATUS_DELETED);
14
15 $content = $this->getNewDocumentContent($object);
16
17 $content->setContent('');
18 $content->setChangeType(PhrictionChangeType::CHANGE_DELETE);
19 }
20
21 public function getActionStrength() {
22 return 150;
23 }
24
25 public function getActionName() {
26 return pht('Deleted');
27 }
28
29 public function getTitle() {
30 return pht(
31 '%s deleted this document.',
32 $this->renderAuthor());
33 }
34
35 public function getTitleForFeed() {
36 return pht(
37 '%s deleted %s.',
38 $this->renderAuthor(),
39 $this->renderObject());
40 }
41
42 public function validateTransactions($object, array $xactions) {
43 $errors = array();
44
45 $e_text = null;
46 foreach ($xactions as $xaction) {
47 switch ($object->getStatus()) {
48 case PhrictionDocumentStatus::STATUS_DELETED:
49 if ($xaction->getMetadataValue('contentDelete')) {
50 $e_text = pht(
51 'This document is already deleted. You must specify '.
52 'content to re-create the document and make further edits.');
53 } else {
54 $e_text = pht(
55 'An already deleted document can not be deleted.');
56 }
57 break;
58 case PhrictionDocumentStatus::STATUS_MOVED:
59 $e_text = pht('A moved document can not be deleted.');
60 break;
61 case PhrictionDocumentStatus::STATUS_STUB:
62 $e_text = pht('A stub document can not be deleted.');
63 break;
64 default:
65 break;
66 }
67
68 if ($e_text !== null) {
69 $errors[] = $this->newInvalidError($e_text);
70 }
71
72 }
73
74 return $errors;
75 }
76
77 public function getIcon() {
78 return 'fa-trash-o';
79 }
80
81 public function getColor() {
82 return 'red';
83 }
84
85}