@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.

Implement Pholio file add/remove transactions without "applyInitialEffects"

Summary:
Depends on D19924. Ref T11351. Like in D19924, apply these transactions by accepting PHIDs instead of objects so we don't need to juggle the `Image` objects down to PHIDs in `applyInitialEffects`.

(Validation is a little light here for now, but only first-party code can reach this, and you can't violate policies or do anything truly bad even if you could pick values to feed in here.)

Test Plan: Created and edited Mocks; added, removed, and reordered images in a Pholio Mock.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T11351

Differential Revision: https://secure.phabricator.com/D19926

+41 -93
+5 -3
src/applications/pholio/controller/PholioMockEditController.php
··· 162 162 ->attachFile($file) 163 163 ->setName(strlen($title) ? $title : $file->getName()) 164 164 ->setDescription($description) 165 - ->setSequence($sequence); 165 + ->setSequence($sequence) 166 + ->save(); 167 + 166 168 $xactions[] = id(new PholioTransaction()) 167 169 ->setTransactionType(PholioImageFileTransaction::TRANSACTIONTYPE) 168 170 ->setNewValue( 169 - array('+' => array($add_image))); 171 + array('+' => array($add_image->getPHID()))); 170 172 $posted_mock_images[] = $add_image; 171 173 } else { 172 174 $xactions[] = id(new PholioTransaction()) ··· 193 195 $xactions[] = id(new PholioTransaction()) 194 196 ->setTransactionType(PholioImageFileTransaction::TRANSACTIONTYPE) 195 197 ->setNewValue( 196 - array('-' => array($mock_image))); 198 + array('-' => array($mock_image->getPHID()))); 197 199 } 198 200 } 199 201
+3 -65
src/applications/pholio/editor/PholioMockEditor.php
··· 2 2 3 3 final class PholioMockEditor extends PhabricatorApplicationTransactionEditor { 4 4 5 - private $newImages = array(); 6 - 7 5 private $images = array(); 8 6 9 7 public function getEditorApplicationClass() { ··· 14 12 return pht('Pholio Mocks'); 15 13 } 16 14 17 - private function setNewImages(array $new_images) { 18 - assert_instances_of($new_images, 'PholioImage'); 19 - $this->newImages = $new_images; 20 - return $this; 21 - } 22 - 23 - public function getNewImages() { 24 - return $this->newImages; 25 - } 26 - 27 15 public function getCreateObjectTitle($author, $object) { 28 16 return pht('%s created this mock.', $author); 29 17 } ··· 43 31 return $types; 44 32 } 45 33 46 - protected function shouldApplyInitialEffects( 47 - PhabricatorLiskDAO $object, 48 - array $xactions) { 49 - 50 - foreach ($xactions as $xaction) { 51 - switch ($xaction->getTransactionType()) { 52 - case PholioImageFileTransaction::TRANSACTIONTYPE: 53 - return true; 54 - } 55 - } 56 - return false; 57 - } 58 - 59 - protected function applyInitialEffects( 60 - PhabricatorLiskDAO $object, 61 - array $xactions) { 62 - 63 - $new_images = array(); 64 - foreach ($xactions as $xaction) { 65 - switch ($xaction->getTransactionType()) { 66 - case PholioImageFileTransaction::TRANSACTIONTYPE: 67 - $new_value = $xaction->getNewValue(); 68 - foreach ($new_value as $key => $txn_images) { 69 - if ($key != '+') { 70 - continue; 71 - } 72 - foreach ($txn_images as $image) { 73 - $image->save(); 74 - $new_images[] = $image; 75 - } 76 - } 77 - break; 78 - } 79 - } 80 - $this->setNewImages($new_images); 81 - } 82 - 83 - protected function applyFinalEffects( 84 - PhabricatorLiskDAO $object, 85 - array $xactions) { 86 - 87 - $images = $this->getNewImages(); 88 - foreach ($images as $image) { 89 - $image->setMockPHID($object->getPHID()); 90 - $image->save(); 91 - } 92 - 93 - return $xactions; 94 - } 95 - 96 34 protected function shouldSendMail( 97 35 PhabricatorLiskDAO $object, 98 36 array $xactions) { ··· 105 43 } 106 44 107 45 protected function buildMailTemplate(PhabricatorLiskDAO $object) { 108 - $id = $object->getID(); 46 + $monogram = $object->getMonogram(); 109 47 $name = $object->getName(); 110 48 111 49 return id(new PhabricatorMetaMTAMail()) 112 - ->setSubject("M{$id}: {$name}"); 50 + ->setSubject("{$monogram}: {$name}"); 113 51 } 114 52 115 53 protected function getMailTo(PhabricatorLiskDAO $object) { ··· 150 88 151 89 $body->addLinkSection( 152 90 pht('MOCK DETAIL'), 153 - PhabricatorEnv::getProductionURI('/M'.$object->getID())); 91 + PhabricatorEnv::getProductionURI($object->getURI())); 154 92 155 93 return $body; 156 94 }
+33 -25
src/applications/pholio/xaction/PholioImageFileTransaction.php
··· 11 11 } 12 12 13 13 public function generateNewValue($object, $value) { 14 - $new_value = array(); 15 - foreach ($value as $key => $images) { 16 - $new_value[$key] = mpull($images, 'getPHID'); 17 - } 18 - $old = array_fuse($this->getOldValue()); 19 - return $this->getEditor()->getPHIDList($old, $new_value); 14 + $editor = $this->getEditor(); 15 + 16 + $old_value = $this->getOldValue(); 17 + $new_value = $value; 18 + 19 + return $editor->getPHIDList($old_value, $new_value); 20 20 } 21 21 22 - public function applyInternalEffects($object, $value) { 22 + public function applyExternalEffects($object, $value) { 23 23 $old_map = array_fuse($this->getOldValue()); 24 24 $new_map = array_fuse($this->getNewValue()); 25 25 26 - $obsolete_map = array_diff_key($old_map, $new_map); 27 - $images = $object->getActiveImages(); 28 - foreach ($images as $seq => $image) { 29 - if (isset($obsolete_map[$image->getPHID()])) { 30 - $image->setIsObsolete(1); 31 - $image->save(); 32 - unset($images[$seq]); 33 - } 26 + $add_map = array_diff_key($new_map, $old_map); 27 + $rem_map = array_diff_key($old_map, $new_map); 28 + 29 + $editor = $this->getEditor(); 30 + 31 + foreach ($rem_map as $phid) { 32 + $editor->loadPholioImage($object, $phid) 33 + ->setIsObsolete(1) 34 + ->save(); 35 + } 36 + 37 + foreach ($add_map as $phid) { 38 + $editor->loadPholioImage($object, $phid) 39 + ->setMockPHID($object->getPHID()) 40 + ->save(); 34 41 } 35 - $object->attachImages($images); 36 42 } 37 43 38 44 public function getTitle() { ··· 95 101 } 96 102 97 103 public function extractFilePHIDs($object, $value) { 98 - $images = $this->getEditor()->getNewImages(); 99 - $images = mpull($images, null, 'getPHID'); 104 + $editor = $this->getEditor(); 100 105 106 + // NOTE: This method is a little weird (and includes ALL the file PHIDs, 107 + // including old file PHIDs) because we currently don't have a storage 108 + // object when called. This might change at some point. 109 + 110 + $new_phids = $value; 101 111 102 112 $file_phids = array(); 103 - foreach ($value as $image_phid) { 104 - $image = idx($images, $image_phid); 105 - if (!$image) { 106 - continue; 107 - } 108 - $file_phids[] = $image->getFilePHID(); 113 + foreach ($new_phids as $phid) { 114 + $file_phids[] = $editor->loadPholioImage($object, $phid) 115 + ->getFilePHID(); 109 116 } 117 + 110 118 return $file_phids; 111 119 } 112 120 ··· 114 122 $object, 115 123 PhabricatorApplicationTransaction $u, 116 124 PhabricatorApplicationTransaction $v) { 117 - return $this->getEditor()->mergePHIDOrEdgeTransactions($u, $v); 125 + return $this->getEditor()->mergePHIDOrEdgeTransactions($u, $v); 118 126 } 119 127 120 128 }