Path: blob/master/src/applications/macro/xaction/PhabricatorMacroFileTransaction.php
12241 views
<?php12final class PhabricatorMacroFileTransaction3extends PhabricatorMacroTransactionType {45const TRANSACTIONTYPE = 'macro:file';67public function generateOldValue($object) {8return $object->getFilePHID();9}1011public function applyInternalEffects($object, $value) {12$object->setFilePHID($value);13}1415public function extractFilePHIDs($object, $value) {16return array($value);17}1819public function getTitle() {20return pht(21'%s changed the image for this macro.',22$this->renderAuthor());23}2425public function getTitleForFeed() {26return pht(27'%s changed the image for %s.',28$this->renderAuthor(),29$this->renderObject());30}3132public function validateTransactions($object, array $xactions) {33$errors = array();34$viewer = $this->getActor();3536$old_phid = $object->getFilePHID();3738foreach ($xactions as $xaction) {39$file_phid = $xaction->getNewValue();4041if (!$old_phid) {42if ($this->isEmptyTextTransaction($file_phid, $xactions)) {43$errors[] = $this->newRequiredError(44pht('Image macros must have a file.'));45return $errors;46}47}4849// Only validate if file was uploaded50if ($file_phid) {51$file = id(new PhabricatorFileQuery())52->setViewer($viewer)53->withPHIDs(array($file_phid))54->executeOne();5556if (!$file) {57$errors[] = $this->newInvalidError(58pht('"%s" is not a valid file PHID.',59$file_phid));60} else {61if (!$file->isViewableImage()) {62$mime_type = $file->getMimeType();63$errors[] = $this->newInvalidError(64pht('File mime type of "%s" is not a valid viewable image.',65$mime_type));66}67}68}6970}7172return $errors;73}7475public function getIcon() {76return 'fa-file-image-o';77}7879}808182