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

Differential Revision relationships

+191 -41
+82 -33
src/applications/differential/editor/revision/DifferentialRevisionEditor.php
··· 308 308 $stable[$key] = array_diff_key($old[$key], $add[$key] + $rem[$key]); 309 309 } 310 310 311 - self::removeReviewers( 311 + self::alterReviewers( 312 312 $revision, 313 + $this->reviewers, 313 314 array_keys($rem['rev']), 314 - $this->actorPHID); 315 - self::addReviewers( 316 - $revision, 317 315 array_keys($add['rev']), 318 316 $this->actorPHID); 319 317 ··· 493 491 } 494 492 495 493 496 - public static function addReviewers( 494 + public static function alterReviewers( 497 495 DifferentialRevision $revision, 498 - array $reviewer_ids, 496 + array $stable_phids, 497 + array $rem_phids, 498 + array $add_phids, 499 499 $reason_phid) { 500 - /* 501 - foreach ($reviewer_ids as $reviewer_id) { 502 - $relationship = new DifferentialRelationship(); 503 - $relationship->setRevisionID($revision->getID()); 504 - $relationship->setRelatedPHID($reviewer_id); 505 - $relationship->setForbidden(false); 506 - $relationship->setReasonPHID($reason_phid); 507 - $relationship->setRelation(DifferentialRelationship::RELATION_REVIEWER); 508 - $relationship->replace(); 500 + 501 + $rem_map = array_fill_keys($rem_phids, true); 502 + $add_map = array_fill_keys($add_phids, true); 503 + 504 + $seq_map = array_values($stable_phids); 505 + $seq_map = array_flip($seq_map); 506 + foreach ($rem_map as $phid => $ignored) { 507 + if (!isset($seq_map[$phid])) { 508 + $seq_map[$phid] = count($seq_map); 509 + } 510 + } 511 + foreach ($add_map as $phid => $ignored) { 512 + if (!isset($seq_map[$phid])) { 513 + $seq_map[$phid] = count($seq_map); 514 + } 515 + } 516 + 517 + $raw = $revision->getRawRelations(DifferentialRevision::RELATION_REVIEWER); 518 + $raw = ipull($raw, 'objectPHID'); 519 + 520 + $sequence = count($seq_map); 521 + foreach ($raw as $phid => $relation) { 522 + if (isset($seq_map[$phid])) { 523 + $raw[$phid]['sequence'] = $seq_map[$phid]; 524 + } else { 525 + $raw[$phid]['sequence'] = $sequence++; 526 + } 527 + } 528 + $raw = isort($raw, 'sequence'); 529 + 530 + foreach ($raw as $phid => $relation) { 531 + if (isset($rem_map[$phid])) { 532 + $relation['forbidden'] = true; 533 + $relation['reasonPHID'] = $reason_phid; 534 + } else if (isset($add_map[$phid])) { 535 + $relation['forbidden'] = false; 536 + $relation['reasonPHID'] = $reason_phid; 537 + } 509 538 } 510 - */ 511 - } 512 539 513 - public static function removeReviewers( 514 - DifferentialRevision $revision, 515 - array $reviewer_ids, 516 - $reason_phid) { 517 - /* 518 - if (!$reviewer_ids) { 519 - return; 540 + foreach ($add_phids as $add) { 541 + $raw[] = array( 542 + 'objectPHID' => $add, 543 + 'forbidden' => false, 544 + 'sequence' => idx($seq_map, $add, $sequence++), 545 + 'reasonPHID' => $reason_phid, 546 + ); 520 547 } 521 548 522 - foreach ($reviewer_ids as $reviewer_id) { 523 - $relationship = new DifferentialRelationship(); 524 - $relationship->setRevisionID($revision->getID()); 525 - $relationship->setRelatedPHID($reviewer_id); 526 - $relationship->setForbidden(true); 527 - $relationship->setReasonPHID($reason_phid); 528 - $relationship->setRelation(DifferentialRelationship::RELATION_REVIEWER); 529 - $relationship->replace(); 549 + $conn_w = $revision->establishConnection('w'); 550 + 551 + $sql = array(); 552 + foreach ($raw as $relation) { 553 + $sql[] = qsprintf( 554 + $conn_w, 555 + '(%d, %s, %s, %d, %d, %s)', 556 + $revision->getID(), 557 + DifferentialRevision::RELATION_REVIEWER, 558 + $relation['objectPHID'], 559 + $relation['forbidden'], 560 + $relation['sequence'], 561 + $relation['reasonPHID']); 530 562 } 531 - */ 563 + 564 + $conn_w->openTransaction(); 565 + queryfx( 566 + $conn_w, 567 + 'DELETE FROM %T WHERE revisionID = %d AND relation = %s', 568 + DifferentialRevision::RELATIONSHIP_TABLE, 569 + $revision->getID(), 570 + DifferentialRevision::RELATION_REVIEWER); 571 + if ($sql) { 572 + queryfx( 573 + $conn_w, 574 + 'INSERT INTO %T 575 + (revisionID, relation, objectPHID, forbidden, sequence, reasonPHID) 576 + VALUES %Q', 577 + DifferentialRevision::RELATIONSHIP_TABLE, 578 + implode(', ', $sql)); 579 + } 580 + $conn_w->saveTransaction(); 532 581 } 533 582 534 583 /*
+3
src/applications/differential/editor/revision/__init__.php
··· 10 10 phutil_require_module('phabricator', 'applications/differential/mail/ccwelcome'); 11 11 phutil_require_module('phabricator', 'applications/differential/mail/newdiff'); 12 12 phutil_require_module('phabricator', 'applications/differential/storage/changeset'); 13 + phutil_require_module('phabricator', 'applications/differential/storage/revision'); 14 + phutil_require_module('phabricator', 'storage/qsprintf'); 15 + phutil_require_module('phabricator', 'storage/queryfx'); 13 16 14 17 phutil_require_module('phutil', 'utils'); 15 18
+100 -7
src/applications/differential/storage/revision/DifferentialRevision.php
··· 32 32 protected $dateCommitted; 33 33 34 34 protected $lineCount; 35 - 35 + 36 + private $related; 37 + private $forbidden; 38 + 39 + const RELATIONSHIP_TABLE = 'differential_relationship'; 40 + 41 + const RELATION_REVIEWER = 'revw'; 42 + const RELATION_SUBSCRIBED = 'subd'; 43 + 36 44 public function getConfiguration() { 37 45 return array( 38 46 self::CONFIG_AUX_PHID => true, ··· 42 50 public function generatePHID() { 43 51 return PhabricatorPHID::generateNewPHID('DREV'); 44 52 } 45 - 53 + 46 54 public function loadRelationships() { 47 - 55 + if (!$this->getID()) { 56 + $this->relationships = array(); 57 + $this->related = array(); 58 + $this->forbidden = array(); 59 + return; 60 + } 61 + 62 + $data = queryfx_all( 63 + $this->establishConnection('r'), 64 + 'SELECT * FROM %T WHERE revisionID = %d ORDER BY sequence', 65 + self::RELATIONSHIP_TABLE, 66 + $this->getID()); 67 + 68 + $related = array(); 69 + $forbidden = array(); 70 + 71 + foreach ($data as $row) { 72 + if ($row['forbidden']) { 73 + $forbidden[] = $row; 74 + } else { 75 + $related[] = $row; 76 + } 77 + } 78 + 79 + $this->related = igroup($related, 'relation'); 80 + $this->forbidden = igroup($related, 'relation'); 81 + $this->relationships = igroup($data, 'relation'); 82 + 83 + return $this; 48 84 } 49 - 85 + 50 86 public function getReviewers() { 51 - return array(); 87 + return $this->getRelatedPHIDs(self::RELATION_REVIEWER); 52 88 } 53 - 89 + 54 90 public function getCCPHIDs() { 55 - return array(); 91 + return $this->getRelatedPHIDs(self::RELATION_SUBSCRIBED); 92 + } 93 + 94 + private function getRelatedPHIDs($relation) { 95 + if ($this->related === null) { 96 + throw new Exception("Must load relationships!"); 97 + } 98 + 99 + $related = idx($this->related, $relation, array()); 100 + 101 + return ipull($related, 'objectPHID'); 102 + } 103 + 104 + public function getRawRelations($relation) { 105 + return idx($this->relationships, $relation, array()); 106 + } 107 + 108 + public function writeRelatedPHIDs( 109 + $relation, 110 + $phids, 111 + $reason_phid, 112 + $forbidden) { 113 + 114 + $conn_w = $this->establishConnection('w'); 115 + 116 + $sql = array(); 117 + $phids = array_values($phids); 118 + foreach ($phids as $key => $phid) { 119 + $sql[] = qsprintf( 120 + $conn_w, 121 + '(%d, %s, %d, %s, %d)', 122 + $this->getRevisionID(), 123 + $phid, 124 + $key, 125 + $reason_phid, 126 + $forbidden); 127 + } 128 + 129 + $conn_w->openTransaction(); 130 + queryfx( 131 + $conn_w, 132 + 'DELETE FROM %T WHERE revisionID = %d AND relation = %s 133 + AND forbidden = %d 134 + AND relatedPHID NOT IN (%Ls)', 135 + self::RELATIONSHIP_TABLE, 136 + $this->getID(), 137 + $relation, 138 + $forbidden, 139 + $phids); 140 + queryfx( 141 + $conn_w, 142 + 'INSERT INTO %T 143 + (revisionID, relatedPHID, sequence, reason_phid, forbidden) 144 + VALUES %Q 145 + ON DUPLICATE KEY UPDATE sequence = VALUES(sequence)', 146 + self::RELATIONSHIP_TABLE, 147 + implode(', ', $sql)); 148 + $conn_w->saveTransaction(); 56 149 } 57 150 58 151 }
+5
src/applications/differential/storage/revision/__init__.php
··· 7 7 8 8 9 9 phutil_require_module('phabricator', 'applications/differential/storage/base'); 10 + phutil_require_module('phabricator', 'applications/phid/storage/phid'); 11 + phutil_require_module('phabricator', 'storage/qsprintf'); 12 + phutil_require_module('phabricator', 'storage/queryfx'); 13 + 14 + phutil_require_module('phutil', 'utils'); 10 15 11 16 12 17 phutil_require_source('DifferentialRevision.php');
+1 -1
src/storage/connection/base/AphrontDatabaseConnection.php
··· 107 107 self::$transactionShutdownRegistered = true; 108 108 register_shutdown_function( 109 109 array( 110 - 'LiskConnection', 110 + 'AphrontDatabaseConnection', 111 111 'shutdownTransactionStacks', 112 112 )); 113 113 }