@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 140 lines 3.4 kB view raw
1<?php 2 3final class PholioImageReplaceTransaction 4 extends PholioImageTransactionType { 5 6 const TRANSACTIONTYPE = 'image-replace'; 7 8 public function generateOldValue($object) { 9 $editor = $this->getEditor(); 10 $new_phid = $this->getNewValue(); 11 12 return $editor->loadPholioImage($object, $new_phid) 13 ->getReplacesImagePHID(); 14 } 15 16 public function applyExternalEffects($object, $value) { 17 $editor = $this->getEditor(); 18 $old_phid = $this->getOldValue(); 19 20 $old_image = $editor->loadPholioImage($object, $old_phid) 21 ->setIsObsolete(1) 22 ->save(); 23 24 $editor->loadPholioImage($object, $value) 25 ->setMockPHID($object->getPHID()) 26 ->setSequence($old_image->getSequence()) 27 ->save(); 28 } 29 30 public function getTitle() { 31 return pht( 32 '%s replaced %s with %s.', 33 $this->renderAuthor(), 34 $this->renderOldHandle(), 35 $this->renderNewHandle()); 36 } 37 38 public function getTitleForFeed() { 39 return pht( 40 '%s updated images of %s.', 41 $this->renderAuthor(), 42 $this->renderObject()); 43 } 44 45 public function getIcon() { 46 return 'fa-picture-o'; 47 } 48 49 public function getColor() { 50 return PhabricatorTransactions::COLOR_YELLOW; 51 } 52 53 public function mergeTransactions( 54 $object, 55 PhabricatorApplicationTransaction $u, 56 PhabricatorApplicationTransaction $v) { 57 58 $u_phid = $u->getOldValue(); 59 $v_phid = $v->getOldValue(); 60 61 if ($u_phid === $v_phid) { 62 return $v; 63 } 64 65 return null; 66 } 67 68 public function extractFilePHIDs($object, $value) { 69 $editor = $this->getEditor(); 70 71 $file_phid = $editor->loadPholioImage($object, $value) 72 ->getFilePHID(); 73 74 return array($file_phid); 75 } 76 77 public function validateTransactions($object, array $xactions) { 78 $errors = array(); 79 80 $mock_phid = $object->getPHID(); 81 82 $editor = $this->getEditor(); 83 foreach ($xactions as $xaction) { 84 $new_phid = $xaction->getNewValue(); 85 86 try { 87 $new_image = $editor->loadPholioImage($object, $new_phid); 88 } catch (Exception $ex) { 89 $errors[] = $this->newInvalidError( 90 pht( 91 'Unable to load replacement image ("%s"): %s', 92 $new_phid, 93 $ex->getMessage()), 94 $xaction); 95 continue; 96 } 97 98 $old_phid = $new_image->getReplacesImagePHID(); 99 if (!$old_phid) { 100 $errors[] = $this->newInvalidError( 101 pht( 102 'Image ("%s") does not specify which image it replaces.', 103 $new_phid), 104 $xaction); 105 continue; 106 } 107 108 try { 109 $old_image = $editor->loadPholioImage($object, $old_phid); 110 } catch (Exception $ex) { 111 $errors[] = $this->newInvalidError( 112 pht( 113 'Unable to load replaced image ("%s"): %s', 114 $old_phid, 115 $ex->getMessage()), 116 $xaction); 117 continue; 118 } 119 120 if ($old_image->getMockPHID() !== $mock_phid) { 121 $errors[] = $this->newInvalidError( 122 pht( 123 'Replaced image ("%s") belongs to the wrong mock ("%s", expected '. 124 '"%s").', 125 $old_phid, 126 $old_image->getMockPHID(), 127 $mock_phid), 128 $xaction); 129 continue; 130 } 131 132 // TODO: You shouldn't be able to replace an image if it has already 133 // been replaced. 134 135 } 136 137 return $errors; 138 } 139 140}