diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index a8bce64d08..4e0a23a68a 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -395,6 +395,7 @@ phutil_register_library_map(array( 'DifferentialRevertPlanFieldSpecification' => 'applications/differential/field/specification/DifferentialRevertPlanFieldSpecification.php', 'DifferentialReviewRequestMail' => 'applications/differential/mail/DifferentialReviewRequestMail.php', 'DifferentialReviewedByFieldSpecification' => 'applications/differential/field/specification/DifferentialReviewedByFieldSpecification.php', + 'DifferentialReviewer' => 'applications/differential/storage/DifferentialReviewer.php', 'DifferentialReviewerStatus' => 'applications/differential/constants/DifferentialReviewerStatus.php', 'DifferentialReviewersFieldSpecification' => 'applications/differential/field/specification/DifferentialReviewersFieldSpecification.php', 'DifferentialRevision' => 'applications/differential/storage/DifferentialRevision.php', diff --git a/src/applications/differential/query/DifferentialRevisionQuery.php b/src/applications/differential/query/DifferentialRevisionQuery.php index 77108e8b0d..0434734112 100644 --- a/src/applications/differential/query/DifferentialRevisionQuery.php +++ b/src/applications/differential/query/DifferentialRevisionQuery.php @@ -56,6 +56,7 @@ final class DifferentialRevisionQuery private $needDiffIDs = false; private $needCommitPHIDs = false; private $needHashes = false; + private $needReviewerStatus = false; private $buildingGlobalOrder; @@ -326,6 +327,19 @@ final class DifferentialRevisionQuery } + /** + * Set whether or not the query should load associated reviewer status. + * + * @param bool True to load and attach reviewers. + * @return this + * @task config + */ + public function needReviewerStatus($need_reviewer_status) { + $this->needReviewerStatus = $need_reviewer_status; + return $this; + } + + /* -( Query Execution )---------------------------------------------------- */ @@ -376,6 +390,10 @@ final class DifferentialRevisionQuery $this->loadHashes($conn_r, $revisions); } + if ($this->needReviewerStatus) { + $this->loadReviewers($conn_r, $revisions); + } + return $revisions; } @@ -903,6 +921,37 @@ final class DifferentialRevisionQuery } } + private function loadReviewers( + AphrontDatabaseConnection $conn_r, + array $revisions) { + + assert_instances_of($revisions, 'DifferentialRevision'); + $edge_type = PhabricatorEdgeConfig::TYPE_DREV_HAS_REVIEWER; + + $edges = id(new PhabricatorEdgeQuery()) + ->withSourcePHIDs(mpull($revisions, 'getPHID')) + ->withEdgeTypes(array($edge_type)) + ->needEdgeData(true) + ->execute(); + + foreach ($revisions as $revision) { + $revision_edges = $edges[$revision->getPHID()][$edge_type]; + + $reviewers = array(); + foreach ($revision_edges as $user_phid => $edge) { + $data = $edge['data']; + $reviewers[] = new DifferentialReviewer( + $user_phid, $data['status'], idx($data, 'diff', null) + ); + } + + $revision->attachReviewerStatus($reviewers); + } + + } + + + public static function splitResponsible(array $revisions, array $user_phids) { $blocking = array(); $active = array(); diff --git a/src/applications/differential/storage/DifferentialReviewer.php b/src/applications/differential/storage/DifferentialReviewer.php new file mode 100644 index 0000000000..142db9c38a --- /dev/null +++ b/src/applications/differential/storage/DifferentialReviewer.php @@ -0,0 +1,39 @@ +reviewerPHID = $reviewer_phid; + $this->setStatus($status, $diff_id); + } + + public function getReviewerPHID() { + return $this->reviewerPHID; + } + + public function getStatus() { + return $this->status; + } + + public function getDiffID() { + return $this->diffID; + } + + public function setStatus($status, $diff_id = null) { + if ($status == DifferentialReviewerStatus::STATUS_REJECTED + && $diff_id === null) { + + throw new Exception('STATUS_REJECTED must have a diff_id set'); + } + + $this->status = $status; + $this->diffID = $diff_id; + + return $this; + } + +} diff --git a/src/applications/differential/storage/DifferentialRevision.php b/src/applications/differential/storage/DifferentialRevision.php index ae2edafb18..58f38457ed 100644 --- a/src/applications/differential/storage/DifferentialRevision.php +++ b/src/applications/differential/storage/DifferentialRevision.php @@ -32,6 +32,7 @@ final class DifferentialRevision extends DifferentialDAO private $diffIDs; private $hashes; + private $reviewerStatus; const RELATIONSHIP_TABLE = 'differential_relationship'; const TABLE_COMMIT = 'differential_commit'; @@ -335,4 +336,19 @@ final class DifferentialRevision extends DifferentialDAO ); } + public function getReviewerStatus() { + if ($this->reviewerStatus === null) { + throw new Exception( + "Call attachReviewerStatus() before getReviewerStatus()!" + ); + } + return $this->reviewerStatus; + } + + public function attachReviewerStatus(array $reviewers) { + assert_instances_of($reviewers, 'DifferentialReviewer'); + + $this->reviewerStatus = $reviewers; + return $this; + } }