Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / maniphest / xaction / ManiphestTaskCoverImageTransaction.php
blob5e6f63c5c40a3a810cb4662c5eb86fdf1a0ec5f8
1 <?php
3 final class ManiphestTaskCoverImageTransaction
4 extends ManiphestTaskTransactionType {
6 const TRANSACTIONTYPE = 'cover-image';
8 public function generateOldValue($object) {
9 return $object->getCoverImageFilePHID();
12 public function applyInternalEffects($object, $value) {
13 $file_phid = $value;
15 if ($file_phid) {
16 $file = id(new PhabricatorFileQuery())
17 ->setViewer($this->getActor())
18 ->withPHIDs(array($file_phid))
19 ->executeOne();
20 } else {
21 $file = null;
24 if (!$file || !$file->isTransformableImage()) {
25 $object->setProperty('cover.filePHID', null);
26 $object->setProperty('cover.thumbnailPHID', null);
27 return;
30 $xform_key = PhabricatorFileThumbnailTransform::TRANSFORM_WORKCARD;
31 $xform = PhabricatorFileTransform::getTransformByKey($xform_key)
32 ->executeTransform($file);
34 $object->setProperty('cover.filePHID', $file->getPHID());
35 $object->setProperty('cover.thumbnailPHID', $xform->getPHID());
38 public function getTitle() {
39 $old = $this->getOldValue();
40 $new = $this->getNewValue();
42 if ($old === null) {
43 return pht(
44 '%s set the cover image to %s.',
45 $this->renderAuthor(),
46 $this->renderHandle($new));
49 return pht(
50 '%s updated the cover image to %s.',
51 $this->renderAuthor(),
52 $this->renderHandle($new));
56 public function getTitleForFeed() {
57 $old = $this->getOldValue();
58 if ($old === null) {
59 return pht(
60 '%s added a cover image to %s.',
61 $this->renderAuthor(),
62 $this->renderObject());
65 return pht(
66 '%s updated the cover image for %s.',
67 $this->renderAuthor(),
68 $this->renderObject());
71 public function validateTransactions($object, array $xactions) {
72 $errors = array();
73 $viewer = $this->getActor();
75 foreach ($xactions as $xaction) {
76 $file_phid = $xaction->getNewValue();
78 $file = id(new PhabricatorFileQuery())
79 ->setViewer($viewer)
80 ->withPHIDs(array($file_phid))
81 ->executeOne();
83 if (!$file) {
84 $errors[] = $this->newInvalidError(
85 pht(
86 'File PHID ("%s") is invalid, or you do not have permission '.
87 'to view it.',
88 $file_phid),
89 $xaction);
90 continue;
93 if (!$file->isViewableImage()) {
94 $errors[] = $this->newInvalidError(
95 pht(
96 'File ("%s", with MIME type "%s") is not a viewable image file.',
97 $file_phid,
98 $file->getMimeType()),
99 $xaction);
100 continue;
103 if (!$file->isTransformableImage()) {
104 $errors[] = $this->newInvalidError(
105 pht(
106 'File ("%s", with MIME type "%s") can not be transformed into '.
107 'a thumbnail. You may be missing support for this file type in '.
108 'the "GD" extension.',
109 $file_phid,
110 $file->getMimeType()),
111 $xaction);
112 continue;
116 return $errors;
119 public function getIcon() {
120 return 'fa-image';