diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 7cbf6f7216..7088012879 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1666,6 +1666,7 @@ phutil_register_library_map(array( 'NuanceSourceActionController' => 'applications/nuance/controller/NuanceSourceActionController.php', 'NuanceSourceController' => 'applications/nuance/controller/NuanceSourceController.php', 'NuanceSourceDefaultEditCapability' => 'applications/nuance/capability/NuanceSourceDefaultEditCapability.php', + 'NuanceSourceDefaultQueueTransaction' => 'applications/nuance/xaction/NuanceSourceDefaultQueueTransaction.php', 'NuanceSourceDefaultViewCapability' => 'applications/nuance/capability/NuanceSourceDefaultViewCapability.php', 'NuanceSourceDefinition' => 'applications/nuance/source/NuanceSourceDefinition.php', 'NuanceSourceDefinitionTestCase' => 'applications/nuance/source/__tests__/NuanceSourceDefinitionTestCase.php', @@ -1675,6 +1676,7 @@ phutil_register_library_map(array( 'NuanceSourceListController' => 'applications/nuance/controller/NuanceSourceListController.php', 'NuanceSourceManageCapability' => 'applications/nuance/capability/NuanceSourceManageCapability.php', 'NuanceSourceNameNgrams' => 'applications/nuance/storage/NuanceSourceNameNgrams.php', + 'NuanceSourceNameTransaction' => 'applications/nuance/xaction/NuanceSourceNameTransaction.php', 'NuanceSourcePHIDType' => 'applications/nuance/phid/NuanceSourcePHIDType.php', 'NuanceSourceQuery' => 'applications/nuance/query/NuanceSourceQuery.php', 'NuanceSourceSearchEngine' => 'applications/nuance/query/NuanceSourceSearchEngine.php', @@ -6785,6 +6787,7 @@ phutil_register_library_map(array( 'NuanceSourceActionController' => 'NuanceController', 'NuanceSourceController' => 'NuanceController', 'NuanceSourceDefaultEditCapability' => 'PhabricatorPolicyCapability', + 'NuanceSourceDefaultQueueTransaction' => 'NuanceSourceTransactionType', 'NuanceSourceDefaultViewCapability' => 'PhabricatorPolicyCapability', 'NuanceSourceDefinition' => 'Phobject', 'NuanceSourceDefinitionTestCase' => 'PhabricatorTestCase', @@ -6794,6 +6797,7 @@ phutil_register_library_map(array( 'NuanceSourceListController' => 'NuanceSourceController', 'NuanceSourceManageCapability' => 'PhabricatorPolicyCapability', 'NuanceSourceNameNgrams' => 'PhabricatorSearchNgrams', + 'NuanceSourceNameTransaction' => 'NuanceSourceTransactionType', 'NuanceSourcePHIDType' => 'PhabricatorPHIDType', 'NuanceSourceQuery' => 'NuanceQuery', 'NuanceSourceSearchEngine' => 'PhabricatorApplicationSearchEngine', diff --git a/src/applications/nuance/editor/NuanceSourceEditEngine.php b/src/applications/nuance/editor/NuanceSourceEditEngine.php index 18d27863ac..eac751c3a5 100644 --- a/src/applications/nuance/editor/NuanceSourceEditEngine.php +++ b/src/applications/nuance/editor/NuanceSourceEditEngine.php @@ -96,14 +96,15 @@ final class NuanceSourceEditEngine ->setKey('name') ->setLabel(pht('Name')) ->setDescription(pht('Name of the source.')) - ->setTransactionType(NuanceSourceTransaction::TYPE_NAME) + ->setTransactionType(NuanceSourceNameTransaction::TRANSACTIONTYPE) ->setIsRequired(true) ->setValue($object->getName()), id(new PhabricatorDatasourceEditField()) ->setKey('defaultQueue') ->setLabel(pht('Default Queue')) ->setDescription(pht('Default queue.')) - ->setTransactionType(NuanceSourceTransaction::TYPE_DEFAULT_QUEUE) + ->setTransactionType( + NuanceSourceDefaultQueueTransaction::TRANSACTIONTYPE) ->setDatasource(new NuanceQueueDatasource()) ->setSingleValue($object->getDefaultQueuePHID()), ); diff --git a/src/applications/nuance/editor/NuanceSourceEditor.php b/src/applications/nuance/editor/NuanceSourceEditor.php index 5fbc02b962..b56b183f9e 100644 --- a/src/applications/nuance/editor/NuanceSourceEditor.php +++ b/src/applications/nuance/editor/NuanceSourceEditor.php @@ -18,111 +18,10 @@ final class NuanceSourceEditor public function 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_EDIT_POLICY; 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; - } - } diff --git a/src/applications/nuance/storage/NuanceSourceTransaction.php b/src/applications/nuance/storage/NuanceSourceTransaction.php index 5d70376ce3..0e264876dd 100644 --- a/src/applications/nuance/storage/NuanceSourceTransaction.php +++ b/src/applications/nuance/storage/NuanceSourceTransaction.php @@ -3,9 +3,6 @@ final class NuanceSourceTransaction extends NuanceTransaction { - const TYPE_NAME = 'source.name'; - const TYPE_DEFAULT_QUEUE = 'source.queue.default'; - public function getApplicationTransactionType() { return NuanceSourcePHIDType::TYPECONST; } @@ -18,63 +15,4 @@ final class NuanceSourceTransaction 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(); - } - } diff --git a/src/applications/nuance/xaction/NuanceSourceDefaultQueueTransaction.php b/src/applications/nuance/xaction/NuanceSourceDefaultQueueTransaction.php new file mode 100644 index 0000000000..f5a7cc4302 --- /dev/null +++ b/src/applications/nuance/xaction/NuanceSourceDefaultQueueTransaction.php @@ -0,0 +1,42 @@ +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; + } + +} diff --git a/src/applications/nuance/xaction/NuanceSourceNameTransaction.php b/src/applications/nuance/xaction/NuanceSourceNameTransaction.php new file mode 100644 index 0000000000..e33b60551c --- /dev/null +++ b/src/applications/nuance/xaction/NuanceSourceNameTransaction.php @@ -0,0 +1,47 @@ +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; + } + +}