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

Move slowvote loading logic into Query class

Summary: Mostly straightforward. Also fixed a couple of error/darkconsole things.

Test Plan:
- Created poll;
- viewed poll;
- voted in poll;
- used `V6` and `{V6}` markup styles in poll.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

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

+158 -23
+4
src/aphront/configuration/AphrontDefaultApplicationConfiguration.php
··· 121 121 122 122 // For non-workflow requests, return a Ajax response. 123 123 if ($request->isAjax() && !$request->isJavelinWorkflow()) { 124 + // Log these; they don't get shown on the client and can be difficult 125 + // to debug. 126 + phlog($ex); 127 + 124 128 $response = new AphrontAjaxResponse(); 125 129 $response->setError( 126 130 array(
+17 -1
src/aphront/console/DarkConsoleCore.php
··· 58 58 'name' => $plugin->getName(), 59 59 'color' => $plugin->getColor(), 60 60 ); 61 - $data[$class] = $plugin->getData(); 61 + $data[$class] = $this->sanitizeForJSON($plugin->getData()); 62 62 } 63 63 64 64 $storage = array( ··· 105 105 'data-console-color' => $this->getColor(), 106 106 ), 107 107 ''); 108 + } 109 + 110 + /** 111 + * Sometimes, tab data includes binary information (like INSERT queries which 112 + * write file data into the database). To successfully JSON encode it, we 113 + * need to convert it to UTF-8. 114 + */ 115 + private function sanitizeForJSON($data) { 116 + if (is_array($data)) { 117 + foreach ($data as $key => $value) { 118 + $data[$key] = $this->sanitizeForJSON($value); 119 + } 120 + return $data; 121 + } else { 122 + return phutil_utf8ize($data); 123 + } 108 124 } 109 125 110 126 }
+4 -6
src/applications/slowvote/controller/PhabricatorSlowvotePollController.php
··· 21 21 $poll = id(new PhabricatorSlowvoteQuery()) 22 22 ->setViewer($user) 23 23 ->withIDs(array($this->id)) 24 + ->needOptions(true) 25 + ->needChoices(true) 24 26 ->executeOne(); 25 27 if (!$poll) { 26 28 return new Aphront404Response(); 27 29 } 28 30 29 - $options = id(new PhabricatorSlowvoteOption())->loadAllWhere( 30 - 'pollID = %d', 31 - $poll->getID()); 32 - $choices = id(new PhabricatorSlowvoteChoice())->loadAllWhere( 33 - 'pollID = %d', 34 - $poll->getID()); 31 + $options = $poll->getOptions(); 32 + $choices = $poll->getChoices(); 35 33 36 34 $choices_by_option = mgroup($choices, 'getOptionID'); 37 35 $choices_by_user = mgroup($choices, 'getAuthorPHID');
+4 -7
src/applications/slowvote/controller/PhabricatorSlowvoteVoteController.php
··· 19 19 $poll = id(new PhabricatorSlowvoteQuery()) 20 20 ->setViewer($user) 21 21 ->withIDs(array($this->id)) 22 + ->needOptions(true) 23 + ->needViewerChoices(true) 22 24 ->executeOne(); 23 25 if (!$poll) { 24 26 return new Aphront404Response(); 25 27 } 26 28 27 - $options = id(new PhabricatorSlowvoteOption())->loadAllWhere( 28 - 'pollID = %d', 29 - $poll->getID()); 30 - $user_choices = id(new PhabricatorSlowvoteChoice())->loadAllWhere( 31 - 'pollID = %d AND authorPHID = %s', 32 - $poll->getID(), 33 - $user->getPHID()); 29 + $options = $poll->getOptions(); 30 + $user_choices = $poll->getViewerChoices($user); 34 31 35 32 $old_votes = mpull($user_choices, null, 'getOptionID'); 36 33
+79
src/applications/slowvote/query/PhabricatorSlowvoteQuery.php
··· 11 11 private $authorPHIDs; 12 12 private $withVotesByViewer; 13 13 14 + private $needOptions; 15 + private $needChoices; 16 + private $needViewerChoices; 17 + 14 18 public function withIDs($ids) { 15 19 $this->ids = $ids; 16 20 return $this; ··· 31 35 return $this; 32 36 } 33 37 38 + public function needOptions($need_options) { 39 + $this->needOptions = $need_options; 40 + return $this; 41 + } 42 + 43 + public function needChoices($need_choices) { 44 + $this->needChoices = $need_choices; 45 + return $this; 46 + } 47 + 48 + public function needViewerChoices($need_viewer_choices) { 49 + $this->needViewerChoices = $need_viewer_choices; 50 + return $this; 51 + } 52 + 34 53 public function loadPage() { 35 54 $table = new PhabricatorSlowvotePoll(); 36 55 $conn_r = $table->establishConnection('r'); ··· 45 64 $this->buildLimitClause($conn_r)); 46 65 47 66 return $table->loadAllFromArray($data); 67 + } 68 + 69 + public function willFilterPage(array $polls) { 70 + assert_instances_of($polls, 'PhabricatorSlowvotePoll'); 71 + 72 + if (!$polls) { 73 + return array(); 74 + } 75 + 76 + $ids = mpull($polls, 'getID'); 77 + $viewer = $this->getViewer(); 78 + 79 + if ($this->needOptions) { 80 + $options = id(new PhabricatorSlowvoteOption())->loadAllWhere( 81 + 'pollID IN (%Ld)', 82 + $ids); 83 + 84 + $options = mgroup($options, 'getPollID'); 85 + foreach ($polls as $poll) { 86 + $poll->attachOptions(idx($options, $poll->getID(), array())); 87 + } 88 + } 89 + 90 + if ($this->needChoices) { 91 + $choices = id(new PhabricatorSlowvoteChoice())->loadAllWhere( 92 + 'pollID IN (%Ld)', 93 + $ids); 94 + 95 + $choices = mgroup($choices, 'getPollID'); 96 + foreach ($polls as $poll) { 97 + $poll->attachChoices(idx($choices, $poll->getID(), array())); 98 + } 99 + 100 + // If we need the viewer's choices, we can just fill them from the data 101 + // we already loaded. 102 + if ($this->needViewerChoices) { 103 + foreach ($polls as $poll) { 104 + $poll->attachViewerChoices( 105 + $viewer, 106 + idx( 107 + mgroup($poll->getChoices(), 'getAuthorPHID'), 108 + $viewer->getPHID(), 109 + array())); 110 + } 111 + } 112 + } else if ($this->needViewerChoices) { 113 + $choices = id(new PhabricatorSlowvoteChoice())->loadAllWhere( 114 + 'pollID IN (%Ld) AND authorPHID = %s', 115 + $ids, 116 + $viewer->getPHID()); 117 + 118 + $choices = mgroup($choices, 'getPollID'); 119 + foreach ($polls as $poll) { 120 + $poll->attachViewerChoices( 121 + $viewer, 122 + idx($choices, $poll->getID(), array())); 123 + } 124 + } 125 + 126 + return $polls; 48 127 } 49 128 50 129 private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
+6 -9
src/applications/slowvote/remarkup/SlowvoteRemarkupRule.php
··· 16 16 return id(new PhabricatorSlowvoteQuery()) 17 17 ->setViewer($viewer) 18 18 ->withIDs($ids) 19 + ->needOptions(true) 20 + ->needChoices(true) 21 + ->needViewerChoices(true) 19 22 ->execute(); 20 23 } 21 24 22 25 protected function renderObjectEmbed($object, $handle, $options) { 23 26 $viewer = $this->getEngine()->getConfig('viewer'); 24 27 25 - $options = id(new PhabricatorSlowvoteOption())->loadAllWhere( 26 - 'pollID = %d', 27 - $object->getID()); 28 - $choices = id(new PhabricatorSlowvoteChoice())->loadAllWhere( 29 - 'pollID = %d', 30 - $object->getID()); 31 - $choices_by_user = mgroup($choices, 'getAuthorPHID'); 32 - 33 - $viewer_choices = idx($choices_by_user, $viewer->getPHID(), array()); 28 + $options = $object->getOptions(); 29 + $choices = $object->getChoices(); 30 + $viewer_choices = $object->getViewerChoices($viewer); 34 31 35 32 $embed = id(new SlowvoteEmbedView()) 36 33 ->setPoll($object)
+44
src/applications/slowvote/storage/PhabricatorSlowvotePoll.php
··· 23 23 protected $method; 24 24 protected $viewPolicy; 25 25 26 + private $options; 27 + private $choices; 28 + private $viewerChoices = array(); 29 + 26 30 public function getConfiguration() { 27 31 return array( 28 32 self::CONFIG_AUX_PHID => true, ··· 32 36 public function generatePHID() { 33 37 return PhabricatorPHID::generateNewPHID( 34 38 PhabricatorPHIDConstants::PHID_TYPE_POLL); 39 + } 40 + 41 + public function getOptions() { 42 + if ($this->options === null) { 43 + throw new Exception("Call attachOptions() before getOptions()!"); 44 + } 45 + return $this->options; 46 + } 47 + 48 + public function attachOptions(array $options) { 49 + assert_instances_of($options, 'PhabricatorSlowvoteOption'); 50 + $this->options = $options; 51 + return $this; 52 + } 53 + 54 + public function getChoices() { 55 + if ($this->choices === null) { 56 + throw new Exception("Call attachChoices() before getChoices()!"); 57 + } 58 + return $this->choices; 59 + } 60 + 61 + public function attachChoices(array $choices) { 62 + assert_instances_of($choices, 'PhabricatorSlowvoteChoice'); 63 + $this->choices = $choices; 64 + return $this; 65 + } 66 + 67 + public function getViewerChoices(PhabricatorUser $viewer) { 68 + if (idx($this->viewerChoices, $viewer->getPHID()) === null) { 69 + throw new Exception( 70 + "Call attachViewerChoices() before getViewerChoices()!"); 71 + } 72 + return idx($this->viewerChoices, $viewer->getPHID()); 73 + } 74 + 75 + public function attachViewerChoices(PhabricatorUser $viewer, array $choices) { 76 + assert_instances_of($choices, 'PhabricatorSlowvoteOption'); 77 + $this->viewerChoices[$viewer->getPHID()] = $choices; 78 + return $this; 35 79 } 36 80 37 81