mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-02 19:01:03 +01:00
Differential Revision relationships
This commit is contained in:
parent
de1fb8ac7d
commit
63c842105c
5 changed files with 192 additions and 42 deletions
|
@ -308,12 +308,10 @@ class DifferentialRevisionEditor {
|
||||||
$stable[$key] = array_diff_key($old[$key], $add[$key] + $rem[$key]);
|
$stable[$key] = array_diff_key($old[$key], $add[$key] + $rem[$key]);
|
||||||
}
|
}
|
||||||
|
|
||||||
self::removeReviewers(
|
self::alterReviewers(
|
||||||
$revision,
|
$revision,
|
||||||
|
$this->reviewers,
|
||||||
array_keys($rem['rev']),
|
array_keys($rem['rev']),
|
||||||
$this->actorPHID);
|
|
||||||
self::addReviewers(
|
|
||||||
$revision,
|
|
||||||
array_keys($add['rev']),
|
array_keys($add['rev']),
|
||||||
$this->actorPHID);
|
$this->actorPHID);
|
||||||
|
|
||||||
|
@ -493,42 +491,93 @@ class DifferentialRevisionEditor {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static function addReviewers(
|
public static function alterReviewers(
|
||||||
DifferentialRevision $revision,
|
DifferentialRevision $revision,
|
||||||
array $reviewer_ids,
|
array $stable_phids,
|
||||||
|
array $rem_phids,
|
||||||
|
array $add_phids,
|
||||||
$reason_phid) {
|
$reason_phid) {
|
||||||
/*
|
|
||||||
foreach ($reviewer_ids as $reviewer_id) {
|
|
||||||
$relationship = new DifferentialRelationship();
|
|
||||||
$relationship->setRevisionID($revision->getID());
|
|
||||||
$relationship->setRelatedPHID($reviewer_id);
|
|
||||||
$relationship->setForbidden(false);
|
|
||||||
$relationship->setReasonPHID($reason_phid);
|
|
||||||
$relationship->setRelation(DifferentialRelationship::RELATION_REVIEWER);
|
|
||||||
$relationship->replace();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function removeReviewers(
|
$rem_map = array_fill_keys($rem_phids, true);
|
||||||
DifferentialRevision $revision,
|
$add_map = array_fill_keys($add_phids, true);
|
||||||
array $reviewer_ids,
|
|
||||||
$reason_phid) {
|
$seq_map = array_values($stable_phids);
|
||||||
/*
|
$seq_map = array_flip($seq_map);
|
||||||
if (!$reviewer_ids) {
|
foreach ($rem_map as $phid => $ignored) {
|
||||||
return;
|
if (!isset($seq_map[$phid])) {
|
||||||
|
$seq_map[$phid] = count($seq_map);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach ($add_map as $phid => $ignored) {
|
||||||
|
if (!isset($seq_map[$phid])) {
|
||||||
|
$seq_map[$phid] = count($seq_map);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($reviewer_ids as $reviewer_id) {
|
$raw = $revision->getRawRelations(DifferentialRevision::RELATION_REVIEWER);
|
||||||
$relationship = new DifferentialRelationship();
|
$raw = ipull($raw, 'objectPHID');
|
||||||
$relationship->setRevisionID($revision->getID());
|
|
||||||
$relationship->setRelatedPHID($reviewer_id);
|
$sequence = count($seq_map);
|
||||||
$relationship->setForbidden(true);
|
foreach ($raw as $phid => $relation) {
|
||||||
$relationship->setReasonPHID($reason_phid);
|
if (isset($seq_map[$phid])) {
|
||||||
$relationship->setRelation(DifferentialRelationship::RELATION_REVIEWER);
|
$raw[$phid]['sequence'] = $seq_map[$phid];
|
||||||
$relationship->replace();
|
} else {
|
||||||
|
$raw[$phid]['sequence'] = $sequence++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
*/
|
$raw = isort($raw, 'sequence');
|
||||||
|
|
||||||
|
foreach ($raw as $phid => $relation) {
|
||||||
|
if (isset($rem_map[$phid])) {
|
||||||
|
$relation['forbidden'] = true;
|
||||||
|
$relation['reasonPHID'] = $reason_phid;
|
||||||
|
} else if (isset($add_map[$phid])) {
|
||||||
|
$relation['forbidden'] = false;
|
||||||
|
$relation['reasonPHID'] = $reason_phid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($add_phids as $add) {
|
||||||
|
$raw[] = array(
|
||||||
|
'objectPHID' => $add,
|
||||||
|
'forbidden' => false,
|
||||||
|
'sequence' => idx($seq_map, $add, $sequence++),
|
||||||
|
'reasonPHID' => $reason_phid,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$conn_w = $revision->establishConnection('w');
|
||||||
|
|
||||||
|
$sql = array();
|
||||||
|
foreach ($raw as $relation) {
|
||||||
|
$sql[] = qsprintf(
|
||||||
|
$conn_w,
|
||||||
|
'(%d, %s, %s, %d, %d, %s)',
|
||||||
|
$revision->getID(),
|
||||||
|
DifferentialRevision::RELATION_REVIEWER,
|
||||||
|
$relation['objectPHID'],
|
||||||
|
$relation['forbidden'],
|
||||||
|
$relation['sequence'],
|
||||||
|
$relation['reasonPHID']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$conn_w->openTransaction();
|
||||||
|
queryfx(
|
||||||
|
$conn_w,
|
||||||
|
'DELETE FROM %T WHERE revisionID = %d AND relation = %s',
|
||||||
|
DifferentialRevision::RELATIONSHIP_TABLE,
|
||||||
|
$revision->getID(),
|
||||||
|
DifferentialRevision::RELATION_REVIEWER);
|
||||||
|
if ($sql) {
|
||||||
|
queryfx(
|
||||||
|
$conn_w,
|
||||||
|
'INSERT INTO %T
|
||||||
|
(revisionID, relation, objectPHID, forbidden, sequence, reasonPHID)
|
||||||
|
VALUES %Q',
|
||||||
|
DifferentialRevision::RELATIONSHIP_TABLE,
|
||||||
|
implode(', ', $sql));
|
||||||
|
}
|
||||||
|
$conn_w->saveTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -10,6 +10,9 @@ phutil_require_module('phabricator', 'applications/differential/constants/revisi
|
||||||
phutil_require_module('phabricator', 'applications/differential/mail/ccwelcome');
|
phutil_require_module('phabricator', 'applications/differential/mail/ccwelcome');
|
||||||
phutil_require_module('phabricator', 'applications/differential/mail/newdiff');
|
phutil_require_module('phabricator', 'applications/differential/mail/newdiff');
|
||||||
phutil_require_module('phabricator', 'applications/differential/storage/changeset');
|
phutil_require_module('phabricator', 'applications/differential/storage/changeset');
|
||||||
|
phutil_require_module('phabricator', 'applications/differential/storage/revision');
|
||||||
|
phutil_require_module('phabricator', 'storage/qsprintf');
|
||||||
|
phutil_require_module('phabricator', 'storage/queryfx');
|
||||||
|
|
||||||
phutil_require_module('phutil', 'utils');
|
phutil_require_module('phutil', 'utils');
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,15 @@ class DifferentialRevision extends DifferentialDAO {
|
||||||
protected $dateCommitted;
|
protected $dateCommitted;
|
||||||
|
|
||||||
protected $lineCount;
|
protected $lineCount;
|
||||||
|
|
||||||
|
private $related;
|
||||||
|
private $forbidden;
|
||||||
|
|
||||||
|
const RELATIONSHIP_TABLE = 'differential_relationship';
|
||||||
|
|
||||||
|
const RELATION_REVIEWER = 'revw';
|
||||||
|
const RELATION_SUBSCRIBED = 'subd';
|
||||||
|
|
||||||
public function getConfiguration() {
|
public function getConfiguration() {
|
||||||
return array(
|
return array(
|
||||||
self::CONFIG_AUX_PHID => true,
|
self::CONFIG_AUX_PHID => true,
|
||||||
|
@ -42,17 +50,102 @@ class DifferentialRevision extends DifferentialDAO {
|
||||||
public function generatePHID() {
|
public function generatePHID() {
|
||||||
return PhabricatorPHID::generateNewPHID('DREV');
|
return PhabricatorPHID::generateNewPHID('DREV');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadRelationships() {
|
public function loadRelationships() {
|
||||||
|
if (!$this->getID()) {
|
||||||
|
$this->relationships = array();
|
||||||
|
$this->related = array();
|
||||||
|
$this->forbidden = array();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = queryfx_all(
|
||||||
|
$this->establishConnection('r'),
|
||||||
|
'SELECT * FROM %T WHERE revisionID = %d ORDER BY sequence',
|
||||||
|
self::RELATIONSHIP_TABLE,
|
||||||
|
$this->getID());
|
||||||
|
|
||||||
|
$related = array();
|
||||||
|
$forbidden = array();
|
||||||
|
|
||||||
|
foreach ($data as $row) {
|
||||||
|
if ($row['forbidden']) {
|
||||||
|
$forbidden[] = $row;
|
||||||
|
} else {
|
||||||
|
$related[] = $row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->related = igroup($related, 'relation');
|
||||||
|
$this->forbidden = igroup($related, 'relation');
|
||||||
|
$this->relationships = igroup($data, 'relation');
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getReviewers() {
|
public function getReviewers() {
|
||||||
return array();
|
return $this->getRelatedPHIDs(self::RELATION_REVIEWER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCCPHIDs() {
|
public function getCCPHIDs() {
|
||||||
return array();
|
return $this->getRelatedPHIDs(self::RELATION_SUBSCRIBED);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getRelatedPHIDs($relation) {
|
||||||
|
if ($this->related === null) {
|
||||||
|
throw new Exception("Must load relationships!");
|
||||||
|
}
|
||||||
|
|
||||||
|
$related = idx($this->related, $relation, array());
|
||||||
|
|
||||||
|
return ipull($related, 'objectPHID');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRawRelations($relation) {
|
||||||
|
return idx($this->relationships, $relation, array());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function writeRelatedPHIDs(
|
||||||
|
$relation,
|
||||||
|
$phids,
|
||||||
|
$reason_phid,
|
||||||
|
$forbidden) {
|
||||||
|
|
||||||
|
$conn_w = $this->establishConnection('w');
|
||||||
|
|
||||||
|
$sql = array();
|
||||||
|
$phids = array_values($phids);
|
||||||
|
foreach ($phids as $key => $phid) {
|
||||||
|
$sql[] = qsprintf(
|
||||||
|
$conn_w,
|
||||||
|
'(%d, %s, %d, %s, %d)',
|
||||||
|
$this->getRevisionID(),
|
||||||
|
$phid,
|
||||||
|
$key,
|
||||||
|
$reason_phid,
|
||||||
|
$forbidden);
|
||||||
|
}
|
||||||
|
|
||||||
|
$conn_w->openTransaction();
|
||||||
|
queryfx(
|
||||||
|
$conn_w,
|
||||||
|
'DELETE FROM %T WHERE revisionID = %d AND relation = %s
|
||||||
|
AND forbidden = %d
|
||||||
|
AND relatedPHID NOT IN (%Ls)',
|
||||||
|
self::RELATIONSHIP_TABLE,
|
||||||
|
$this->getID(),
|
||||||
|
$relation,
|
||||||
|
$forbidden,
|
||||||
|
$phids);
|
||||||
|
queryfx(
|
||||||
|
$conn_w,
|
||||||
|
'INSERT INTO %T
|
||||||
|
(revisionID, relatedPHID, sequence, reason_phid, forbidden)
|
||||||
|
VALUES %Q
|
||||||
|
ON DUPLICATE KEY UPDATE sequence = VALUES(sequence)',
|
||||||
|
self::RELATIONSHIP_TABLE,
|
||||||
|
implode(', ', $sql));
|
||||||
|
$conn_w->saveTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,11 @@
|
||||||
|
|
||||||
|
|
||||||
phutil_require_module('phabricator', 'applications/differential/storage/base');
|
phutil_require_module('phabricator', 'applications/differential/storage/base');
|
||||||
|
phutil_require_module('phabricator', 'applications/phid/storage/phid');
|
||||||
|
phutil_require_module('phabricator', 'storage/qsprintf');
|
||||||
|
phutil_require_module('phabricator', 'storage/queryfx');
|
||||||
|
|
||||||
|
phutil_require_module('phutil', 'utils');
|
||||||
|
|
||||||
|
|
||||||
phutil_require_source('DifferentialRevision.php');
|
phutil_require_source('DifferentialRevision.php');
|
||||||
|
|
|
@ -107,7 +107,7 @@ abstract class AphrontDatabaseConnection {
|
||||||
self::$transactionShutdownRegistered = true;
|
self::$transactionShutdownRegistered = true;
|
||||||
register_shutdown_function(
|
register_shutdown_function(
|
||||||
array(
|
array(
|
||||||
'LiskConnection',
|
'AphrontDatabaseConnection',
|
||||||
'shutdownTransactionStacks',
|
'shutdownTransactionStacks',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue