Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/editor/DifferentialRevisionEditor.php
Show First 20 Lines • Show All 244 Lines • ▼ Show 20 Lines | public function save() { | ||||
$new = array( | $new = array( | ||||
'rev' => array_fill_keys($this->reviewers, true), | 'rev' => array_fill_keys($this->reviewers, true), | ||||
'ccs' => array_fill_keys($this->cc, true), | 'ccs' => array_fill_keys($this->cc, true), | ||||
); | ); | ||||
$rem_ccs = array(); | $rem_ccs = array(); | ||||
$xscript_phid = null; | $xscript_phid = null; | ||||
if ($diff) { | if ($diff) { | ||||
$unsubscribed_phids = PhabricatorEdgeQuery::loadDestinationPHIDs( | |||||
$revision->getPHID(), | |||||
PhabricatorEdgeConfig::TYPE_OBJECT_HAS_UNSUBSCRIBER); | |||||
$adapter = HeraldDifferentialRevisionAdapter::newLegacyAdapter( | $adapter = HeraldDifferentialRevisionAdapter::newLegacyAdapter( | ||||
$revision, | $revision, | ||||
$diff); | $diff); | ||||
$adapter->setExplicitCCs($new['ccs']); | $adapter->setExplicitCCs($new['ccs']); | ||||
$adapter->setExplicitReviewers($new['rev']); | $adapter->setExplicitReviewers($new['rev']); | ||||
$adapter->setForbiddenCCs($revision->loadUnsubscribedPHIDs()); | $adapter->setForbiddenCCs($unsubscribed_phids); | ||||
$adapter->setIsNewObject($is_new); | $adapter->setIsNewObject($is_new); | ||||
$xscript = HeraldEngine::loadAndApplyRules($adapter); | $xscript = HeraldEngine::loadAndApplyRules($adapter); | ||||
$xscript_uri = '/herald/transcript/'.$xscript->getID().'/'; | $xscript_uri = '/herald/transcript/'.$xscript->getID().'/'; | ||||
$xscript_phid = $xscript->getPHID(); | $xscript_phid = $xscript->getPHID(); | ||||
$xscript_header = $xscript->getXHeraldRulesHeader(); | $xscript_header = $xscript->getXHeraldRulesHeader(); | ||||
$xscript_header = HeraldTranscript::saveXHeraldRulesHeader( | $xscript_header = HeraldTranscript::saveXHeraldRulesHeader( | ||||
▲ Show 20 Lines • Show All 325 Lines • ▼ Show 20 Lines | protected static function alterCCs( | ||||
array $stable_phids, | array $stable_phids, | ||||
array $rem_phids, | array $rem_phids, | ||||
array $add_phids, | array $add_phids, | ||||
$reason_phid) { | $reason_phid) { | ||||
$dont_add = self::getImpliedCCs($revision); | $dont_add = self::getImpliedCCs($revision); | ||||
$add_phids = array_diff($add_phids, $dont_add); | $add_phids = array_diff($add_phids, $dont_add); | ||||
return self::alterRelationships( | id(new PhabricatorSubscriptionsEditor()) | ||||
$revision, | ->setActor(PhabricatorUser::getOmnipotentUser()) | ||||
$stable_phids, | ->setObject($revision) | ||||
$rem_phids, | ->subscribeExplicit($add_phids) | ||||
$add_phids, | ->unsubscribe($rem_phids) | ||||
$reason_phid, | ->save(); | ||||
DifferentialRevision::RELATION_SUBSCRIBED); | |||||
} | } | ||||
private static function getImpliedCCs(DifferentialRevision $revision) { | private static function getImpliedCCs(DifferentialRevision $revision) { | ||||
return array_merge( | return array_merge( | ||||
$revision->getReviewers(), | $revision->getReviewers(), | ||||
array($revision->getAuthorPHID())); | array($revision->getAuthorPHID())); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | id(new PhabricatorEdgeEditor()) | ||||
->addEdge( | ->addEdge( | ||||
$revision->getPHID(), | $revision->getPHID(), | ||||
PhabricatorEdgeConfig::TYPE_DREV_HAS_REVIEWER, | PhabricatorEdgeConfig::TYPE_DREV_HAS_REVIEWER, | ||||
$reviewer_phid, | $reviewer_phid, | ||||
$options) | $options) | ||||
->save(); | ->save(); | ||||
} | } | ||||
private static function alterRelationships( | |||||
epriestley: goodbye terrible code
no one will miss you | |||||
DifferentialRevision $revision, | |||||
array $stable_phids, | |||||
array $rem_phids, | |||||
array $add_phids, | |||||
$reason_phid, | |||||
$relation_type) { | |||||
$rem_map = array_fill_keys($rem_phids, true); | |||||
$add_map = array_fill_keys($add_phids, true); | |||||
$seq_map = array_values($stable_phids); | |||||
$seq_map = array_flip($seq_map); | |||||
foreach ($rem_map as $phid => $ignored) { | |||||
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); | |||||
} | |||||
} | |||||
$raw = $revision->getRawRelations($relation_type); | |||||
$raw = ipull($raw, null, 'objectPHID'); | |||||
$sequence = count($seq_map); | |||||
foreach ($raw as $phid => $ignored) { | |||||
if (isset($seq_map[$phid])) { | |||||
$raw[$phid]['sequence'] = $seq_map[$phid]; | |||||
} else { | |||||
$raw[$phid]['sequence'] = $sequence++; | |||||
} | |||||
} | |||||
$raw = isort($raw, 'sequence'); | |||||
foreach ($raw as $phid => $ignored) { | |||||
if (isset($rem_map[$phid])) { | |||||
unset($raw[$phid]); | |||||
} | |||||
} | |||||
foreach ($add_phids as $add) { | |||||
$reason = is_array($reason_phid) | |||||
? idx($reason_phid, $add) | |||||
: $reason_phid; | |||||
$raw[$add] = array( | |||||
'objectPHID' => $add, | |||||
'sequence' => idx($seq_map, $add, $sequence++), | |||||
'reasonPHID' => $reason, | |||||
); | |||||
} | |||||
$conn_w = $revision->establishConnection('w'); | |||||
$sql = array(); | |||||
foreach ($raw as $relation) { | |||||
$sql[] = qsprintf( | |||||
$conn_w, | |||||
'(%d, %s, %s, %d, %s)', | |||||
$revision->getID(), | |||||
$relation_type, | |||||
$relation['objectPHID'], | |||||
$relation['sequence'], | |||||
$relation['reasonPHID']); | |||||
} | |||||
$conn_w->openTransaction(); | |||||
queryfx( | |||||
$conn_w, | |||||
'DELETE FROM %T WHERE revisionID = %d AND relation = %s', | |||||
DifferentialRevision::RELATIONSHIP_TABLE, | |||||
$revision->getID(), | |||||
$relation_type); | |||||
if ($sql) { | |||||
queryfx( | |||||
$conn_w, | |||||
'INSERT INTO %T | |||||
(revisionID, relation, objectPHID, sequence, reasonPHID) | |||||
VALUES %Q', | |||||
DifferentialRevision::RELATIONSHIP_TABLE, | |||||
implode(', ', $sql)); | |||||
} | |||||
$conn_w->saveTransaction(); | |||||
$revision->loadRelationships(); | |||||
} | |||||
private function createComment() { | private function createComment() { | ||||
$template = id(new DifferentialComment()) | $template = id(new DifferentialComment()) | ||||
->setAuthorPHID($this->getActorPHID()) | ->setAuthorPHID($this->getActorPHID()) | ||||
->setRevision($this->revision); | ->setRevision($this->revision); | ||||
if ($this->contentSource) { | if ($this->contentSource) { | ||||
$template->setContentSource($this->contentSource); | $template->setContentSource($this->contentSource); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 322 Lines • Show Last 20 Lines |
goodbye terrible code
no one will miss you