Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/maniphest/xaction/ManiphestTaskCoverImageTransaction.php
12256 views
1
<?php
2
3
final class ManiphestTaskCoverImageTransaction
4
extends ManiphestTaskTransactionType {
5
6
const TRANSACTIONTYPE = 'cover-image';
7
8
public function generateOldValue($object) {
9
return $object->getCoverImageFilePHID();
10
}
11
12
public function applyInternalEffects($object, $value) {
13
$file_phid = $value;
14
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;
22
}
23
24
if (!$file || !$file->isTransformableImage()) {
25
$object->setProperty('cover.filePHID', null);
26
$object->setProperty('cover.thumbnailPHID', null);
27
return;
28
}
29
30
$xform_key = PhabricatorFileThumbnailTransform::TRANSFORM_WORKCARD;
31
$xform = PhabricatorFileTransform::getTransformByKey($xform_key)
32
->executeTransform($file);
33
34
$object->setProperty('cover.filePHID', $file->getPHID());
35
$object->setProperty('cover.thumbnailPHID', $xform->getPHID());
36
}
37
38
public function getTitle() {
39
$old = $this->getOldValue();
40
$new = $this->getNewValue();
41
42
if ($old === null) {
43
return pht(
44
'%s set the cover image to %s.',
45
$this->renderAuthor(),
46
$this->renderHandle($new));
47
}
48
49
return pht(
50
'%s updated the cover image to %s.',
51
$this->renderAuthor(),
52
$this->renderHandle($new));
53
54
}
55
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());
63
}
64
65
return pht(
66
'%s updated the cover image for %s.',
67
$this->renderAuthor(),
68
$this->renderObject());
69
}
70
71
public function validateTransactions($object, array $xactions) {
72
$errors = array();
73
$viewer = $this->getActor();
74
75
foreach ($xactions as $xaction) {
76
$file_phid = $xaction->getNewValue();
77
78
$file = id(new PhabricatorFileQuery())
79
->setViewer($viewer)
80
->withPHIDs(array($file_phid))
81
->executeOne();
82
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;
91
}
92
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;
101
}
102
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;
113
}
114
}
115
116
return $errors;
117
}
118
119
public function getIcon() {
120
return 'fa-image';
121
}
122
123
124
}
125
126