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

Methods for reading reviewers from edges in differential

Summary: Add `getReviewerStatus` to get an array of `DifferentialReviewer` objects. The method `needReviewerStatus` in `DifferentialRevisionQuery` loads the edges into the revisions loaded.

Test Plan: Added `->needReviewerStatus(true)` to `DifferentialRevisionSearchEngine` and checked through logging that the data was being loaded correctly.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

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

authored by

Juan Pablo Civile and committed by
epriestley
d4c28dcb 1b48e922

+105
+1
src/__phutil_library_map__.php
··· 395 395 'DifferentialRevertPlanFieldSpecification' => 'applications/differential/field/specification/DifferentialRevertPlanFieldSpecification.php', 396 396 'DifferentialReviewRequestMail' => 'applications/differential/mail/DifferentialReviewRequestMail.php', 397 397 'DifferentialReviewedByFieldSpecification' => 'applications/differential/field/specification/DifferentialReviewedByFieldSpecification.php', 398 + 'DifferentialReviewer' => 'applications/differential/storage/DifferentialReviewer.php', 398 399 'DifferentialReviewerStatus' => 'applications/differential/constants/DifferentialReviewerStatus.php', 399 400 'DifferentialReviewersFieldSpecification' => 'applications/differential/field/specification/DifferentialReviewersFieldSpecification.php', 400 401 'DifferentialRevision' => 'applications/differential/storage/DifferentialRevision.php',
+49
src/applications/differential/query/DifferentialRevisionQuery.php
··· 56 56 private $needDiffIDs = false; 57 57 private $needCommitPHIDs = false; 58 58 private $needHashes = false; 59 + private $needReviewerStatus = false; 59 60 60 61 private $buildingGlobalOrder; 61 62 ··· 326 327 } 327 328 328 329 330 + /** 331 + * Set whether or not the query should load associated reviewer status. 332 + * 333 + * @param bool True to load and attach reviewers. 334 + * @return this 335 + * @task config 336 + */ 337 + public function needReviewerStatus($need_reviewer_status) { 338 + $this->needReviewerStatus = $need_reviewer_status; 339 + return $this; 340 + } 341 + 342 + 329 343 /* -( Query Execution )---------------------------------------------------- */ 330 344 331 345 ··· 374 388 375 389 if ($this->needHashes) { 376 390 $this->loadHashes($conn_r, $revisions); 391 + } 392 + 393 + if ($this->needReviewerStatus) { 394 + $this->loadReviewers($conn_r, $revisions); 377 395 } 378 396 379 397 return $revisions; ··· 902 920 $revision->attachHashes($list); 903 921 } 904 922 } 923 + 924 + private function loadReviewers( 925 + AphrontDatabaseConnection $conn_r, 926 + array $revisions) { 927 + 928 + assert_instances_of($revisions, 'DifferentialRevision'); 929 + $edge_type = PhabricatorEdgeConfig::TYPE_DREV_HAS_REVIEWER; 930 + 931 + $edges = id(new PhabricatorEdgeQuery()) 932 + ->withSourcePHIDs(mpull($revisions, 'getPHID')) 933 + ->withEdgeTypes(array($edge_type)) 934 + ->needEdgeData(true) 935 + ->execute(); 936 + 937 + foreach ($revisions as $revision) { 938 + $revision_edges = $edges[$revision->getPHID()][$edge_type]; 939 + 940 + $reviewers = array(); 941 + foreach ($revision_edges as $user_phid => $edge) { 942 + $data = $edge['data']; 943 + $reviewers[] = new DifferentialReviewer( 944 + $user_phid, $data['status'], idx($data, 'diff', null) 945 + ); 946 + } 947 + 948 + $revision->attachReviewerStatus($reviewers); 949 + } 950 + 951 + } 952 + 953 + 905 954 906 955 public static function splitResponsible(array $revisions, array $user_phids) { 907 956 $blocking = array();
+39
src/applications/differential/storage/DifferentialReviewer.php
··· 1 + <?php 2 + 3 + final class DifferentialReviewer { 4 + 5 + protected $reviewerPHID; 6 + protected $status; 7 + protected $diffID; 8 + 9 + public function __construct($reviewer_phid, $status, $diff_id = null) { 10 + $this->reviewerPHID = $reviewer_phid; 11 + $this->setStatus($status, $diff_id); 12 + } 13 + 14 + public function getReviewerPHID() { 15 + return $this->reviewerPHID; 16 + } 17 + 18 + public function getStatus() { 19 + return $this->status; 20 + } 21 + 22 + public function getDiffID() { 23 + return $this->diffID; 24 + } 25 + 26 + public function setStatus($status, $diff_id = null) { 27 + if ($status == DifferentialReviewerStatus::STATUS_REJECTED 28 + && $diff_id === null) { 29 + 30 + throw new Exception('STATUS_REJECTED must have a diff_id set'); 31 + } 32 + 33 + $this->status = $status; 34 + $this->diffID = $diff_id; 35 + 36 + return $this; 37 + } 38 + 39 + }
+16
src/applications/differential/storage/DifferentialRevision.php
··· 32 32 private $diffIDs; 33 33 private $hashes; 34 34 35 + private $reviewerStatus; 35 36 36 37 const RELATIONSHIP_TABLE = 'differential_relationship'; 37 38 const TABLE_COMMIT = 'differential_commit'; ··· 335 336 ); 336 337 } 337 338 339 + public function getReviewerStatus() { 340 + if ($this->reviewerStatus === null) { 341 + throw new Exception( 342 + "Call attachReviewerStatus() before getReviewerStatus()!" 343 + ); 344 + } 345 + return $this->reviewerStatus; 346 + } 347 + 348 + public function attachReviewerStatus(array $reviewers) { 349 + assert_instances_of($reviewers, 'DifferentialReviewer'); 350 + 351 + $this->reviewerStatus = $reviewers; 352 + return $this; 353 + } 338 354 }