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);
27 $files = id(new PhabricatorFileQuery())
28 ->setViewer($this->getActor())
31 $files = mpull($files, null, 'getPHID');
33 $old_file = idx($files, $old);
35 $old_file->detachFromObject($object->getPHID());
38 $new_file = idx($files, $new);
40 $new_file->attachToObject($object->getPHID());
44 public function getTitle() {
46 '%s changed the image for this macro.',
47 $this->renderAuthor());
50 public function getTitleForFeed() {
52 '%s changed the image for %s.',
53 $this->renderAuthor(),
54 $this->renderObject());
57 public function validateTransactions($object, array $xactions) {
59 $viewer = $this->getActor();
61 $old_phid = $object->getFilePHID();
63 foreach ($xactions as $xaction) {
64 $file_phid = $xaction->getNewValue();
67 if ($this->isEmptyTextTransaction($file_phid, $xactions)) {
68 $errors[] = $this->newRequiredError(
69 pht('Image macros must have a file.'));
74 // Only validate if file was uploaded
76 $file = id(new PhabricatorFileQuery())
78 ->withPHIDs(array($file_phid))
82 $errors[] = $this->newInvalidError(
83 pht('"%s" is not a valid file PHID.',
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.',
100 public function getIcon() {
101 return 'fa-file-image-o';