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

Surface token counts for Pholio

Summary: Provide this data so the list view can present it somehow.

Test Plan: {F34520}

Reviewers: chad

Reviewed By: chad

CC: aran

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

+99 -18
+2
src/__phutil_library_map__.php
··· 1343 1343 'PhabricatorToken' => 'applications/tokens/storage/PhabricatorToken.php', 1344 1344 'PhabricatorTokenController' => 'applications/tokens/controller/PhabricatorTokenController.php', 1345 1345 'PhabricatorTokenCount' => 'applications/tokens/storage/PhabricatorTokenCount.php', 1346 + 'PhabricatorTokenCountQuery' => 'applications/tokens/query/PhabricatorTokenCountQuery.php', 1346 1347 'PhabricatorTokenDAO' => 'applications/tokens/storage/PhabricatorTokenDAO.php', 1347 1348 'PhabricatorTokenGiveController' => 'applications/tokens/controller/PhabricatorTokenGiveController.php', 1348 1349 'PhabricatorTokenGiven' => 'applications/tokens/storage/PhabricatorTokenGiven.php', ··· 2813 2814 ), 2814 2815 'PhabricatorTokenController' => 'PhabricatorController', 2815 2816 'PhabricatorTokenCount' => 'PhabricatorTokenDAO', 2817 + 'PhabricatorTokenCountQuery' => 'PhabricatorOffsetPagedQuery', 2816 2818 'PhabricatorTokenDAO' => 'PhabricatorLiskDAO', 2817 2819 'PhabricatorTokenGiveController' => 'PhabricatorTokenController', 2818 2820 'PhabricatorTokenGiven' =>
+3 -1
src/applications/pholio/controller/PholioMockListController.php
··· 18 18 19 19 $query = id(new PholioMockQuery()) 20 20 ->setViewer($user) 21 - ->needCoverFiles(true); 21 + ->needCoverFiles(true) 22 + ->needTokenCounts(true); 22 23 23 24 $nav = $this->buildSideNav(); 24 25 $filter = $nav->selectFilter('view/'.$this->view, 'view/all'); ··· 65 66 'div', 66 67 array(), 67 68 pht('Created on %s', $datetime))); 69 + 68 70 $board->addItem($item); 69 71 } 70 72
+41 -17
src/applications/pholio/query/PholioMockQuery.php
··· 13 13 private $needCoverFiles; 14 14 private $needImages; 15 15 private $needInlineComments; 16 + private $needTokenCounts; 16 17 17 18 public function withIDs(array $ids) { 18 19 $this->ids = $ids; ··· 29 30 return $this; 30 31 } 31 32 33 + public function needCoverFiles($need_cover_files) { 34 + $this->needCoverFiles = $need_cover_files; 35 + return $this; 36 + } 37 + 38 + public function needImages($need_images) { 39 + $this->needImages = $need_images; 40 + return $this; 41 + } 42 + 43 + public function needInlineComments($need_inline_comments) { 44 + $this->needInlineComments = $need_inline_comments; 45 + return $this; 46 + } 47 + 48 + public function needTokenCounts($need) { 49 + $this->needTokenCounts = $need; 50 + return $this; 51 + } 52 + 32 53 public function loadPage() { 33 54 $table = new PholioMock(); 34 55 $conn_r = $table->establishConnection('r'); ··· 46 67 if ($mocks && $this->needImages) { 47 68 $this->loadImages($mocks); 48 69 } 70 + 49 71 if ($mocks && $this->needCoverFiles) { 50 72 $this->loadCoverFiles($mocks); 51 73 } 52 74 75 + if ($mocks && $this->needTokenCounts) { 76 + $this->loadTokenCounts($mocks); 77 + } 53 78 54 79 return $mocks; 55 80 } ··· 83 108 return $this->formatWhereClause($where); 84 109 } 85 110 86 - public function needCoverFiles($need_cover_files) { 87 - $this->needCoverFiles = $need_cover_files; 88 - return $this; 89 - } 90 - 91 - public function needImages($need_images) { 92 - $this->needImages = $need_images; 93 - return $this; 94 - } 95 - 96 - public function needInlineComments($need_inline_comments) { 97 - $this->needInlineComments = $need_inline_comments; 98 - return $this; 99 - } 100 - 101 - public function loadImages(array $mocks) { 111 + private function loadImages(array $mocks) { 102 112 assert_instances_of($mocks, 'PholioMock'); 103 113 104 114 $mock_ids = mpull($mocks, 'getID'); ··· 133 143 } 134 144 } 135 145 136 - public function loadCoverFiles(array $mocks) { 146 + private function loadCoverFiles(array $mocks) { 137 147 assert_instances_of($mocks, 'PholioMock'); 138 148 $cover_file_phids = mpull($mocks, 'getCoverPHID'); 139 149 $cover_files = mpull(id(new PhabricatorFile())->loadAllWhere( ··· 144 154 $mock->attachCoverFile($cover_files[$mock->getCoverPHID()]); 145 155 } 146 156 } 157 + 158 + private function loadTokenCounts(array $mocks) { 159 + assert_instances_of($mocks, 'PholioMock'); 160 + 161 + $phids = mpull($mocks, 'getPHID'); 162 + $counts = id(new PhabricatorTokenCountQuery()) 163 + ->withObjectPHIDs($phids) 164 + ->execute(); 165 + 166 + foreach ($mocks as $mock) { 167 + $mock->attachTokenCount(idx($counts, $mock->getPHID(), 0)); 168 + } 169 + } 170 + 147 171 }
+13
src/applications/pholio/storage/PholioMock.php
··· 24 24 25 25 private $images; 26 26 private $coverFile; 27 + private $tokenCount; 27 28 28 29 public function getConfiguration() { 29 30 return array( ··· 65 66 throw new Exception("Call attachCoverFile() before getCoverFile()!"); 66 67 } 67 68 return $this->coverFile; 69 + } 70 + 71 + public function getTokenCount() { 72 + if ($this->tokenCount === null) { 73 + throw new Exception("Call attachTokenCount() before getTokenCount()!"); 74 + } 75 + return $this->tokenCount; 76 + } 77 + 78 + public function attachTokenCount($count) { 79 + $this->tokenCount = $count; 80 + return $this; 68 81 } 69 82 70 83
+40
src/applications/tokens/query/PhabricatorTokenCountQuery.php
··· 1 + <?php 2 + 3 + final class PhabricatorTokenCountQuery 4 + extends PhabricatorOffsetPagedQuery { 5 + 6 + private $objectPHIDs; 7 + 8 + public function withObjectPHIDs(array $object_phids) { 9 + $this->objectPHIDs = $object_phids; 10 + return $this; 11 + } 12 + 13 + final public function execute() { 14 + $table = new PhabricatorTokenCount(); 15 + $conn_r = $table->establishConnection('r'); 16 + 17 + $rows = queryfx_all( 18 + $conn_r, 19 + 'SELECT objectPHID, tokenCount FROM %T %Q %Q', 20 + $table->getTableName(), 21 + $this->buildWhereClause($conn_r), 22 + $this->buildLimitClause($conn_r)); 23 + 24 + return ipull($rows, 'tokenCount', 'objectPHID'); 25 + } 26 + 27 + private function buildWhereClause(AphrontDatabaseConnection $conn_r) { 28 + $where = array(); 29 + 30 + if ($this->objectPHIDs) { 31 + $where[] = qsprintf( 32 + $conn_r, 33 + 'objectPHID IN (%Ls)', 34 + $this->objectPHIDs); 35 + } 36 + 37 + return $this->formatWhereClause($where); 38 + } 39 + 40 + }