Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / macro / xaction / PhabricatorMacroFileTransaction.php
blob4e9f0190711ee4726fd12ae690c20e112e54919a
1 <?php
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) {
17 return array($value);
20 public function getTitle() {
21 return pht(
22 '%s changed the image for this macro.',
23 $this->renderAuthor());
26 public function getTitleForFeed() {
27 return pht(
28 '%s changed the image for %s.',
29 $this->renderAuthor(),
30 $this->renderObject());
33 public function validateTransactions($object, array $xactions) {
34 $errors = array();
35 $viewer = $this->getActor();
37 $old_phid = $object->getFilePHID();
39 foreach ($xactions as $xaction) {
40 $file_phid = $xaction->getNewValue();
42 if (!$old_phid) {
43 if ($this->isEmptyTextTransaction($file_phid, $xactions)) {
44 $errors[] = $this->newRequiredError(
45 pht('Image macros must have a file.'));
46 return $errors;
50 // Only validate if file was uploaded
51 if ($file_phid) {
52 $file = id(new PhabricatorFileQuery())
53 ->setViewer($viewer)
54 ->withPHIDs(array($file_phid))
55 ->executeOne();
57 if (!$file) {
58 $errors[] = $this->newInvalidError(
59 pht('"%s" is not a valid file PHID.',
60 $file_phid));
61 } else {
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.',
66 $mime_type));
73 return $errors;
76 public function getIcon() {
77 return 'fa-file-image-o';