Remove product literal strings in "pht()", part 6
[phabricator.git] / src / applications / macro / xaction / PhabricatorMacroFileTransaction.php
blobfb0c56f1c1c3c758af32eef81e7c09c9f82501b1
1 <?php
3 final class PhabricatorMacroFileTransaction
4 extends PhabricatorMacroTransactionType {
6 const TRANSACTIONTYPE = 'macro:file';
8 public function generateOldValue($object) {
9 return $object->getFilePHID();
12 public function applyInternalEffects($object, $value) {
13 $object->setFilePHID($value);
16 public function applyExternalEffects($object, $value) {
17 $old = $this->generateOldValue($object);
18 $new = $value;
19 $all = array();
20 if ($old) {
21 $all[] = $old;
23 if ($new) {
24 $all[] = $new;
27 $files = id(new PhabricatorFileQuery())
28 ->setViewer($this->getActor())
29 ->withPHIDs($all)
30 ->execute();
31 $files = mpull($files, null, 'getPHID');
33 $old_file = idx($files, $old);
34 if ($old_file) {
35 $old_file->detachFromObject($object->getPHID());
38 $new_file = idx($files, $new);
39 if ($new_file) {
40 $new_file->attachToObject($object->getPHID());
44 public function getTitle() {
45 return pht(
46 '%s changed the image for this macro.',
47 $this->renderAuthor());
50 public function getTitleForFeed() {
51 return pht(
52 '%s changed the image for %s.',
53 $this->renderAuthor(),
54 $this->renderObject());
57 public function validateTransactions($object, array $xactions) {
58 $errors = array();
59 $viewer = $this->getActor();
61 $old_phid = $object->getFilePHID();
63 foreach ($xactions as $xaction) {
64 $file_phid = $xaction->getNewValue();
66 if (!$old_phid) {
67 if ($this->isEmptyTextTransaction($file_phid, $xactions)) {
68 $errors[] = $this->newRequiredError(
69 pht('Image macros must have a file.'));
70 return $errors;
74 // Only validate if file was uploaded
75 if ($file_phid) {
76 $file = id(new PhabricatorFileQuery())
77 ->setViewer($viewer)
78 ->withPHIDs(array($file_phid))
79 ->executeOne();
81 if (!$file) {
82 $errors[] = $this->newInvalidError(
83 pht('"%s" is not a valid file PHID.',
84 $file_phid));
85 } else {
86 if (!$file->isViewableImage()) {
87 $mime_type = $file->getMimeType();
88 $errors[] = $this->newInvalidError(
89 pht('File mime type of "%s" is not a valid viewable image.',
90 $mime_type));
97 return $errors;
100 public function getIcon() {
101 return 'fa-file-image-o';