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

Make the Pholio Mock "getImages" / "getAllImages" API more clear

Summary:
Depends on D19920. Ref T11351. Currently, "images" and "all images" are attached to Mocks separately, and `getImages()` gets you only some images.

Clean this up slightly:

- One attach method; attach everything.
- Two getters, one for "images" (returns all images); one for "active images" (returns active images).

Test Plan: Browsed around Pholio without any apparent behavioral changes.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T11351

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

+30 -38
+2 -2
src/applications/pholio/controller/PholioMockCommentController.php
··· 24 24 25 25 $draft = PhabricatorDraft::buildFromRequest($request); 26 26 27 - $mock_uri = '/M'.$mock->getID(); 27 + $mock_uri = $mock->getURI(); 28 28 29 29 $comment = $request->getStr('comment'); 30 30 ··· 33 33 $inline_comments = id(new PholioTransactionComment())->loadAllWhere( 34 34 'authorphid = %s AND transactionphid IS NULL AND imageid IN (%Ld)', 35 35 $viewer->getPHID(), 36 - mpull($mock->getImages(), 'getID')); 36 + mpull($mock->getActiveImages(), 'getID')); 37 37 38 38 if (!$inline_comments || strlen($comment)) { 39 39 $xactions[] = id(new PholioTransaction())
+1 -1
src/applications/pholio/controller/PholioMockEditController.php
··· 25 25 $title = pht('Edit Mock: %s', $mock->getName()); 26 26 27 27 $is_new = false; 28 - $mock_images = $mock->getImages(); 28 + $mock_images = $mock->getActiveImages(); 29 29 $files = mpull($mock_images, 'getFile'); 30 30 $mock_images = mpull($mock_images, null, 'getFilePHID'); 31 31 } else {
+2 -4
src/applications/pholio/query/PholioMockQuery.php
··· 58 58 } 59 59 60 60 protected function loadPage() { 61 - $mocks = $this->loadStandardPage(new PholioMock()); 61 + $mocks = $this->loadStandardPage($this->newResultObject()); 62 62 63 63 if ($mocks && $this->needImages) { 64 64 self::loadImages($this->getViewer(), $mocks, $this->needInlineComments); ··· 127 127 128 128 foreach ($mocks as $mock) { 129 129 $mock_images = idx($image_groups, $mock->getPHID(), array()); 130 - $mock->attachAllImages($mock_images); 131 - $active_images = mfilter($mock_images, 'getIsObsolete', true); 132 - $mock->attachImages(msort($active_images, 'getSequence')); 130 + $mock->attachImages($mock_images); 133 131 } 134 132 } 135 133
+1 -1
src/applications/pholio/query/PholioMockSearchEngine.php
··· 111 111 ->setImageURI($image_uri) 112 112 ->setImageSize($x, $y) 113 113 ->setDisabled($mock->isClosed()) 114 - ->addIconCount('fa-picture-o', count($mock->getImages())) 114 + ->addIconCount('fa-picture-o', count($mock->getActiveImages())) 115 115 ->addIconCount('fa-trophy', $mock->getTokenCount()); 116 116 117 117 if ($mock->getAuthorPHID()) {
+13 -19
src/applications/pholio/storage/PholioMock.php
··· 30 30 protected $spacePHID; 31 31 32 32 private $images = self::ATTACHABLE; 33 - private $allImages = self::ATTACHABLE; 34 33 private $coverFile = self::ATTACHABLE; 35 34 private $tokenCount = self::ATTACHABLE; 36 35 ··· 93 92 return parent::save(); 94 93 } 95 94 96 - /** 97 - * These should be the images currently associated with the Mock. 98 - */ 99 95 public function attachImages(array $images) { 100 96 assert_instances_of($images, 'PholioImage'); 97 + $images = mpull($images, null, 'getPHID'); 98 + $images = msort($images, 'getSequence'); 101 99 $this->images = $images; 102 100 return $this; 103 101 } 104 102 105 103 public function getImages() { 106 - $this->assertAttached($this->images); 107 - return $this->images; 104 + return $this->assertAttached($this->images); 108 105 } 109 106 110 - /** 111 - * These should be *all* images associated with the Mock. This includes 112 - * images which have been removed and / or replaced from the Mock. 113 - */ 114 - public function attachAllImages(array $images) { 115 - assert_instances_of($images, 'PholioImage'); 116 - $this->allImages = $images; 117 - return $this; 118 - } 107 + public function getActiveImages() { 108 + $images = $this->getImages(); 109 + 110 + foreach ($images as $phid => $image) { 111 + if ($image->getIsObsolete()) { 112 + unset($images[$phid]); 113 + } 114 + } 119 115 120 - public function getAllImages() { 121 - $this->assertAttached($this->images); 122 - return $this->allImages; 116 + return $images; 123 117 } 124 118 125 119 public function attachCoverFile(PhabricatorFile $file) { ··· 143 137 } 144 138 145 139 public function getImageHistorySet($image_id) { 146 - $images = $this->getAllImages(); 140 + $images = $this->getImages(); 147 141 $images = mpull($images, null, 'getID'); 148 142 $selected_image = $images[$image_id]; 149 143
+2 -2
src/applications/pholio/view/PholioMockEmbedView.php
··· 25 25 $thumbnail = null; 26 26 if (!empty($this->images)) { 27 27 $images_to_show = array_intersect_key( 28 - $this->mock->getImages(), array_flip($this->images)); 28 + $this->mock->getActiveImages(), array_flip($this->images)); 29 29 } 30 30 31 31 $xform = PhabricatorFileTransform::getTransformByKey( ··· 54 54 ->setImageURI($thumbnail) 55 55 ->setImageSize($x, $y) 56 56 ->setDisabled($mock->isClosed()) 57 - ->addIconCount('fa-picture-o', count($mock->getImages())) 57 + ->addIconCount('fa-picture-o', count($mock->getActiveImages())) 58 58 ->addIconCount('fa-trophy', $mock->getTokenCount()); 59 59 60 60 return $item;
+3 -3
src/applications/pholio/view/PholioMockImagesView.php
··· 74 74 75 75 $images = array(); 76 76 $current_set = 0; 77 - foreach ($mock->getAllImages() as $image) { 77 + foreach ($mock->getImages() as $image) { 78 78 $file = $image->getFile(); 79 79 $metadata = $file->getMetadata(); 80 80 $x = idx($metadata, PhabricatorFile::METADATA_IMAGE_WIDTH); ··· 110 110 ); 111 111 } 112 112 113 - $ids = mpull($mock->getImages(), 'getID'); 113 + $ids = mpull($mock->getActiveImages(), 'getID'); 114 114 if ($this->imageID && isset($ids[$this->imageID])) { 115 115 $selected_id = $this->imageID; 116 116 } else { ··· 118 118 } 119 119 120 120 $navsequence = array(); 121 - foreach ($mock->getImages() as $image) { 121 + foreach ($mock->getActiveImages() as $image) { 122 122 $navsequence[] = $image->getID(); 123 123 } 124 124
+3 -3
src/applications/pholio/view/PholioMockThumbGridView.php
··· 12 12 public function render() { 13 13 $mock = $this->mock; 14 14 15 - $all_images = $mock->getAllImages(); 15 + $all_images = $mock->getImages(); 16 16 $all_images = mpull($all_images, null, 'getPHID'); 17 17 18 18 $history = mpull($all_images, 'getReplacesImagePHID', 'getPHID'); ··· 25 25 } 26 26 27 27 // Figure out the columns. Start with all the active images. 28 - $images = mpull($mock->getImages(), null, 'getPHID'); 28 + $images = mpull($mock->getActiveImages(), null, 'getPHID'); 29 29 30 30 // Now, find deleted images: obsolete images which were not replaced. 31 - foreach ($mock->getAllImages() as $image) { 31 + foreach ($mock->getImages() as $image) { 32 32 if (!$image->getIsObsolete()) { 33 33 // Image is current. 34 34 continue;
+1 -1
src/applications/pholio/view/PholioTransactionView.php
··· 97 97 private function renderInlineContent(PholioTransaction $inline) { 98 98 $comment = $inline->getComment(); 99 99 $mock = $this->getMock(); 100 - $images = $mock->getAllImages(); 100 + $images = $mock->getImages(); 101 101 $images = mpull($images, null, 'getID'); 102 102 103 103 $image = idx($images, $comment->getImageID());
+2 -2
src/applications/pholio/xaction/PholioImageFileTransaction.php
··· 6 6 const TRANSACTIONTYPE = 'image-file'; 7 7 8 8 public function generateOldValue($object) { 9 - $images = $object->getImages(); 9 + $images = $object->getActiveImages(); 10 10 return array_values(mpull($images, 'getPHID')); 11 11 } 12 12 ··· 24 24 $new_map = array_fuse($this->getNewValue()); 25 25 26 26 $obsolete_map = array_diff_key($old_map, $new_map); 27 - $images = $object->getImages(); 27 + $images = $object->getActiveImages(); 28 28 foreach ($images as $seq => $image) { 29 29 if (isset($obsolete_map[$image->getPHID()])) { 30 30 $image->setIsObsolete(1);