Differential D17495 Diff 42073 src/applications/differential/xaction/DifferentialRevisionReviewersTransaction.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/xaction/DifferentialRevisionReviewersTransaction.php
Show First 20 Lines • Show All 100 Lines • ▼ Show 20 Lines | public function getTransactionHasEffect($object, $old, $new) { | ||||
ksort($old); | ksort($old); | ||||
ksort($new); | ksort($new); | ||||
return ($old !== $new); | return ($old !== $new); | ||||
} | } | ||||
public function applyExternalEffects($object, $value) { | public function applyExternalEffects($object, $value) { | ||||
$src_phid = $object->getPHID(); | $src_phid = $object->getPHID(); | ||||
// This is currently double-writing: to the old (edge) store and the new | |||||
// (reviewer) store. Do the old edge write first. | |||||
$old = $this->generateOldValue($object); | $old = $this->generateOldValue($object); | ||||
$new = $value; | $new = $value; | ||||
$edge_type = DifferentialRevisionHasReviewerEdgeType::EDGECONST; | $edge_type = DifferentialRevisionHasReviewerEdgeType::EDGECONST; | ||||
$editor = new PhabricatorEdgeEditor(); | $editor = new PhabricatorEdgeEditor(); | ||||
$rem = array_diff_key($old, $new); | $rem = array_diff_key($old, $new); | ||||
foreach ($rem as $dst_phid => $status) { | foreach ($rem as $dst_phid => $status) { | ||||
Show All 16 Lines | foreach ($new as $dst_phid => $status) { | ||||
'diffID' => null, | 'diffID' => null, | ||||
), | ), | ||||
); | ); | ||||
$editor->addEdge($src_phid, $edge_type, $dst_phid, $data); | $editor->addEdge($src_phid, $edge_type, $dst_phid, $data); | ||||
} | } | ||||
$editor->save(); | $editor->save(); | ||||
// Now, do the new write. | |||||
$table = new DifferentialReviewer(); | |||||
$table_name = $table->getTableName(); | |||||
$conn = $table->establishConnection('w'); | |||||
if ($rem) { | |||||
queryfx( | |||||
$conn, | |||||
'DELETE FROM %T WHERE revisionPHID = %s AND reviewerPHID IN (%Ls)', | |||||
$table_name, | |||||
$src_phid, | |||||
array_keys($rem)); | |||||
} | |||||
if ($new) { | |||||
$reviewers = $table->loadAllWhere( | |||||
'revisionPHID = %s AND reviewerPHID IN (%Ls)', | |||||
$src_phid, | |||||
array_keys($new)); | |||||
$reviewers = mpull($reviewers, null, 'getReviewerPHID'); | |||||
foreach ($new as $dst_phid => $status) { | |||||
$old_status = idx($old, $dst_phid); | |||||
if ($old_status === $status) { | |||||
continue; | |||||
} | |||||
$reviewer = idx($reviewers, $dst_phid); | |||||
if (!$reviewer) { | |||||
$reviewer = id(new DifferentialReviewer()) | |||||
->setRevisionPHID($src_phid) | |||||
->setReviewerPHID($dst_phid); | |||||
} | |||||
$reviewer->setReviewerStatus($status); | |||||
try { | |||||
$reviewer->save(); | |||||
} catch (AphrontDuplicateKeyQueryException $ex) { | |||||
// At least for now, just ignore it if we lost a race. | |||||
} | |||||
} | |||||
} | |||||
} | } | ||||
public function getTitle() { | public function getTitle() { | ||||
return $this->renderReviewerEditTitle(false); | return $this->renderReviewerEditTitle(false); | ||||
} | } | ||||
public function getTitleForFeed() { | public function getTitleForFeed() { | ||||
return $this->renderReviewerEditTitle(true); | return $this->renderReviewerEditTitle(true); | ||||
▲ Show 20 Lines • Show All 226 Lines • Show Last 20 Lines |