Differential D15063 Diff 36373 src/applications/project/editor/PhabricatorProjectTransactionEditor.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/project/editor/PhabricatorProjectTransactionEditor.php
Show First 20 Lines • Show All 182 Lines • ▼ Show 20 Lines | protected function applyBuiltinExternalTransaction( | ||||
PhabricatorApplicationTransaction $xaction) { | PhabricatorApplicationTransaction $xaction) { | ||||
switch ($xaction->getTransactionType()) { | switch ($xaction->getTransactionType()) { | ||||
case PhabricatorTransactions::TYPE_EDGE: | case PhabricatorTransactions::TYPE_EDGE: | ||||
$edge_type = $xaction->getMetadataValue('edge:type'); | $edge_type = $xaction->getMetadataValue('edge:type'); | ||||
switch ($edge_type) { | switch ($edge_type) { | ||||
case PhabricatorProjectProjectHasMemberEdgeType::EDGECONST: | case PhabricatorProjectProjectHasMemberEdgeType::EDGECONST: | ||||
case PhabricatorObjectHasWatcherEdgeType::EDGECONST: | case PhabricatorObjectHasWatcherEdgeType::EDGECONST: | ||||
$edge_const = PhabricatorProjectProjectHasMemberEdgeType::EDGECONST; | |||||
if ($edge_type != $edge_const) { | |||||
break; | |||||
} | |||||
$old = $xaction->getOldValue(); | $old = $xaction->getOldValue(); | ||||
$new = $xaction->getNewValue(); | $new = $xaction->getNewValue(); | ||||
// When adding members or watchers, we add subscriptions. | // When adding members, we add subscriptions. When removing | ||||
// members, we remove subscriptions. | |||||
$add = array_keys(array_diff_key($new, $old)); | $add = array_keys(array_diff_key($new, $old)); | ||||
// When removing members, we remove their subscription too. | |||||
// When unwatching, we leave subscriptions, since it's fine to be | |||||
// subscribed to a project but not be a member of it. | |||||
$edge_const = PhabricatorProjectProjectHasMemberEdgeType::EDGECONST; | |||||
if ($edge_type == $edge_const) { | |||||
$rem = array_keys(array_diff_key($old, $new)); | $rem = array_keys(array_diff_key($old, $new)); | ||||
} else { | |||||
$rem = array(); | |||||
} | |||||
// NOTE: The subscribe is "explicit" because there's no implicit | // NOTE: The subscribe is "explicit" because there's no implicit | ||||
// unsubscribe, so Join -> Leave -> Join doesn't resubscribe you | // unsubscribe, so Join -> Leave -> Join doesn't resubscribe you | ||||
// if we use an implicit subscribe, even though you never willfully | // if we use an implicit subscribe, even though you never willfully | ||||
// unsubscribed. Not sure if adding implicit unsubscribe (which | // unsubscribed. Not sure if adding implicit unsubscribe (which | ||||
// would not write the unsubscribe row) is justified to deal with | // would not write the unsubscribe row) is justified to deal with | ||||
// this, which is a fairly weird edge case and pretty arguable both | // this, which is a fairly weird edge case and pretty arguable both | ||||
// ways. | // ways. | ||||
// Subscriptions caused by watches should also clearly be explicit, | |||||
// and that case is unambiguous. | |||||
id(new PhabricatorSubscriptionsEditor()) | id(new PhabricatorSubscriptionsEditor()) | ||||
->setActor($this->requireActor()) | ->setActor($this->requireActor()) | ||||
->setObject($object) | ->setObject($object) | ||||
->subscribeExplicit($add) | ->subscribeExplicit($add) | ||||
->unsubscribe($rem) | ->unsubscribe($rem) | ||||
->save(); | ->save(); | ||||
if ($rem) { | |||||
// When removing members, also remove any watches on the project. | |||||
$edge_editor = new PhabricatorEdgeEditor(); | |||||
foreach ($rem as $rem_phid) { | |||||
$edge_editor->removeEdge( | |||||
$object->getPHID(), | |||||
PhabricatorObjectHasWatcherEdgeType::EDGECONST, | |||||
$rem_phid); | |||||
} | |||||
$edge_editor->save(); | |||||
} | |||||
break; | break; | ||||
} | } | ||||
break; | break; | ||||
} | } | ||||
return parent::applyBuiltinExternalTransaction($object, $xaction); | return parent::applyBuiltinExternalTransaction($object, $xaction); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 692 Lines • Show Last 20 Lines |