Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / pholio / editor / PholioMockEditor.php
blobdf5d55672c10718abf10a9e6c74e8b8a211f10fd
1 <?php
3 final class PholioMockEditor extends PhabricatorApplicationTransactionEditor {
5 private $images = array();
7 public function getEditorApplicationClass() {
8 return 'PhabricatorPholioApplication';
11 public function getEditorObjectsDescription() {
12 return pht('Pholio Mocks');
15 public function getCreateObjectTitle($author, $object) {
16 return pht('%s created this mock.', $author);
19 public function getCreateObjectTitleForFeed($author, $object) {
20 return pht('%s created %s.', $author, $object);
23 public function getTransactionTypes() {
24 $types = parent::getTransactionTypes();
26 $types[] = PhabricatorTransactions::TYPE_EDGE;
27 $types[] = PhabricatorTransactions::TYPE_COMMENT;
28 $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
29 $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
31 return $types;
34 protected function shouldSendMail(
35 PhabricatorLiskDAO $object,
36 array $xactions) {
37 return true;
40 protected function buildReplyHandler(PhabricatorLiskDAO $object) {
41 return id(new PholioReplyHandler())
42 ->setMailReceiver($object);
45 protected function buildMailTemplate(PhabricatorLiskDAO $object) {
46 $monogram = $object->getMonogram();
47 $name = $object->getName();
49 return id(new PhabricatorMetaMTAMail())
50 ->setSubject("{$monogram}: {$name}");
53 protected function getMailTo(PhabricatorLiskDAO $object) {
54 return array(
55 $object->getAuthorPHID(),
56 $this->requireActor()->getPHID(),
60 protected function buildMailBody(
61 PhabricatorLiskDAO $object,
62 array $xactions) {
64 $viewer = $this->requireActor();
66 $body = id(new PhabricatorMetaMTAMailBody())
67 ->setViewer($viewer);
69 $mock_uri = $object->getURI();
70 $mock_uri = PhabricatorEnv::getProductionURI($mock_uri);
72 $this->addHeadersAndCommentsToMailBody(
73 $body,
74 $xactions,
75 pht('View Mock'),
76 $mock_uri);
78 $type_inline = PholioMockInlineTransaction::TRANSACTIONTYPE;
80 $inlines = array();
81 foreach ($xactions as $xaction) {
82 if ($xaction->getTransactionType() == $type_inline) {
83 $inlines[] = $xaction;
87 $this->appendInlineCommentsForMail($object, $inlines, $body);
89 $body->addLinkSection(
90 pht('MOCK DETAIL'),
91 PhabricatorEnv::getProductionURI($object->getURI()));
93 return $body;
96 private function appendInlineCommentsForMail(
97 $object,
98 array $inlines,
99 PhabricatorMetaMTAMailBody $body) {
101 if (!$inlines) {
102 return;
105 $viewer = $this->requireActor();
107 $header = pht('INLINE COMMENTS');
108 $body->addRawPlaintextSection($header);
109 $body->addRawHTMLSection(phutil_tag('strong', array(), $header));
111 $image_ids = array();
112 foreach ($inlines as $inline) {
113 $comment = $inline->getComment();
114 $image_id = $comment->getImageID();
115 $image_ids[$image_id] = $image_id;
118 $images = id(new PholioImageQuery())
119 ->setViewer($viewer)
120 ->withIDs($image_ids)
121 ->execute();
122 $images = mpull($images, null, 'getID');
124 foreach ($inlines as $inline) {
125 $comment = $inline->getComment();
126 $content = $comment->getContent();
127 $image_id = $comment->getImageID();
128 $image = idx($images, $image_id);
129 if ($image) {
130 $image_name = $image->getName();
131 } else {
132 $image_name = pht('Unknown (ID %d)', $image_id);
135 $body->addRemarkupSection(
136 pht('Image "%s":', $image_name),
137 $content);
141 protected function getMailSubjectPrefix() {
142 return pht('[Pholio]');
145 public function getMailTagsMap() {
146 return array(
147 PholioTransaction::MAILTAG_STATUS =>
148 pht("A mock's status changes."),
149 PholioTransaction::MAILTAG_COMMENT =>
150 pht('Someone comments on a mock.'),
151 PholioTransaction::MAILTAG_UPDATED =>
152 pht('Mock images or descriptions change.'),
153 PholioTransaction::MAILTAG_OTHER =>
154 pht('Other mock activity not listed above occurs.'),
158 protected function shouldPublishFeedStory(
159 PhabricatorLiskDAO $object,
160 array $xactions) {
161 return true;
164 protected function supportsSearch() {
165 return true;
168 protected function shouldApplyHeraldRules(
169 PhabricatorLiskDAO $object,
170 array $xactions) {
171 return true;
174 protected function buildHeraldAdapter(
175 PhabricatorLiskDAO $object,
176 array $xactions) {
178 return id(new HeraldPholioMockAdapter())
179 ->setMock($object);
182 protected function sortTransactions(array $xactions) {
183 $head = array();
184 $tail = array();
186 // Move inline comments to the end, so the comments precede them.
187 foreach ($xactions as $xaction) {
188 $type = $xaction->getTransactionType();
189 if ($type == PholioMockInlineTransaction::TRANSACTIONTYPE) {
190 $tail[] = $xaction;
191 } else {
192 $head[] = $xaction;
196 return array_values(array_merge($head, $tail));
199 protected function shouldImplyCC(
200 PhabricatorLiskDAO $object,
201 PhabricatorApplicationTransaction $xaction) {
203 switch ($xaction->getTransactionType()) {
204 case PholioMockInlineTransaction::TRANSACTIONTYPE:
205 return true;
208 return parent::shouldImplyCC($object, $xaction);
211 public function loadPholioImage($object, $phid) {
212 if (!isset($this->images[$phid])) {
214 $image = id(new PholioImageQuery())
215 ->setViewer($this->getActor())
216 ->withPHIDs(array($phid))
217 ->executeOne();
219 if (!$image) {
220 throw new Exception(
221 pht(
222 'No image exists with PHID "%s".',
223 $phid));
226 $mock_phid = $image->getMockPHID();
227 if ($mock_phid) {
228 if ($mock_phid !== $object->getPHID()) {
229 throw new Exception(
230 pht(
231 'Image ("%s") belongs to the wrong object ("%s", expected "%s").',
232 $phid,
233 $mock_phid,
234 $object->getPHID()));
238 $this->images[$phid] = $image;
241 return $this->images[$phid];