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 extractFilePHIDs($object, $value) {
20 public function getTitle() {
22 '%s changed the image for this macro.',
23 $this->renderAuthor());
26 public function getTitleForFeed() {
28 '%s changed the image for %s.',
29 $this->renderAuthor(),
30 $this->renderObject());
33 public function validateTransactions($object, array $xactions) {
35 $viewer = $this->getActor();
37 $old_phid = $object->getFilePHID();
39 foreach ($xactions as $xaction) {
40 $file_phid = $xaction->getNewValue();
43 if ($this->isEmptyTextTransaction($file_phid, $xactions)) {
44 $errors[] = $this->newRequiredError(
45 pht('Image macros must have a file.'));
50 // Only validate if file was uploaded
52 $file = id(new PhabricatorFileQuery())
54 ->withPHIDs(array($file_phid))
58 $errors[] = $this->newInvalidError(
59 pht('"%s" is not a valid file PHID.',
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.',
76 public function getIcon() {
77 return 'fa-file-image-o';