Page MenuHomePhabricator

D16651.id40086.diff
No OneTemporary

D16651.id40086.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -2980,6 +2980,7 @@
'PhabricatorOwnersPackageFulltextEngine' => 'applications/owners/query/PhabricatorOwnersPackageFulltextEngine.php',
'PhabricatorOwnersPackageFunctionDatasource' => 'applications/owners/typeahead/PhabricatorOwnersPackageFunctionDatasource.php',
'PhabricatorOwnersPackageNameNgrams' => 'applications/owners/storage/PhabricatorOwnersPackageNameNgrams.php',
+ 'PhabricatorOwnersPackageNameTransaction' => 'applications/owners/xaction/PhabricatorOwnersPackageNameTransaction.php',
'PhabricatorOwnersPackageOwnerDatasource' => 'applications/owners/typeahead/PhabricatorOwnersPackageOwnerDatasource.php',
'PhabricatorOwnersPackagePHIDType' => 'applications/owners/phid/PhabricatorOwnersPackagePHIDType.php',
'PhabricatorOwnersPackageQuery' => 'applications/owners/query/PhabricatorOwnersPackageQuery.php',
@@ -2989,6 +2990,7 @@
'PhabricatorOwnersPackageTransaction' => 'applications/owners/storage/PhabricatorOwnersPackageTransaction.php',
'PhabricatorOwnersPackageTransactionEditor' => 'applications/owners/editor/PhabricatorOwnersPackageTransactionEditor.php',
'PhabricatorOwnersPackageTransactionQuery' => 'applications/owners/query/PhabricatorOwnersPackageTransactionQuery.php',
+ 'PhabricatorOwnersPackageTransactionType' => 'applications/owners/xaction/PhabricatorOwnersPackageTransactionType.php',
'PhabricatorOwnersPath' => 'applications/owners/storage/PhabricatorOwnersPath.php',
'PhabricatorOwnersPathsController' => 'applications/owners/controller/PhabricatorOwnersPathsController.php',
'PhabricatorOwnersPathsSearchEngineAttachment' => 'applications/owners/engineextension/PhabricatorOwnersPathsSearchEngineAttachment.php',
@@ -7856,15 +7858,17 @@
'PhabricatorOwnersPackageFulltextEngine' => 'PhabricatorFulltextEngine',
'PhabricatorOwnersPackageFunctionDatasource' => 'PhabricatorTypeaheadCompositeDatasource',
'PhabricatorOwnersPackageNameNgrams' => 'PhabricatorSearchNgrams',
+ 'PhabricatorOwnersPackageNameTransaction' => 'PhabricatorOwnersPackageTransactionType',
'PhabricatorOwnersPackageOwnerDatasource' => 'PhabricatorTypeaheadCompositeDatasource',
'PhabricatorOwnersPackagePHIDType' => 'PhabricatorPHIDType',
'PhabricatorOwnersPackageQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorOwnersPackageRemarkupRule' => 'PhabricatorObjectRemarkupRule',
'PhabricatorOwnersPackageSearchEngine' => 'PhabricatorApplicationSearchEngine',
'PhabricatorOwnersPackageTestCase' => 'PhabricatorTestCase',
- 'PhabricatorOwnersPackageTransaction' => 'PhabricatorApplicationTransaction',
+ 'PhabricatorOwnersPackageTransaction' => 'PhabricatorModularTransaction',
'PhabricatorOwnersPackageTransactionEditor' => 'PhabricatorApplicationTransactionEditor',
'PhabricatorOwnersPackageTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
+ 'PhabricatorOwnersPackageTransactionType' => 'PhabricatorModularTransactionType',
'PhabricatorOwnersPath' => 'PhabricatorOwnersDAO',
'PhabricatorOwnersPathsController' => 'PhabricatorOwnersController',
'PhabricatorOwnersPathsSearchEngineAttachment' => 'PhabricatorSearchEngineAttachment',
diff --git a/src/applications/owners/editor/PhabricatorOwnersPackageEditEngine.php b/src/applications/owners/editor/PhabricatorOwnersPackageEditEngine.php
--- a/src/applications/owners/editor/PhabricatorOwnersPackageEditEngine.php
+++ b/src/applications/owners/editor/PhabricatorOwnersPackageEditEngine.php
@@ -95,14 +95,16 @@
->setKey('name')
->setLabel(pht('Name'))
->setDescription(pht('Name of the package.'))
- ->setTransactionType(PhabricatorOwnersPackageTransaction::TYPE_NAME)
+ ->setTransactionType(
+ PhabricatorOwnersPackageNameTransaction::TRANSACTIONTYPE)
->setIsRequired(true)
->setValue($object->getName()),
id(new PhabricatorDatasourceEditField())
->setKey('owners')
->setLabel(pht('Owners'))
->setDescription(pht('Users and projects which own the package.'))
- ->setTransactionType(PhabricatorOwnersPackageTransaction::TYPE_OWNERS)
+ ->setTransactionType(
+ PhabricatorOwnersPackageOwnersTransaction::TRANSACTIONTYPE)
->setDatasource(new PhabricatorProjectOrUserDatasource())
->setIsCopyable(true)
->setValue($object->getOwnerPHIDs()),
@@ -135,7 +137,8 @@
pht(
'Automatically trigger audits for commits affecting files in '.
'this package.'))
- ->setTransactionType(PhabricatorOwnersPackageTransaction::TYPE_AUDITING)
+ ->setTransactionType(
+ PhabricatorOwnersPackageAuditingTransaction::TRANSACTIONTYPE)
->setIsCopyable(true)
->setValue($object->getAuditingEnabled())
->setOptions(
@@ -148,7 +151,7 @@
->setLabel(pht('Description'))
->setDescription(pht('Human-readable description of the package.'))
->setTransactionType(
- PhabricatorOwnersPackageTransaction::TYPE_DESCRIPTION)
+ PhabricatorOwnersPackageDescriptionTransaction::TRANSACTIONTYPE)
->setValue($object->getDescription()),
id(new PhabricatorSelectEditField())
->setKey('status')
diff --git a/src/applications/owners/editor/PhabricatorOwnersPackageTransactionEditor.php b/src/applications/owners/editor/PhabricatorOwnersPackageTransactionEditor.php
--- a/src/applications/owners/editor/PhabricatorOwnersPackageTransactionEditor.php
+++ b/src/applications/owners/editor/PhabricatorOwnersPackageTransactionEditor.php
@@ -14,11 +14,6 @@
public function getTransactionTypes() {
$types = parent::getTransactionTypes();
- $types[] = PhabricatorOwnersPackageTransaction::TYPE_NAME;
- $types[] = PhabricatorOwnersPackageTransaction::TYPE_OWNERS;
- $types[] = PhabricatorOwnersPackageTransaction::TYPE_AUDITING;
- $types[] = PhabricatorOwnersPackageTransaction::TYPE_DESCRIPTION;
- $types[] = PhabricatorOwnersPackageTransaction::TYPE_PATHS;
$types[] = PhabricatorOwnersPackageTransaction::TYPE_STATUS;
$types[] = PhabricatorOwnersPackageTransaction::TYPE_AUTOREVIEW;
$types[] = PhabricatorOwnersPackageTransaction::TYPE_DOMINION;
@@ -34,19 +29,6 @@
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
- case PhabricatorOwnersPackageTransaction::TYPE_NAME:
- return $object->getName();
- case PhabricatorOwnersPackageTransaction::TYPE_OWNERS:
- $phids = mpull($object->getOwners(), 'getUserPHID');
- $phids = array_values($phids);
- return $phids;
- case PhabricatorOwnersPackageTransaction::TYPE_AUDITING:
- return (int)$object->getAuditingEnabled();
- case PhabricatorOwnersPackageTransaction::TYPE_DESCRIPTION:
- return $object->getDescription();
- case PhabricatorOwnersPackageTransaction::TYPE_PATHS:
- $paths = $object->getPaths();
- return mpull($paths, 'getRef');
case PhabricatorOwnersPackageTransaction::TYPE_STATUS:
return $object->getStatus();
case PhabricatorOwnersPackageTransaction::TYPE_AUTOREVIEW:
@@ -61,25 +43,10 @@
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
- case PhabricatorOwnersPackageTransaction::TYPE_NAME:
- case PhabricatorOwnersPackageTransaction::TYPE_DESCRIPTION:
case PhabricatorOwnersPackageTransaction::TYPE_STATUS:
case PhabricatorOwnersPackageTransaction::TYPE_AUTOREVIEW:
case PhabricatorOwnersPackageTransaction::TYPE_DOMINION:
return $xaction->getNewValue();
- case PhabricatorOwnersPackageTransaction::TYPE_PATHS:
- $new = $xaction->getNewValue();
- foreach ($new as $key => $info) {
- $new[$key]['excluded'] = (int)idx($info, 'excluded');
- }
- return $new;
- case PhabricatorOwnersPackageTransaction::TYPE_AUDITING:
- return (int)$xaction->getNewValue();
- case PhabricatorOwnersPackageTransaction::TYPE_OWNERS:
- $phids = $xaction->getNewValue();
- $phids = array_unique($phids);
- $phids = array_values($phids);
- return $phids;
}
}
@@ -106,16 +73,6 @@
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
- case PhabricatorOwnersPackageTransaction::TYPE_NAME:
- $object->setName($xaction->getNewValue());
- return;
- case PhabricatorOwnersPackageTransaction::TYPE_DESCRIPTION:
- $object->setDescription($xaction->getNewValue());
- return;
- case PhabricatorOwnersPackageTransaction::TYPE_AUDITING:
- $object->setAuditingEnabled($xaction->getNewValue());
- return;
- case PhabricatorOwnersPackageTransaction::TYPE_OWNERS:
case PhabricatorOwnersPackageTransaction::TYPE_PATHS:
return;
case PhabricatorOwnersPackageTransaction::TYPE_STATUS:
@@ -137,38 +94,10 @@
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
- case PhabricatorOwnersPackageTransaction::TYPE_NAME:
- case PhabricatorOwnersPackageTransaction::TYPE_DESCRIPTION:
- case PhabricatorOwnersPackageTransaction::TYPE_AUDITING:
case PhabricatorOwnersPackageTransaction::TYPE_STATUS:
case PhabricatorOwnersPackageTransaction::TYPE_AUTOREVIEW:
case PhabricatorOwnersPackageTransaction::TYPE_DOMINION:
return;
- case PhabricatorOwnersPackageTransaction::TYPE_OWNERS:
- $old = $xaction->getOldValue();
- $new = $xaction->getNewValue();
-
- $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
- return;
case PhabricatorOwnersPackageTransaction::TYPE_PATHS:
$old = $xaction->getOldValue();
$new = $xaction->getNewValue();
@@ -206,37 +135,6 @@
$errors = parent::validateTransaction($object, $type, $xactions);
switch ($type) {
- case PhabricatorOwnersPackageTransaction::TYPE_NAME:
- $missing = $this->validateIsEmptyTextField(
- $object->getName(),
- $xactions);
-
- if ($missing) {
- $error = new PhabricatorApplicationTransactionValidationError(
- $type,
- pht('Required'),
- pht('Package name is required.'),
- nonempty(last($xactions), null));
-
- $error->setIsMissingFieldError(true);
- $errors[] = $error;
- }
-
- foreach ($xactions as $xaction) {
- $new = $xaction->getNewValue();
- if (preg_match('([,!])', $new)) {
- $errors[] = new PhabricatorApplicationTransactionValidationError(
- $type,
- pht('Invalid'),
- pht(
- 'Package names may not contain commas (",") or exclamation '.
- 'marks ("!"). These characters are ambiguous when package '.
- 'names are parsed from the command line.'),
- $xaction);
- }
- }
-
- break;
case PhabricatorOwnersPackageTransaction::TYPE_AUTOREVIEW:
$map = PhabricatorOwnersPackage::getAutoreviewOptionsMap();
foreach ($xactions as $xaction) {
diff --git a/src/applications/owners/storage/PhabricatorOwnersPackageTransaction.php b/src/applications/owners/storage/PhabricatorOwnersPackageTransaction.php
--- a/src/applications/owners/storage/PhabricatorOwnersPackageTransaction.php
+++ b/src/applications/owners/storage/PhabricatorOwnersPackageTransaction.php
@@ -1,14 +1,8 @@
<?php
final class PhabricatorOwnersPackageTransaction
- extends PhabricatorApplicationTransaction {
+ extends PhabricatorModularTransaction {
- const TYPE_NAME = 'owners.name';
- const TYPE_PRIMARY = 'owners.primary';
- const TYPE_OWNERS = 'owners.owners';
- const TYPE_AUDITING = 'owners.auditing';
- const TYPE_DESCRIPTION = 'owners.description';
- const TYPE_PATHS = 'owners.paths';
const TYPE_STATUS = 'owners.status';
const TYPE_AUTOREVIEW = 'owners.autoreview';
const TYPE_DOMINION = 'owners.dominion';
@@ -21,6 +15,10 @@
return PhabricatorOwnersPackagePHIDType::TYPECONST;
}
+ public function getBaseTransactionClass() {
+ return 'PhabricatorOwnersPackageTransactionType';
+ }
+
public function getRequiredHandlePHIDs() {
$phids = parent::getRequiredHandlePHIDs();
@@ -28,7 +26,7 @@
$new = $this->getNewValue();
switch ($this->getTransactionType()) {
- case self::TYPE_OWNERS:
+ case PhabricatorOwnersPackageOwnersTransaction::TRANSACTIONTYPE:
if (!is_array($old)) {
$old = array();
}
@@ -51,24 +49,6 @@
return $phids;
}
- public function shouldHide() {
- $old = $this->getOldValue();
- $new = $this->getNewValue();
-
- switch ($this->getTransactionType()) {
- case self::TYPE_DESCRIPTION:
- if ($old === null) {
- return true;
- }
- break;
- case self::TYPE_PRIMARY:
- // TODO: Eventually, remove these transactions entirely.
- return true;
- }
-
- return parent::shouldHide();
- }
-
public function getTitle() {
$old = $this->getOldValue();
$new = $this->getNewValue();
@@ -79,57 +59,6 @@
return pht(
'%s created this package.',
$this->renderHandleLink($author_phid));
- case self::TYPE_NAME:
- if ($old === null) {
- return pht(
- '%s created this package.',
- $this->renderHandleLink($author_phid));
- } else {
- return pht(
- '%s renamed this package from "%s" to "%s".',
- $this->renderHandleLink($author_phid),
- $old,
- $new);
- }
- case self::TYPE_OWNERS:
- $add = array_diff($new, $old);
- $rem = array_diff($old, $new);
- if ($add && !$rem) {
- return pht(
- '%s added %s owner(s): %s.',
- $this->renderHandleLink($author_phid),
- count($add),
- $this->renderHandleList($add));
- } else if ($rem && !$add) {
- return pht(
- '%s removed %s owner(s): %s.',
- $this->renderHandleLink($author_phid),
- count($rem),
- $this->renderHandleList($rem));
- } else {
- return pht(
- '%s changed %s package owner(s), added %s: %s; removed %s: %s.',
- $this->renderHandleLink($author_phid),
- count($add) + count($rem),
- count($add),
- $this->renderHandleList($add),
- count($rem),
- $this->renderHandleList($rem));
- }
- case self::TYPE_AUDITING:
- if ($new) {
- return pht(
- '%s enabled auditing for this package.',
- $this->renderHandleLink($author_phid));
- } else {
- return pht(
- '%s disabled auditing for this package.',
- $this->renderHandleLink($author_phid));
- }
- case self::TYPE_DESCRIPTION:
- return pht(
- '%s updated the description for this package.',
- $this->renderHandleLink($author_phid));
case self::TYPE_PATHS:
// TODO: Flesh this out.
return pht(
@@ -176,8 +105,6 @@
public function hasChangeDetails() {
switch ($this->getTransactionType()) {
- case self::TYPE_DESCRIPTION:
- return ($this->getOldValue() !== null);
case self::TYPE_PATHS:
return true;
}
@@ -187,14 +114,6 @@
public function renderChangeDetails(PhabricatorUser $viewer) {
switch ($this->getTransactionType()) {
- case self::TYPE_DESCRIPTION:
- $old = $this->getOldValue();
- $new = $this->getNewValue();
-
- return $this->renderTextCorpusChangeDetails(
- $viewer,
- $old,
- $new);
case self::TYPE_PATHS:
$old = $this->getOldValue();
$new = $this->getNewValue();
@@ -251,16 +170,4 @@
return parent::renderChangeDetails($viewer);
}
- public function getRemarkupBlocks() {
- $blocks = parent::getRemarkupBlocks();
-
- switch ($this->getTransactionType()) {
- case self::TYPE_DESCRIPTION:
- $blocks[] = $this->getNewValue();
- break;
- }
-
- return $blocks;
- }
-
}
diff --git a/src/applications/owners/xaction/PhabricatorOwnersPackageAuditingTransaction.php b/src/applications/owners/xaction/PhabricatorOwnersPackageAuditingTransaction.php
new file mode 100644
--- /dev/null
+++ b/src/applications/owners/xaction/PhabricatorOwnersPackageAuditingTransaction.php
@@ -0,0 +1,28 @@
+<?php
+
+final class PhabricatorOwnersPackageAuditingTransaction
+ extends PhabricatorOwnersPackageTransactionType {
+
+ const TRANSACTIONTYPE = 'owners.auditing';
+
+ public function generateOldValue($object) {
+ return (int)$object->getAuditingEnabled();
+ }
+
+ public function applyInternalEffects($object, $value) {
+ $object->setAuditingEnabled($value);
+ }
+
+ public function getTitle() {
+ if ($this->getNewValue()) {
+ return pht(
+ '%s enabled auditing for this package.',
+ $this->renderAuthor());
+ } else {
+ return pht(
+ '%s disabled auditing for this package.',
+ $this->renderAuthor());
+ }
+ }
+
+}
diff --git a/src/applications/owners/xaction/PhabricatorOwnersPackageDescriptionTransaction.php b/src/applications/owners/xaction/PhabricatorOwnersPackageDescriptionTransaction.php
new file mode 100644
--- /dev/null
+++ b/src/applications/owners/xaction/PhabricatorOwnersPackageDescriptionTransaction.php
@@ -0,0 +1,37 @@
+<?php
+
+final class PhabricatorOwnersPackageDescriptionTransaction
+ extends PhabricatorOwnersPackageTransactionType {
+
+ const TRANSACTIONTYPE = 'owners.description';
+
+ public function generateOldValue($object) {
+ return $object->getDescription();
+ }
+
+ public function applyInternalEffects($object, $value) {
+ $object->setDescription($value);
+ }
+
+ public function shouldHide() {
+ return ($this->getOldValue() === null);
+ }
+
+ public function getTitle() {
+ return pht(
+ '%s updated the description for this package.',
+ $this->renderAuthor());
+ }
+
+ public function hasChangeDetailView() {
+ return ($this->getOldValue() !== null);
+ }
+
+ public function newChangeDetailView() {
+ return id(new PhabricatorApplicationTransactionTextDiffDetailView())
+ ->setViewer($this->getViewer())
+ ->setOldText($this->getOldValue())
+ ->setNewText($this->getNewValue());
+ }
+
+}
diff --git a/src/applications/owners/xaction/PhabricatorOwnersPackageNameTransaction.php b/src/applications/owners/xaction/PhabricatorOwnersPackageNameTransaction.php
new file mode 100644
--- /dev/null
+++ b/src/applications/owners/xaction/PhabricatorOwnersPackageNameTransaction.php
@@ -0,0 +1,52 @@
+<?php
+
+final class PhabricatorOwnersPackageNameTransaction
+ extends PhabricatorOwnersPackageTransactionType {
+
+ const TRANSACTIONTYPE = 'owners.name';
+
+ public function generateOldValue($object) {
+ return $object->getName();
+ }
+
+ public function validateTransactions($object, array $xactions) {
+ $errors = parent::validateTransactions($object, $xactions);
+
+ $missing = $this->isEmptyTextTransaction(
+ $object->getName(),
+ $xactions);
+
+ if ($missing) {
+ $errors[] = $this->newRequiredError(
+ pht('Package name is required.'),
+ nonempty(last($xactions), null));
+ }
+
+ foreach ($xactions as $xaction) {
+ $new = $xaction->getNewValue();
+ if (preg_match('([,!])', $new)) {
+ $errors[] = $this->newInvalidError(
+ pht(
+ 'Package names may not contain commas (",") or exclamation '.
+ 'marks ("!"). These characters are ambiguous when package '.
+ 'names are parsed from the command line.'),
+ $xaction);
+ }
+ }
+
+ return $errors;
+ }
+
+ public function applyInternalEffects($object, $value) {
+ $object->setName($value);
+ }
+
+ public function getTitle() {
+ return pht(
+ '%s renamed this package from "%s" to "%s".',
+ $this->renderAuthor(),
+ $this->renderOldValue(),
+ $this->renderNewValue());
+ }
+
+}
diff --git a/src/applications/owners/xaction/PhabricatorOwnersPackageOwnersTransaction.php b/src/applications/owners/xaction/PhabricatorOwnersPackageOwnersTransaction.php
new file mode 100644
--- /dev/null
+++ b/src/applications/owners/xaction/PhabricatorOwnersPackageOwnersTransaction.php
@@ -0,0 +1,76 @@
+<?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->getOldValue();
+ $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));
+ }
+ }
+
+}
diff --git a/src/applications/owners/xaction/PhabricatorOwnersPackagePathsTransaction.php b/src/applications/owners/xaction/PhabricatorOwnersPackagePathsTransaction.php
new file mode 100644
--- /dev/null
+++ b/src/applications/owners/xaction/PhabricatorOwnersPackagePathsTransaction.php
@@ -0,0 +1,77 @@
+<?php
+
+final class PhabricatorOwnersPackagePathsTransaction
+ extends PhabricatorOwnersPackageTransactionType {
+
+ const TRANSACTIONTYPE = 'owners.paths';
+
+ public function generateOldValue($object) {
+ $paths = $object->getPaths();
+ return mpull($paths, 'getRef');
+ }
+
+ public function generateNewValue($object, $value) {
+ $new = $xaction->getNewValue();
+ foreach ($new as $key => $info) {
+ $new[$key]['excluded'] = (int)idx($info, 'excluded');
+ }
+ return $new;
+ }
+
+ public function applyExternalEffects($object, $value) {
+ $old = $this->getOldValue();
+ $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));
+ }
+ }
+
+}
diff --git a/src/applications/owners/xaction/PhabricatorOwnersPackagePrimaryTransaction.php b/src/applications/owners/xaction/PhabricatorOwnersPackagePrimaryTransaction.php
new file mode 100644
--- /dev/null
+++ b/src/applications/owners/xaction/PhabricatorOwnersPackagePrimaryTransaction.php
@@ -0,0 +1,15 @@
+<?php
+
+/**
+ * @deprecated
+ */
+final class PhabricatorOwnersPackagePrimaryTransaction
+ extends PhabricatorOwnersPackageTransactionType {
+
+ const TRANSACTIONTYPE = 'owners.primary';
+
+ public function shouldHide() {
+ return true;
+ }
+
+}
diff --git a/src/applications/owners/xaction/PhabricatorOwnersPackageTransactionType.php b/src/applications/owners/xaction/PhabricatorOwnersPackageTransactionType.php
new file mode 100644
--- /dev/null
+++ b/src/applications/owners/xaction/PhabricatorOwnersPackageTransactionType.php
@@ -0,0 +1,4 @@
+<?php
+
+abstract class PhabricatorOwnersPackageTransactionType
+ extends PhabricatorModularTransactionType {}

File Metadata

Mime Type
text/plain
Expires
Mon, Oct 21, 9:07 AM (4 w, 3 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6720704
Default Alt Text
D16651.id40086.diff (25 KB)

Event Timeline