Changeset View
Changeset View
Standalone View
Standalone View
src/applications/macro/xaction/PhabricatorMacroFileTransaction.php
<?php | <?php | ||||
final class PhabricatorMacroFileTransaction | final class PhabricatorMacroFileTransaction | ||||
extends PhabricatorMacroTransactionType { | extends PhabricatorMacroTransactionType { | ||||
const TRANSACTIONTYPE = 'macro:file'; | const TRANSACTIONTYPE = 'macro:file'; | ||||
public function generateOldValue($object) { | public function generateOldValue($object) { | ||||
return $object->getFilePHID(); | return $object->getFilePHID(); | ||||
} | } | ||||
public function applyInternalEffects($object, $value) { | public function applyInternalEffects($object, $value) { | ||||
$object->setFilePHID($value); | $object->setFilePHID($value); | ||||
} | } | ||||
epriestley: What's this one for? | |||||
Not Done Inline ActionsEditing a macro without changing the file generates an empty transaction instead of no transaction. chad: Editing a macro without changing the file generates an empty transaction instead of no… | |||||
Not Done Inline ActionsSpecifically, it tries to set null, and the column isn't nullable. chad: Specifically, it tries to set `null`, and the column isn't nullable. | |||||
public function applyExternalEffects($object, $value) { | public function applyExternalEffects($object, $value) { | ||||
$old = $this->generateOldValue($object); | $old = $this->generateOldValue($object); | ||||
$new = $value; | $new = $value; | ||||
$all = array(); | $all = array(); | ||||
if ($old) { | if ($old) { | ||||
$all[] = $old; | $all[] = $old; | ||||
} | } | ||||
Show All 21 Lines | final class PhabricatorMacroFileTransaction | ||||
public function getTitle() { | public function getTitle() { | ||||
return pht( | return pht( | ||||
'%s changed the image for this macro.', | '%s changed the image for this macro.', | ||||
$this->renderAuthor()); | $this->renderAuthor()); | ||||
} | } | ||||
public function getTitleForFeed() { | public function getTitleForFeed() { | ||||
return pht( | return pht( | ||||
'%s changed the image for macro %s.', | '%s changed the image for %s.', | ||||
$this->renderAuthor(), | $this->renderAuthor(), | ||||
$this->renderObject()); | $this->renderObject()); | ||||
} | } | ||||
public function validateTransactions($object, array $xactions) { | public function validateTransactions($object, array $xactions) { | ||||
$errors = array(); | $errors = array(); | ||||
$viewer = $this->getActor(); | $viewer = $this->getActor(); | ||||
$old_phid = $object->getFilePHID(); | |||||
foreach ($xactions as $xaction) { | foreach ($xactions as $xaction) { | ||||
$file_phid = $xaction->getNewValue(); | $file_phid = $xaction->getNewValue(); | ||||
if (!$old_phid) { | |||||
if ($this->isEmptyTextTransaction($file_phid, $xactions)) { | if ($this->isEmptyTextTransaction($file_phid, $xactions)) { | ||||
$errors[] = $this->newRequiredError( | $errors[] = $this->newRequiredError( | ||||
pht('Image macros must have a file.')); | pht('Image macros must have a file.')); | ||||
return $errors; | |||||
} | |||||
} | } | ||||
// Only validate if file was uploaded | |||||
if ($file_phid) { | |||||
$file = id(new PhabricatorFileQuery()) | $file = id(new PhabricatorFileQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withPHIDs(array($file_phid)) | ->withPHIDs(array($file_phid)) | ||||
->executeOne(); | ->executeOne(); | ||||
if (!$file) { | if (!$file) { | ||||
$errors[] = $this->newInvalidError( | $errors[] = $this->newInvalidError( | ||||
pht('"%s" is not a valid file PHID.', | pht('"%s" is not a valid file PHID.', | ||||
$file_phid)); | $file_phid)); | ||||
} else { | } else { | ||||
if (!$file->isViewableInBrowser()) { | if (!$file->isViewableImage()) { | ||||
$mime_type = $file->getMimeType(); | $mime_type = $file->getMimeType(); | ||||
$errors[] = $this->newInvalidError( | $errors[] = $this->newInvalidError( | ||||
pht('File mime type of "%s" is not a valid viewable image.', | pht('File mime type of "%s" is not a valid viewable image.', | ||||
$mime_type)); | $mime_type)); | ||||
} | } | ||||
} | } | ||||
} | |||||
} | } | ||||
return $errors; | return $errors; | ||||
} | } | ||||
public function getIcon() { | public function getIcon() { | ||||
return 'fa-file-image-o'; | return 'fa-file-image-o'; | ||||
} | } | ||||
} | } |
What's this one for?