1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-12 00:26:13 +01:00
phorge-phorge/src/applications/owners/xaction/PhabricatorOwnersPackageOwnersTransaction.php
Mike Riley 8247edff98 Modularize Owners package transactions
Summary: Converts Owners package transactions to modular transactions.

Test Plan:
 - created a new package
 - edited all simple properties from the web ui
 - checked that project and user owners were added as reviewers appropriately to new diffs
 - inspected the change details for various types of path add / remove / update / reorder changes

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin, epriestley

Differential Revision: https://secure.phabricator.com/D16651
2016-10-13 21:07:02 +00:00

76 lines
1.9 KiB
PHP

<?php
final class PhabricatorOwnersPackageOwnersTransaction
extends PhabricatorOwnersPackageTransactionType {
const TRANSACTIONTYPE = 'owners.owners';
public function generateOldValue($object) {
$phids = mpull($object->getOwners(), 'getUserPHID');
$phids = array_values($phids);
return $phids;
}
public function generateNewValue($object, $value) {
$phids = array_unique($value);
$phids = array_values($phids);
return $phids;
}
public function applyExternalEffects($object, $value) {
$old = $this->generateOldValue($object);
$new = $value;
$owners = $object->getOwners();
$owners = mpull($owners, null, 'getUserPHID');
$rem = array_diff($old, $new);
foreach ($rem as $phid) {
if (isset($owners[$phid])) {
$owners[$phid]->delete();
unset($owners[$phid]);
}
}
$add = array_diff($new, $old);
foreach ($add as $phid) {
$owners[$phid] = id(new PhabricatorOwnersOwner())
->setPackageID($object->getID())
->setUserPHID($phid)
->save();
}
// TODO: Attach owners here
}
public function getTitle() {
$old = $this->getOldValue();
$new = $this->getNewValue();
$add = array_diff($new, $old);
$rem = array_diff($old, $new);
if ($add && !$rem) {
return pht(
'%s added %s owner(s): %s.',
$this->renderAuthor(),
count($add),
$this->renderHandleList($add));
} else if ($rem && !$add) {
return pht(
'%s removed %s owner(s): %s.',
$this->renderAuthor(),
count($rem),
$this->renderHandleList($rem));
} else {
return pht(
'%s changed %s package owner(s), added %s: %s; removed %s: %s.',
$this->renderAuthor(),
count($add) + count($rem),
count($add),
$this->renderHandleList($add),
count($rem),
$this->renderHandleList($rem));
}
}
}