Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/macro/xaction/PhabricatorMacroFileTransaction.php
12241 views
1
<?php
2
3
final class PhabricatorMacroFileTransaction
4
extends PhabricatorMacroTransactionType {
5
6
const TRANSACTIONTYPE = 'macro:file';
7
8
public function generateOldValue($object) {
9
return $object->getFilePHID();
10
}
11
12
public function applyInternalEffects($object, $value) {
13
$object->setFilePHID($value);
14
}
15
16
public function extractFilePHIDs($object, $value) {
17
return array($value);
18
}
19
20
public function getTitle() {
21
return pht(
22
'%s changed the image for this macro.',
23
$this->renderAuthor());
24
}
25
26
public function getTitleForFeed() {
27
return pht(
28
'%s changed the image for %s.',
29
$this->renderAuthor(),
30
$this->renderObject());
31
}
32
33
public function validateTransactions($object, array $xactions) {
34
$errors = array();
35
$viewer = $this->getActor();
36
37
$old_phid = $object->getFilePHID();
38
39
foreach ($xactions as $xaction) {
40
$file_phid = $xaction->getNewValue();
41
42
if (!$old_phid) {
43
if ($this->isEmptyTextTransaction($file_phid, $xactions)) {
44
$errors[] = $this->newRequiredError(
45
pht('Image macros must have a file.'));
46
return $errors;
47
}
48
}
49
50
// Only validate if file was uploaded
51
if ($file_phid) {
52
$file = id(new PhabricatorFileQuery())
53
->setViewer($viewer)
54
->withPHIDs(array($file_phid))
55
->executeOne();
56
57
if (!$file) {
58
$errors[] = $this->newInvalidError(
59
pht('"%s" is not a valid file PHID.',
60
$file_phid));
61
} else {
62
if (!$file->isViewableImage()) {
63
$mime_type = $file->getMimeType();
64
$errors[] = $this->newInvalidError(
65
pht('File mime type of "%s" is not a valid viewable image.',
66
$mime_type));
67
}
68
}
69
}
70
71
}
72
73
return $errors;
74
}
75
76
public function getIcon() {
77
return 'fa-file-image-o';
78
}
79
80
}
81
82