@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 PhabricatorCountdown extends PhabricatorCountdownDAO
4 implements
5 PhabricatorPolicyInterface,
6 PhabricatorFlaggableInterface,
7 PhabricatorSubscribableInterface,
8 PhabricatorApplicationTransactionInterface,
9 PhabricatorTokenReceiverInterface,
10 PhabricatorSpacesInterface,
11 PhabricatorProjectInterface,
12 PhabricatorDestructibleInterface,
13 PhabricatorConduitResultInterface {
14
15 protected $title;
16 protected $authorPHID;
17 protected $epoch;
18 protected $description;
19 protected $viewPolicy;
20 protected $editPolicy;
21 protected $mailKey;
22 protected $spacePHID;
23
24 public static function initializeNewCountdown(PhabricatorUser $actor) {
25 $app = id(new PhabricatorApplicationQuery())
26 ->setViewer($actor)
27 ->withClasses(array(PhabricatorCountdownApplication::class))
28 ->executeOne();
29
30 $view_policy = $app->getPolicy(
31 PhabricatorCountdownDefaultViewCapability::CAPABILITY);
32
33 $edit_policy = $app->getPolicy(
34 PhabricatorCountdownDefaultEditCapability::CAPABILITY);
35
36 return id(new PhabricatorCountdown())
37 ->setAuthorPHID($actor->getPHID())
38 ->setViewPolicy($view_policy)
39 ->setEditPolicy($edit_policy)
40 ->setSpacePHID($actor->getDefaultSpacePHID());
41 }
42
43 protected function getConfiguration() {
44 return array(
45 self::CONFIG_AUX_PHID => true,
46 self::CONFIG_COLUMN_SCHEMA => array(
47 'title' => 'text255',
48 'description' => 'text',
49 'mailKey' => 'bytes20',
50 ),
51 self::CONFIG_KEY_SCHEMA => array(
52 'key_epoch' => array(
53 'columns' => array('epoch'),
54 ),
55 'key_author' => array(
56 'columns' => array('authorPHID', 'epoch'),
57 ),
58 ),
59 ) + parent::getConfiguration();
60 }
61
62 public function generatePHID() {
63 return PhabricatorPHID::generateNewPHID(
64 PhabricatorCountdownCountdownPHIDType::TYPECONST);
65 }
66
67 public function getMonogram() {
68 return 'C'.$this->getID();
69 }
70
71 public function getURI() {
72 return '/'.$this->getMonogram();
73 }
74
75 public function save() {
76 if (!$this->getMailKey()) {
77 $this->setMailKey(Filesystem::readRandomCharacters(20));
78 }
79 return parent::save();
80 }
81
82
83/* -( PhabricatorSubscribableInterface )----------------------------------- */
84
85
86 public function isAutomaticallySubscribed($phid) {
87 return ($phid == $this->getAuthorPHID());
88 }
89
90
91/* -( PhabricatorApplicationTransactionInterface )------------------------- */
92
93
94 public function getApplicationTransactionEditor() {
95 return new PhabricatorCountdownEditor();
96 }
97
98 public function getApplicationTransactionTemplate() {
99 return new PhabricatorCountdownTransaction();
100 }
101
102
103/* -( PhabricatorTokenReceiverInterface )---------------------------------- */
104
105
106 public function getUsersToNotifyOfTokenGiven() {
107 return array($this->getAuthorPHID());
108 }
109
110
111/* -( PhabricatorPolicyInterface )----------------------------------------- */
112
113
114 public function getCapabilities() {
115 return array(
116 PhabricatorPolicyCapability::CAN_VIEW,
117 PhabricatorPolicyCapability::CAN_EDIT,
118 );
119 }
120
121 public function getPolicy($capability) {
122 switch ($capability) {
123 case PhabricatorPolicyCapability::CAN_VIEW:
124 return $this->getViewPolicy();
125 case PhabricatorPolicyCapability::CAN_EDIT:
126 return $this->getEditPolicy();
127 }
128 }
129
130 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
131 return false;
132 }
133
134/* -( PhabricatorSpacesInterface )------------------------------------------- */
135
136
137 public function getSpacePHID() {
138 return $this->spacePHID;
139 }
140
141/* -( PhabricatorDestructibleInterface )----------------------------------- */
142
143
144 public function destroyObjectPermanently(
145 PhabricatorDestructionEngine $engine) {
146
147 $this->openTransaction();
148 $this->delete();
149 $this->saveTransaction();
150 }
151
152/* -( PhabricatorConduitResultInterface )---------------------------------- */
153
154
155 public function getFieldSpecificationsForConduit() {
156 return array(
157 id(new PhabricatorConduitSearchFieldSpecification())
158 ->setKey('title')
159 ->setType('string')
160 ->setDescription(pht('The title of the countdown.')),
161 id(new PhabricatorConduitSearchFieldSpecification())
162 ->setKey('description')
163 ->setType('remarkup')
164 ->setDescription(pht('The description of the countdown.')),
165 id(new PhabricatorConduitSearchFieldSpecification())
166 ->setKey('epoch')
167 ->setType('epoch')
168 ->setDescription(pht('The end date of the countdown.')),
169 );
170 }
171
172 public function getFieldValuesForConduit() {
173 return array(
174 'title' => $this->getTitle(),
175 'description' => array(
176 'raw' => $this->getDescription(),
177 ),
178 'epoch' => (int)$this->getEpoch(),
179 );
180 }
181
182 public function getConduitSearchAttachments() {
183 return array();
184 }
185
186}