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

Add PhabricatorSlowvoteQuery

Summary: Ref T603. Ref T2625. Start pushing Slowvote (the greatest app of all time) into the modern era.

Test Plan: Looked at vote detail. Used `V1` and `{V1}` embeds.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T603, T2625

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

+116 -8
+7 -1
src/__phutil_library_map__.php
··· 1532 1532 'PhabricatorSlowvoteOption' => 'applications/slowvote/storage/PhabricatorSlowvoteOption.php', 1533 1533 'PhabricatorSlowvotePoll' => 'applications/slowvote/storage/PhabricatorSlowvotePoll.php', 1534 1534 'PhabricatorSlowvotePollController' => 'applications/slowvote/controller/PhabricatorSlowvotePollController.php', 1535 + 'PhabricatorSlowvoteQuery' => 'applications/slowvote/query/PhabricatorSlowvoteQuery.php', 1535 1536 'PhabricatorSlowvoteVoteController' => 'applications/slowvote/controller/PhabricatorSlowvoteVoteController.php', 1536 1537 'PhabricatorSlug' => 'infrastructure/util/PhabricatorSlug.php', 1537 1538 'PhabricatorSlugTestCase' => 'infrastructure/util/__tests__/PhabricatorSlugTestCase.php', ··· 3483 3484 'PhabricatorSlowvoteDAO' => 'PhabricatorLiskDAO', 3484 3485 'PhabricatorSlowvoteListController' => 'PhabricatorSlowvoteController', 3485 3486 'PhabricatorSlowvoteOption' => 'PhabricatorSlowvoteDAO', 3486 - 'PhabricatorSlowvotePoll' => 'PhabricatorSlowvoteDAO', 3487 + 'PhabricatorSlowvotePoll' => 3488 + array( 3489 + 0 => 'PhabricatorSlowvoteDAO', 3490 + 1 => 'PhabricatorPolicyInterface', 3491 + ), 3487 3492 'PhabricatorSlowvotePollController' => 'PhabricatorSlowvoteController', 3493 + 'PhabricatorSlowvoteQuery' => 'PhabricatorPolicyAwareCursorPagedQuery', 3488 3494 'PhabricatorSlowvoteVoteController' => 'PhabricatorSlowvoteController', 3489 3495 'PhabricatorSlugTestCase' => 'PhabricatorTestCase', 3490 3496 'PhabricatorSortTableExample' => 'PhabricatorUIExample',
+4 -1
src/applications/slowvote/controller/PhabricatorSlowvotePollController.php
··· 18 18 $user = $request->getUser(); 19 19 $viewer_phid = $user->getPHID(); 20 20 21 - $poll = id(new PhabricatorSlowvotePoll())->load($this->id); 21 + $poll = id(new PhabricatorSlowvoteQuery()) 22 + ->setViewer($user) 23 + ->withIDs(array($this->id)) 24 + ->executeOne(); 22 25 if (!$poll) { 23 26 return new Aphront404Response(); 24 27 }
+8 -1
src/applications/slowvote/controller/PhabricatorSlowvoteVoteController.php
··· 16 16 $request = $this->getRequest(); 17 17 $user = $request->getUser(); 18 18 19 - $poll = id(new PhabricatorSlowvotePoll())->load($this->id); 19 + $poll = id(new PhabricatorSlowvoteQuery()) 20 + ->setViewer($user) 21 + ->withIDs(array($this->id)) 22 + ->executeOne(); 23 + if (!$poll) { 24 + return new Aphront404Response(); 25 + } 26 + 20 27 $options = id(new PhabricatorSlowvoteOption())->loadAllWhere( 21 28 'pollID = %d', 22 29 $poll->getID());
+71
src/applications/slowvote/query/PhabricatorSlowvoteQuery.php
··· 1 + <?php 2 + 3 + /** 4 + * @group slowvote 5 + */ 6 + final class PhabricatorSlowvoteQuery 7 + extends PhabricatorCursorPagedPolicyAwareQuery { 8 + 9 + private $ids; 10 + private $phids; 11 + private $authorPHIDs; 12 + 13 + public function withIDs($ids) { 14 + $this->ids = $ids; 15 + return $this; 16 + } 17 + 18 + public function withPHIDs($phids) { 19 + $this->phids = $phids; 20 + return $this; 21 + } 22 + 23 + public function withAuthorPHIDs($author_phids) { 24 + $this->authorPHIDs = $author_phids; 25 + return $this; 26 + } 27 + 28 + public function loadPage() { 29 + $table = new PhabricatorSlowvotePoll(); 30 + $conn_r = $table->establishConnection('r'); 31 + 32 + $data = queryfx_all( 33 + $conn_r, 34 + 'SELECT * FROM %T %Q %Q %Q', 35 + $table->getTableName(), 36 + $this->buildWhereClause($conn_r), 37 + $this->buildOrderClause($conn_r), 38 + $this->buildLimitClause($conn_r)); 39 + 40 + return $table->loadAllFromArray($data); 41 + } 42 + 43 + private function buildWhereClause(AphrontDatabaseConnection $conn_r) { 44 + $where = array(); 45 + 46 + if ($this->ids) { 47 + $where[] = qsprintf( 48 + $conn_r, 49 + 'id IN (%Ld)', 50 + $this->ids); 51 + } 52 + 53 + if ($this->phids) { 54 + $where[] = qsprintf( 55 + $conn_r, 56 + 'phid IN (%Ls)', 57 + $this->phids); 58 + } 59 + 60 + if ($this->authorPHIDs) { 61 + $where[] = qsprintf( 62 + $conn_r, 63 + 'authorPHID IN (%Ls)', 64 + $this->authorPHIDs); 65 + } 66 + 67 + $where[] = $this->buildPagingClause($conn_r); 68 + return $this->formatWhereClause($where); 69 + } 70 + 71 + }
+5 -3
src/applications/slowvote/remarkup/SlowvoteRemarkupRule.php
··· 11 11 } 12 12 13 13 protected function loadObjects(array $ids) { 14 - $polls = array(id(new PhabricatorSlowvotePoll())->load(head($ids))); 14 + $viewer = $this->getEngine()->getConfig('viewer'); 15 15 16 - return id(new PhabricatorSlowvotePoll()) 17 - ->loadAllWhere('id IN (%Ld)', $ids); 16 + return id(new PhabricatorSlowvoteQuery()) 17 + ->setViewer($viewer) 18 + ->withIDs($ids) 19 + ->execute(); 18 20 } 19 21 20 22 protected function renderObjectEmbed($object, $handle, $options) {
+21 -2
src/applications/slowvote/storage/PhabricatorSlowvotePoll.php
··· 3 3 /** 4 4 * @group slowvote 5 5 */ 6 - final class PhabricatorSlowvotePoll extends PhabricatorSlowvoteDAO { 6 + final class PhabricatorSlowvotePoll extends PhabricatorSlowvoteDAO 7 + implements PhabricatorPolicyInterface { 7 8 8 9 const RESPONSES_VISIBLE = 0; 9 10 const RESPONSES_VOTERS = 1; ··· 13 14 const METHOD_APPROVAL = 1; 14 15 15 16 protected $question; 16 - protected $phid; 17 17 protected $authorPHID; 18 18 protected $responseVisibility; 19 19 protected $shuffle; ··· 28 28 public function generatePHID() { 29 29 return PhabricatorPHID::generateNewPHID( 30 30 PhabricatorPHIDConstants::PHID_TYPE_POLL); 31 + } 32 + 33 + 34 + /* -( PhabricatorPolicyInterface )----------------------------------------- */ 35 + 36 + 37 + public function getCapabilities() { 38 + return array( 39 + PhabricatorPolicyCapability::CAN_VIEW, 40 + PhabricatorPolicyCapability::CAN_EDIT, 41 + ); 42 + } 43 + 44 + public function getPolicy($capability) { 45 + return PhabricatorPolicies::POLICY_USER; 46 + } 47 + 48 + public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { 49 + return ($viewer->getPHID() == $this->getAuthorPHID()); 31 50 } 32 51 33 52 }