Path: blob/master/src/applications/maniphest/xaction/ManiphestTaskCoverImageTransaction.php
12256 views
<?php12final class ManiphestTaskCoverImageTransaction3extends ManiphestTaskTransactionType {45const TRANSACTIONTYPE = 'cover-image';67public function generateOldValue($object) {8return $object->getCoverImageFilePHID();9}1011public function applyInternalEffects($object, $value) {12$file_phid = $value;1314if ($file_phid) {15$file = id(new PhabricatorFileQuery())16->setViewer($this->getActor())17->withPHIDs(array($file_phid))18->executeOne();19} else {20$file = null;21}2223if (!$file || !$file->isTransformableImage()) {24$object->setProperty('cover.filePHID', null);25$object->setProperty('cover.thumbnailPHID', null);26return;27}2829$xform_key = PhabricatorFileThumbnailTransform::TRANSFORM_WORKCARD;30$xform = PhabricatorFileTransform::getTransformByKey($xform_key)31->executeTransform($file);3233$object->setProperty('cover.filePHID', $file->getPHID());34$object->setProperty('cover.thumbnailPHID', $xform->getPHID());35}3637public function getTitle() {38$old = $this->getOldValue();39$new = $this->getNewValue();4041if ($old === null) {42return pht(43'%s set the cover image to %s.',44$this->renderAuthor(),45$this->renderHandle($new));46}4748return pht(49'%s updated the cover image to %s.',50$this->renderAuthor(),51$this->renderHandle($new));5253}5455public function getTitleForFeed() {56$old = $this->getOldValue();57if ($old === null) {58return pht(59'%s added a cover image to %s.',60$this->renderAuthor(),61$this->renderObject());62}6364return pht(65'%s updated the cover image for %s.',66$this->renderAuthor(),67$this->renderObject());68}6970public function validateTransactions($object, array $xactions) {71$errors = array();72$viewer = $this->getActor();7374foreach ($xactions as $xaction) {75$file_phid = $xaction->getNewValue();7677$file = id(new PhabricatorFileQuery())78->setViewer($viewer)79->withPHIDs(array($file_phid))80->executeOne();8182if (!$file) {83$errors[] = $this->newInvalidError(84pht(85'File PHID ("%s") is invalid, or you do not have permission '.86'to view it.',87$file_phid),88$xaction);89continue;90}9192if (!$file->isViewableImage()) {93$errors[] = $this->newInvalidError(94pht(95'File ("%s", with MIME type "%s") is not a viewable image file.',96$file_phid,97$file->getMimeType()),98$xaction);99continue;100}101102if (!$file->isTransformableImage()) {103$errors[] = $this->newInvalidError(104pht(105'File ("%s", with MIME type "%s") can not be transformed into '.106'a thumbnail. You may be missing support for this file type in '.107'the "GD" extension.',108$file_phid,109$file->getMimeType()),110$xaction);111continue;112}113}114115return $errors;116}117118public function getIcon() {119return 'fa-image';120}121122123}124125126