mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 14:00:56 +01:00
Convert Nuance sources to modular transactions
Summary: Ref T12738. Update sources to modular transactions. Test Plan: Created and edited a source. Reviewers: chad Reviewed By: chad Maniphest Tasks: T12738 Differential Revision: https://secure.phabricator.com/D17994
This commit is contained in:
parent
5b035af6ff
commit
3a0a086a09
6 changed files with 96 additions and 165 deletions
|
@ -1666,6 +1666,7 @@ phutil_register_library_map(array(
|
||||||
'NuanceSourceActionController' => 'applications/nuance/controller/NuanceSourceActionController.php',
|
'NuanceSourceActionController' => 'applications/nuance/controller/NuanceSourceActionController.php',
|
||||||
'NuanceSourceController' => 'applications/nuance/controller/NuanceSourceController.php',
|
'NuanceSourceController' => 'applications/nuance/controller/NuanceSourceController.php',
|
||||||
'NuanceSourceDefaultEditCapability' => 'applications/nuance/capability/NuanceSourceDefaultEditCapability.php',
|
'NuanceSourceDefaultEditCapability' => 'applications/nuance/capability/NuanceSourceDefaultEditCapability.php',
|
||||||
|
'NuanceSourceDefaultQueueTransaction' => 'applications/nuance/xaction/NuanceSourceDefaultQueueTransaction.php',
|
||||||
'NuanceSourceDefaultViewCapability' => 'applications/nuance/capability/NuanceSourceDefaultViewCapability.php',
|
'NuanceSourceDefaultViewCapability' => 'applications/nuance/capability/NuanceSourceDefaultViewCapability.php',
|
||||||
'NuanceSourceDefinition' => 'applications/nuance/source/NuanceSourceDefinition.php',
|
'NuanceSourceDefinition' => 'applications/nuance/source/NuanceSourceDefinition.php',
|
||||||
'NuanceSourceDefinitionTestCase' => 'applications/nuance/source/__tests__/NuanceSourceDefinitionTestCase.php',
|
'NuanceSourceDefinitionTestCase' => 'applications/nuance/source/__tests__/NuanceSourceDefinitionTestCase.php',
|
||||||
|
@ -1675,6 +1676,7 @@ phutil_register_library_map(array(
|
||||||
'NuanceSourceListController' => 'applications/nuance/controller/NuanceSourceListController.php',
|
'NuanceSourceListController' => 'applications/nuance/controller/NuanceSourceListController.php',
|
||||||
'NuanceSourceManageCapability' => 'applications/nuance/capability/NuanceSourceManageCapability.php',
|
'NuanceSourceManageCapability' => 'applications/nuance/capability/NuanceSourceManageCapability.php',
|
||||||
'NuanceSourceNameNgrams' => 'applications/nuance/storage/NuanceSourceNameNgrams.php',
|
'NuanceSourceNameNgrams' => 'applications/nuance/storage/NuanceSourceNameNgrams.php',
|
||||||
|
'NuanceSourceNameTransaction' => 'applications/nuance/xaction/NuanceSourceNameTransaction.php',
|
||||||
'NuanceSourcePHIDType' => 'applications/nuance/phid/NuanceSourcePHIDType.php',
|
'NuanceSourcePHIDType' => 'applications/nuance/phid/NuanceSourcePHIDType.php',
|
||||||
'NuanceSourceQuery' => 'applications/nuance/query/NuanceSourceQuery.php',
|
'NuanceSourceQuery' => 'applications/nuance/query/NuanceSourceQuery.php',
|
||||||
'NuanceSourceSearchEngine' => 'applications/nuance/query/NuanceSourceSearchEngine.php',
|
'NuanceSourceSearchEngine' => 'applications/nuance/query/NuanceSourceSearchEngine.php',
|
||||||
|
@ -6785,6 +6787,7 @@ phutil_register_library_map(array(
|
||||||
'NuanceSourceActionController' => 'NuanceController',
|
'NuanceSourceActionController' => 'NuanceController',
|
||||||
'NuanceSourceController' => 'NuanceController',
|
'NuanceSourceController' => 'NuanceController',
|
||||||
'NuanceSourceDefaultEditCapability' => 'PhabricatorPolicyCapability',
|
'NuanceSourceDefaultEditCapability' => 'PhabricatorPolicyCapability',
|
||||||
|
'NuanceSourceDefaultQueueTransaction' => 'NuanceSourceTransactionType',
|
||||||
'NuanceSourceDefaultViewCapability' => 'PhabricatorPolicyCapability',
|
'NuanceSourceDefaultViewCapability' => 'PhabricatorPolicyCapability',
|
||||||
'NuanceSourceDefinition' => 'Phobject',
|
'NuanceSourceDefinition' => 'Phobject',
|
||||||
'NuanceSourceDefinitionTestCase' => 'PhabricatorTestCase',
|
'NuanceSourceDefinitionTestCase' => 'PhabricatorTestCase',
|
||||||
|
@ -6794,6 +6797,7 @@ phutil_register_library_map(array(
|
||||||
'NuanceSourceListController' => 'NuanceSourceController',
|
'NuanceSourceListController' => 'NuanceSourceController',
|
||||||
'NuanceSourceManageCapability' => 'PhabricatorPolicyCapability',
|
'NuanceSourceManageCapability' => 'PhabricatorPolicyCapability',
|
||||||
'NuanceSourceNameNgrams' => 'PhabricatorSearchNgrams',
|
'NuanceSourceNameNgrams' => 'PhabricatorSearchNgrams',
|
||||||
|
'NuanceSourceNameTransaction' => 'NuanceSourceTransactionType',
|
||||||
'NuanceSourcePHIDType' => 'PhabricatorPHIDType',
|
'NuanceSourcePHIDType' => 'PhabricatorPHIDType',
|
||||||
'NuanceSourceQuery' => 'NuanceQuery',
|
'NuanceSourceQuery' => 'NuanceQuery',
|
||||||
'NuanceSourceSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
'NuanceSourceSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||||
|
|
|
@ -96,14 +96,15 @@ final class NuanceSourceEditEngine
|
||||||
->setKey('name')
|
->setKey('name')
|
||||||
->setLabel(pht('Name'))
|
->setLabel(pht('Name'))
|
||||||
->setDescription(pht('Name of the source.'))
|
->setDescription(pht('Name of the source.'))
|
||||||
->setTransactionType(NuanceSourceTransaction::TYPE_NAME)
|
->setTransactionType(NuanceSourceNameTransaction::TRANSACTIONTYPE)
|
||||||
->setIsRequired(true)
|
->setIsRequired(true)
|
||||||
->setValue($object->getName()),
|
->setValue($object->getName()),
|
||||||
id(new PhabricatorDatasourceEditField())
|
id(new PhabricatorDatasourceEditField())
|
||||||
->setKey('defaultQueue')
|
->setKey('defaultQueue')
|
||||||
->setLabel(pht('Default Queue'))
|
->setLabel(pht('Default Queue'))
|
||||||
->setDescription(pht('Default queue.'))
|
->setDescription(pht('Default queue.'))
|
||||||
->setTransactionType(NuanceSourceTransaction::TYPE_DEFAULT_QUEUE)
|
->setTransactionType(
|
||||||
|
NuanceSourceDefaultQueueTransaction::TRANSACTIONTYPE)
|
||||||
->setDatasource(new NuanceQueueDatasource())
|
->setDatasource(new NuanceQueueDatasource())
|
||||||
->setSingleValue($object->getDefaultQueuePHID()),
|
->setSingleValue($object->getDefaultQueuePHID()),
|
||||||
);
|
);
|
||||||
|
|
|
@ -18,111 +18,10 @@ final class NuanceSourceEditor
|
||||||
public function getTransactionTypes() {
|
public function getTransactionTypes() {
|
||||||
$types = parent::getTransactionTypes();
|
$types = parent::getTransactionTypes();
|
||||||
|
|
||||||
$types[] = NuanceSourceTransaction::TYPE_NAME;
|
|
||||||
$types[] = NuanceSourceTransaction::TYPE_DEFAULT_QUEUE;
|
|
||||||
|
|
||||||
$types[] = PhabricatorTransactions::TYPE_EDGE;
|
|
||||||
$types[] = PhabricatorTransactions::TYPE_COMMENT;
|
|
||||||
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
|
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
|
||||||
$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
|
$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
|
||||||
|
|
||||||
return $types;
|
return $types;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getCustomTransactionOldValue(
|
|
||||||
PhabricatorLiskDAO $object,
|
|
||||||
PhabricatorApplicationTransaction $xaction) {
|
|
||||||
|
|
||||||
switch ($xaction->getTransactionType()) {
|
|
||||||
case NuanceSourceTransaction::TYPE_NAME:
|
|
||||||
return $object->getName();
|
|
||||||
case NuanceSourceTransaction::TYPE_DEFAULT_QUEUE:
|
|
||||||
return $object->getDefaultQueuePHID();
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent::getCustomTransactionOldValue($object, $xaction);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getCustomTransactionNewValue(
|
|
||||||
PhabricatorLiskDAO $object,
|
|
||||||
PhabricatorApplicationTransaction $xaction) {
|
|
||||||
|
|
||||||
switch ($xaction->getTransactionType()) {
|
|
||||||
case NuanceSourceTransaction::TYPE_NAME:
|
|
||||||
case NuanceSourceTransaction::TYPE_DEFAULT_QUEUE:
|
|
||||||
return $xaction->getNewValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent::getCustomTransactionNewValue($object, $xaction);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function applyCustomInternalTransaction(
|
|
||||||
PhabricatorLiskDAO $object,
|
|
||||||
PhabricatorApplicationTransaction $xaction) {
|
|
||||||
|
|
||||||
switch ($xaction->getTransactionType()) {
|
|
||||||
case NuanceSourceTransaction::TYPE_NAME:
|
|
||||||
$object->setName($xaction->getNewValue());
|
|
||||||
break;
|
|
||||||
case NuanceSourceTransaction::TYPE_DEFAULT_QUEUE:
|
|
||||||
$object->setDefaultQueuePHID($xaction->getNewValue());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function applyCustomExternalTransaction(
|
|
||||||
PhabricatorLiskDAO $object,
|
|
||||||
PhabricatorApplicationTransaction $xaction) {
|
|
||||||
|
|
||||||
switch ($xaction->getTransactionType()) {
|
|
||||||
case NuanceSourceTransaction::TYPE_NAME:
|
|
||||||
case NuanceSourceTransaction::TYPE_DEFAULT_QUEUE:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent::applyCustomExternalTransaction($object, $xaction);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function validateTransaction(
|
|
||||||
PhabricatorLiskDAO $object,
|
|
||||||
$type,
|
|
||||||
array $xactions) {
|
|
||||||
|
|
||||||
$errors = parent::validateTransaction($object, $type, $xactions);
|
|
||||||
|
|
||||||
switch ($type) {
|
|
||||||
case NuanceSourceTransaction::TYPE_NAME:
|
|
||||||
$missing = $this->validateIsEmptyTextField(
|
|
||||||
$object->getName(),
|
|
||||||
$xactions);
|
|
||||||
|
|
||||||
if ($missing) {
|
|
||||||
$error = new PhabricatorApplicationTransactionValidationError(
|
|
||||||
$type,
|
|
||||||
pht('Required'),
|
|
||||||
pht('Source name is required.'),
|
|
||||||
nonempty(last($xactions), null));
|
|
||||||
|
|
||||||
$error->setIsMissingFieldError(true);
|
|
||||||
$errors[] = $error;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case NuanceSourceTransaction::TYPE_DEFAULT_QUEUE:
|
|
||||||
foreach ($xactions as $xaction) {
|
|
||||||
if (!$xaction->getNewValue()) {
|
|
||||||
$error = new PhabricatorApplicationTransactionValidationError(
|
|
||||||
$type,
|
|
||||||
pht('Required'),
|
|
||||||
pht('Sources must have a default queue.'),
|
|
||||||
$xaction);
|
|
||||||
$error->setIsMissingFieldError(true);
|
|
||||||
$errors[] = $error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $errors;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,6 @@
|
||||||
final class NuanceSourceTransaction
|
final class NuanceSourceTransaction
|
||||||
extends NuanceTransaction {
|
extends NuanceTransaction {
|
||||||
|
|
||||||
const TYPE_NAME = 'source.name';
|
|
||||||
const TYPE_DEFAULT_QUEUE = 'source.queue.default';
|
|
||||||
|
|
||||||
public function getApplicationTransactionType() {
|
public function getApplicationTransactionType() {
|
||||||
return NuanceSourcePHIDType::TYPECONST;
|
return NuanceSourcePHIDType::TYPECONST;
|
||||||
}
|
}
|
||||||
|
@ -18,63 +15,4 @@ final class NuanceSourceTransaction
|
||||||
return 'NuanceSourceTransactionType';
|
return 'NuanceSourceTransactionType';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function shouldHide() {
|
|
||||||
$old = $this->getOldValue();
|
|
||||||
$new = $this->getNewValue();
|
|
||||||
$type = $this->getTransactionType();
|
|
||||||
|
|
||||||
switch ($type) {
|
|
||||||
case self::TYPE_DEFAULT_QUEUE:
|
|
||||||
return !$old;
|
|
||||||
case self::TYPE_NAME:
|
|
||||||
return ($old === null);
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent::shouldHide();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getRequiredHandlePHIDs() {
|
|
||||||
$old = $this->getOldValue();
|
|
||||||
$new = $this->getNewValue();
|
|
||||||
$type = $this->getTransactionType();
|
|
||||||
|
|
||||||
$phids = parent::getRequiredHandlePHIDs();
|
|
||||||
switch ($type) {
|
|
||||||
case self::TYPE_DEFAULT_QUEUE:
|
|
||||||
if ($old) {
|
|
||||||
$phids[] = $old;
|
|
||||||
}
|
|
||||||
if ($new) {
|
|
||||||
$phids[] = $new;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $phids;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTitle() {
|
|
||||||
$old = $this->getOldValue();
|
|
||||||
$new = $this->getNewValue();
|
|
||||||
$type = $this->getTransactionType();
|
|
||||||
$author_phid = $this->getAuthorPHID();
|
|
||||||
|
|
||||||
switch ($type) {
|
|
||||||
case self::TYPE_DEFAULT_QUEUE:
|
|
||||||
return pht(
|
|
||||||
'%s changed the default queue from %s to %s.',
|
|
||||||
$this->renderHandleLink($author_phid),
|
|
||||||
$this->renderHandleLink($old),
|
|
||||||
$this->renderHandleLink($new));
|
|
||||||
case self::TYPE_NAME:
|
|
||||||
return pht(
|
|
||||||
'%s renamed this source from "%s" to "%s".',
|
|
||||||
$this->renderHandleLink($author_phid),
|
|
||||||
$old,
|
|
||||||
$new);
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent::getTitle();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class NuanceSourceDefaultQueueTransaction
|
||||||
|
extends NuanceSourceTransactionType {
|
||||||
|
|
||||||
|
const TRANSACTIONTYPE = 'source.queue.default';
|
||||||
|
|
||||||
|
public function generateOldValue($object) {
|
||||||
|
return $object->getDefaultQueuePHID();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function applyInternalEffects($object, $value) {
|
||||||
|
$object->setDefaultQueuePHID($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTitle() {
|
||||||
|
return pht(
|
||||||
|
'%s changed the default queue for this source from %s to %s.',
|
||||||
|
$this->renderAuthor(),
|
||||||
|
$this->renderOldHandle(),
|
||||||
|
$this->renderNewHandle());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function validateTransactions($object, array $xactions) {
|
||||||
|
$errors = array();
|
||||||
|
|
||||||
|
if (!$object->getDefaultQueuePHID() && !$xactions) {
|
||||||
|
$errors[] = $this->newRequiredError(
|
||||||
|
pht('Sources must have a default queue.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($xactions as $xaction) {
|
||||||
|
if (!$xaction->getNewValue()) {
|
||||||
|
$errors[] = $this->newRequiredError(
|
||||||
|
pht('Sources must have a default queue.'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class NuanceSourceNameTransaction
|
||||||
|
extends NuanceSourceTransactionType {
|
||||||
|
|
||||||
|
const TRANSACTIONTYPE = 'source.name';
|
||||||
|
|
||||||
|
public function generateOldValue($object) {
|
||||||
|
return $object->getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function applyInternalEffects($object, $value) {
|
||||||
|
$object->setName($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTitle() {
|
||||||
|
return pht(
|
||||||
|
'%s renamed this source from %s to %s.',
|
||||||
|
$this->renderAuthor(),
|
||||||
|
$this->renderOldValue(),
|
||||||
|
$this->renderNewValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function validateTransactions($object, array $xactions) {
|
||||||
|
$errors = array();
|
||||||
|
|
||||||
|
if ($this->isEmptyTextTransaction($object->getName(), $xactions)) {
|
||||||
|
$errors[] = $this->newRequiredError(
|
||||||
|
pht('Sources must have a name.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$max_length = $object->getColumnMaximumByteLength('name');
|
||||||
|
foreach ($xactions as $xaction) {
|
||||||
|
$new_value = $xaction->getNewValue();
|
||||||
|
$new_length = strlen($new_value);
|
||||||
|
if ($new_length > $max_length) {
|
||||||
|
$errors[] = $this->newInvalidError(
|
||||||
|
pht(
|
||||||
|
'Source names must not be longer than %s character(s).',
|
||||||
|
new PhutilNumber($max_length)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue