Differential D19184 Diff 45951 src/applications/owners/xaction/PhabricatorOwnersPackagePathsTransaction.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/owners/xaction/PhabricatorOwnersPackagePathsTransaction.php
Show First 20 Lines • Show All 97 Lines • ▼ Show 20 Lines | final class PhabricatorOwnersPackagePathsTransaction | ||||
} | } | ||||
public function applyExternalEffects($object, $value) { | public function applyExternalEffects($object, $value) { | ||||
$old = $this->generateOldValue($object); | $old = $this->generateOldValue($object); | ||||
$new = $value; | $new = $value; | ||||
$paths = $object->getPaths(); | $paths = $object->getPaths(); | ||||
// We store paths in a normalized format with a trailing slash, regardless | |||||
// of whether the user enters "path/to/file.c" or "src/backend/". Normalize | |||||
// paths now. | |||||
$display_map = array(); | |||||
foreach ($new as $key => $spec) { | |||||
$display_path = $spec['path']; | |||||
$raw_path = rtrim($display_path, '/').'/'; | |||||
// If the user entered two paths which normalize to the same value | |||||
// (like "src/main.c" and "src/main.c/"), discard the duplicates. | |||||
if (isset($display_map[$raw_path])) { | |||||
unset($new[$key]); | |||||
continue; | |||||
} | |||||
$new[$key]['path'] = $raw_path; | |||||
$display_map[$raw_path] = $display_path; | |||||
} | |||||
$diffs = PhabricatorOwnersPath::getTransactionValueChanges($old, $new); | $diffs = PhabricatorOwnersPath::getTransactionValueChanges($old, $new); | ||||
list($rem, $add) = $diffs; | list($rem, $add) = $diffs; | ||||
$set = PhabricatorOwnersPath::getSetFromTransactionValue($rem); | $set = PhabricatorOwnersPath::getSetFromTransactionValue($rem); | ||||
foreach ($paths as $path) { | foreach ($paths as $path) { | ||||
$ref = $path->getRef(); | $ref = $path->getRef(); | ||||
if (PhabricatorOwnersPath::isRefInSet($ref, $set)) { | if (PhabricatorOwnersPath::isRefInSet($ref, $set)) { | ||||
$path->delete(); | $path->delete(); | ||||
continue; | |||||
} | |||||
// If the user has changed the display value for a path but the raw | |||||
// storage value hasn't changed, update the display value. | |||||
if (isset($display_map[$path->getPath()])) { | |||||
$path | |||||
->setPathDisplay($display_map[$path->getPath()]) | |||||
->save(); | |||||
continue; | |||||
} | } | ||||
} | } | ||||
foreach ($add as $ref) { | foreach ($add as $ref) { | ||||
$path = PhabricatorOwnersPath::newFromRef($ref) | $path = PhabricatorOwnersPath::newFromRef($ref) | ||||
->setPackageID($object->getID()) | ->setPackageID($object->getID()) | ||||
->setPathDisplay($display_map[$ref['path']]) | |||||
->save(); | ->save(); | ||||
} | } | ||||
} | } | ||||
public function getTitle() { | public function getTitle() { | ||||
// TODO: Flesh this out. | // TODO: Flesh this out. | ||||
return pht( | return pht( | ||||
'%s updated paths for this package.', | '%s updated paths for this package.', | ||||
▲ Show 20 Lines • Show All 62 Lines • Show Last 20 Lines |