@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at recaptime-dev/main 108 lines 2.8 kB view raw
1<?php 2 3final class PhabricatorProjectImageTransaction 4 extends PhabricatorProjectTransactionType { 5 6 const TRANSACTIONTYPE = 'project:image'; 7 8 public function generateOldValue($object) { 9 return $object->getProfileImagePHID(); 10 } 11 12 public function applyInternalEffects($object, $value) { 13 $object->setProfileImagePHID($value); 14 } 15 16 public function getTitle() { 17 $old = $this->getOldValue(); 18 $new = $this->getNewValue(); 19 20 // TODO: Some day, it would be nice to show the images. 21 if (!$old) { 22 return pht( 23 "%s set this project's image to %s.", 24 $this->renderAuthor(), 25 $this->renderNewHandle()); 26 } else if (!$new) { 27 return pht( 28 "%s removed this project's image.", 29 $this->renderAuthor()); 30 } else { 31 return pht( 32 "%s updated this project's image from %s to %s.", 33 $this->renderAuthor(), 34 $this->renderOldHandle(), 35 $this->renderNewHandle()); 36 } 37 } 38 39 public function getTitleForFeed() { 40 $old = $this->getOldValue(); 41 $new = $this->getNewValue(); 42 43 // TODO: Some day, it would be nice to show the images. 44 if (!$old) { 45 return pht( 46 '%s set the image for %s to %s.', 47 $this->renderAuthor(), 48 $this->renderObject(), 49 $this->renderNewHandle()); 50 } else if (!$new) { 51 return pht( 52 '%s removed the image for %s.', 53 $this->renderAuthor(), 54 $this->renderObject()); 55 } else { 56 return pht( 57 '%s updated the image for %s from %s to %s.', 58 $this->renderAuthor(), 59 $this->renderObject(), 60 $this->renderOldHandle(), 61 $this->renderNewHandle()); 62 } 63 } 64 65 public function getIcon() { 66 return 'fa-picture-o'; 67 } 68 69 public function extractFilePHIDs($object, $value) { 70 if ($value) { 71 return array($value); 72 } 73 return array(); 74 } 75 76 public function validateTransactions($object, array $xactions) { 77 $errors = array(); 78 $viewer = $this->getActor(); 79 80 foreach ($xactions as $xaction) { 81 $file_phid = $xaction->getNewValue(); 82 83 // Only validate if file was uploaded 84 if ($file_phid) { 85 $file = id(new PhabricatorFileQuery()) 86 ->setViewer($viewer) 87 ->withPHIDs(array($file_phid)) 88 ->executeOne(); 89 90 if (!$file) { 91 $errors[] = $this->newInvalidError( 92 pht('"%s" is not a valid file PHID.', 93 $file_phid)); 94 } else { 95 if (!$file->isViewableImage()) { 96 $mime_type = $file->getMimeType(); 97 $errors[] = $this->newInvalidError( 98 pht('File mime type of "%s" is not a valid viewable image.', 99 $mime_type)); 100 } 101 } 102 } 103 } 104 105 return $errors; 106 } 107 108}