Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F13981469
D18845.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
13 KB
Referenced Files
None
Subscribers
None
D18845.diff
View Options
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
@@ -1008,6 +1008,7 @@
'DrydockBlueprintCustomField' => 'applications/drydock/customfield/DrydockBlueprintCustomField.php',
'DrydockBlueprintDatasource' => 'applications/drydock/typeahead/DrydockBlueprintDatasource.php',
'DrydockBlueprintDisableController' => 'applications/drydock/controller/DrydockBlueprintDisableController.php',
+ 'DrydockBlueprintDisableTransaction' => 'applications/drydock/xaction/DrydockBlueprintDisableTransaction.php',
'DrydockBlueprintEditConduitAPIMethod' => 'applications/drydock/conduit/DrydockBlueprintEditConduitAPIMethod.php',
'DrydockBlueprintEditController' => 'applications/drydock/controller/DrydockBlueprintEditController.php',
'DrydockBlueprintEditEngine' => 'applications/drydock/editor/DrydockBlueprintEditEngine.php',
@@ -1016,12 +1017,14 @@
'DrydockBlueprintImplementationTestCase' => 'applications/drydock/blueprint/__tests__/DrydockBlueprintImplementationTestCase.php',
'DrydockBlueprintListController' => 'applications/drydock/controller/DrydockBlueprintListController.php',
'DrydockBlueprintNameNgrams' => 'applications/drydock/storage/DrydockBlueprintNameNgrams.php',
+ 'DrydockBlueprintNameTransaction' => 'applications/drydock/xaction/DrydockBlueprintNameTransaction.php',
'DrydockBlueprintPHIDType' => 'applications/drydock/phid/DrydockBlueprintPHIDType.php',
'DrydockBlueprintQuery' => 'applications/drydock/query/DrydockBlueprintQuery.php',
'DrydockBlueprintSearchConduitAPIMethod' => 'applications/drydock/conduit/DrydockBlueprintSearchConduitAPIMethod.php',
'DrydockBlueprintSearchEngine' => 'applications/drydock/query/DrydockBlueprintSearchEngine.php',
'DrydockBlueprintTransaction' => 'applications/drydock/storage/DrydockBlueprintTransaction.php',
'DrydockBlueprintTransactionQuery' => 'applications/drydock/query/DrydockBlueprintTransactionQuery.php',
+ 'DrydockBlueprintTransactionType' => 'applications/drydock/xaction/DrydockBlueprintTransactionType.php',
'DrydockBlueprintViewController' => 'applications/drydock/controller/DrydockBlueprintViewController.php',
'DrydockCommand' => 'applications/drydock/storage/DrydockCommand.php',
'DrydockCommandError' => 'applications/drydock/exception/DrydockCommandError.php',
@@ -6102,6 +6105,7 @@
'DrydockBlueprintCustomField' => 'PhabricatorCustomField',
'DrydockBlueprintDatasource' => 'PhabricatorTypeaheadDatasource',
'DrydockBlueprintDisableController' => 'DrydockBlueprintController',
+ 'DrydockBlueprintDisableTransaction' => 'DrydockBlueprintTransactionType',
'DrydockBlueprintEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod',
'DrydockBlueprintEditController' => 'DrydockBlueprintController',
'DrydockBlueprintEditEngine' => 'PhabricatorEditEngine',
@@ -6110,12 +6114,14 @@
'DrydockBlueprintImplementationTestCase' => 'PhabricatorTestCase',
'DrydockBlueprintListController' => 'DrydockBlueprintController',
'DrydockBlueprintNameNgrams' => 'PhabricatorSearchNgrams',
+ 'DrydockBlueprintNameTransaction' => 'DrydockBlueprintTransactionType',
'DrydockBlueprintPHIDType' => 'PhabricatorPHIDType',
'DrydockBlueprintQuery' => 'DrydockQuery',
'DrydockBlueprintSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod',
'DrydockBlueprintSearchEngine' => 'PhabricatorApplicationSearchEngine',
- 'DrydockBlueprintTransaction' => 'PhabricatorApplicationTransaction',
+ 'DrydockBlueprintTransaction' => 'PhabricatorModularTransaction',
'DrydockBlueprintTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
+ 'DrydockBlueprintTransactionType' => 'PhabricatorModularTransactionType',
'DrydockBlueprintViewController' => 'DrydockBlueprintController',
'DrydockCommand' => array(
'DrydockDAO',
diff --git a/src/applications/drydock/controller/DrydockBlueprintDisableController.php b/src/applications/drydock/controller/DrydockBlueprintDisableController.php
--- a/src/applications/drydock/controller/DrydockBlueprintDisableController.php
+++ b/src/applications/drydock/controller/DrydockBlueprintDisableController.php
@@ -28,7 +28,8 @@
$xactions = array();
$xactions[] = id(new DrydockBlueprintTransaction())
- ->setTransactionType(DrydockBlueprintTransaction::TYPE_DISABLED)
+ ->setTransactionType(
+ DrydockBlueprintDisableTransaction::TRANSACTIONTYPE)
->setNewValue($is_disable ? 1 : 0);
$editor = id(new DrydockBlueprintEditor())
diff --git a/src/applications/drydock/editor/DrydockBlueprintEditEngine.php b/src/applications/drydock/editor/DrydockBlueprintEditEngine.php
--- a/src/applications/drydock/editor/DrydockBlueprintEditEngine.php
+++ b/src/applications/drydock/editor/DrydockBlueprintEditEngine.php
@@ -121,7 +121,7 @@
->setKey('name')
->setLabel(pht('Name'))
->setDescription(pht('Name of the blueprint.'))
- ->setTransactionType(DrydockBlueprintTransaction::TYPE_NAME)
+ ->setTransactionType(DrydockBlueprintNameTransaction::TRANSACTIONTYPE)
->setIsRequired(true)
->setValue($object->getBlueprintName()),
);
diff --git a/src/applications/drydock/editor/DrydockBlueprintEditor.php b/src/applications/drydock/editor/DrydockBlueprintEditor.php
--- a/src/applications/drydock/editor/DrydockBlueprintEditor.php
+++ b/src/applications/drydock/editor/DrydockBlueprintEditor.php
@@ -11,6 +11,14 @@
return pht('Drydock Blueprints');
}
+ public function getCreateObjectTitle($author, $object) {
+ return pht('%s created this blueprint.', $author);
+ }
+
+ public function getCreateObjectTitleForFeed($author, $object) {
+ return pht('%s created %s.', $author, $object);
+ }
+
protected function supportsSearch() {
return true;
}
@@ -21,99 +29,7 @@
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
- $types[] = DrydockBlueprintTransaction::TYPE_NAME;
- $types[] = DrydockBlueprintTransaction::TYPE_DISABLED;
-
return $types;
}
- protected function getCustomTransactionOldValue(
- PhabricatorLiskDAO $object,
- PhabricatorApplicationTransaction $xaction) {
-
- switch ($xaction->getTransactionType()) {
- case DrydockBlueprintTransaction::TYPE_NAME:
- return $object->getBlueprintName();
- case DrydockBlueprintTransaction::TYPE_DISABLED:
- return (int)$object->getIsDisabled();
- }
-
- return parent::getCustomTransactionOldValue($object, $xaction);
- }
-
- protected function getCustomTransactionNewValue(
- PhabricatorLiskDAO $object,
- PhabricatorApplicationTransaction $xaction) {
-
- switch ($xaction->getTransactionType()) {
- case DrydockBlueprintTransaction::TYPE_NAME:
- return $xaction->getNewValue();
- case DrydockBlueprintTransaction::TYPE_DISABLED:
- return (int)$xaction->getNewValue();
- }
-
- return parent::getCustomTransactionNewValue($object, $xaction);
- }
-
- protected function applyCustomInternalTransaction(
- PhabricatorLiskDAO $object,
- PhabricatorApplicationTransaction $xaction) {
-
- switch ($xaction->getTransactionType()) {
- case DrydockBlueprintTransaction::TYPE_NAME:
- $object->setBlueprintName($xaction->getNewValue());
- return;
- case DrydockBlueprintTransaction::TYPE_DISABLED:
- $object->setIsDisabled((int)$xaction->getNewValue());
- return;
- }
-
- return parent::applyCustomInternalTransaction($object, $xaction);
- }
-
- protected function applyCustomExternalTransaction(
- PhabricatorLiskDAO $object,
- PhabricatorApplicationTransaction $xaction) {
-
- switch ($xaction->getTransactionType()) {
- case DrydockBlueprintTransaction::TYPE_NAME:
- case DrydockBlueprintTransaction::TYPE_DISABLED:
- return;
- }
-
- return parent::applyCustomExternalTransaction($object, $xaction);
- }
-
-
- protected function validateTransaction(
- PhabricatorLiskDAO $object,
- $type,
- array $xactions) {
-
- $errors = parent::validateTransaction($object, $type, $xactions);
-
- switch ($type) {
- case DrydockBlueprintTransaction::TYPE_NAME:
- $missing = $this->validateIsEmptyTextField(
- $object->getBlueprintName(),
- $xactions);
-
- if ($missing) {
- $error = new PhabricatorApplicationTransactionValidationError(
- $type,
- pht('Required'),
- pht('You must choose a name for this blueprint.'),
- nonempty(last($xactions), null));
-
- $error->setIsMissingFieldError(true);
- $errors[] = $error;
- continue;
- }
-
- break;
- }
-
- return $errors;
- }
-
}
diff --git a/src/applications/drydock/storage/DrydockBlueprintTransaction.php b/src/applications/drydock/storage/DrydockBlueprintTransaction.php
--- a/src/applications/drydock/storage/DrydockBlueprintTransaction.php
+++ b/src/applications/drydock/storage/DrydockBlueprintTransaction.php
@@ -1,7 +1,7 @@
<?php
final class DrydockBlueprintTransaction
- extends PhabricatorApplicationTransaction {
+ extends PhabricatorModularTransaction {
const TYPE_NAME = 'drydock:blueprint:name';
const TYPE_DISABLED = 'drydock:blueprint:disabled';
@@ -14,37 +14,8 @@
return DrydockBlueprintPHIDType::TYPECONST;
}
- public function getTitle() {
- $old = $this->getOldValue();
- $new = $this->getNewValue();
- $author_handle = $this->renderHandleLink($this->getAuthorPHID());
-
- switch ($this->getTransactionType()) {
- case self::TYPE_NAME:
- if (!strlen($old)) {
- return pht(
- '%s created this blueprint.',
- $author_handle);
- } else {
- return pht(
- '%s renamed this blueprint from "%s" to "%s".',
- $author_handle,
- $old,
- $new);
- }
- case self::TYPE_DISABLED:
- if ($new) {
- return pht(
- '%s disabled this blueprint.',
- $author_handle);
- } else {
- return pht(
- '%s enabled this blueprint.',
- $author_handle);
- }
- }
-
- return parent::getTitle();
+ public function getBaseTransactionClass() {
+ return 'DrydockBlueprintTransactionType';
}
}
diff --git a/src/applications/drydock/xaction/DrydockBlueprintDisableTransaction.php b/src/applications/drydock/xaction/DrydockBlueprintDisableTransaction.php
new file mode 100644
--- /dev/null
+++ b/src/applications/drydock/xaction/DrydockBlueprintDisableTransaction.php
@@ -0,0 +1,48 @@
+<?php
+
+final class DrydockBlueprintDisableTransaction
+ extends DrydockBlueprintTransactionType {
+
+ const TRANSACTIONTYPE = 'drydock:blueprint:disabled';
+
+ public function generateOldValue($object) {
+ return (bool)$object->getIsDisabled();
+ }
+
+ public function generateNewValue($object, $value) {
+ return (bool)$value;
+ }
+
+ public function applyInternalEffects($object, $value) {
+ $object->setIsDisabled((int)$value);
+ }
+
+ public function getTitle() {
+ $new = $this->getNewValue();
+ if ($new) {
+ return pht(
+ '%s disabled this blueprint.',
+ $this->renderAuthor());
+ } else {
+ return pht(
+ '%s enabled this blueprint.',
+ $this->renderAuthor());
+ }
+ }
+
+ public function getTitleForFeed() {
+ $new = $this->getNewValue();
+ if ($new) {
+ return pht(
+ '%s disabled %s.',
+ $this->renderAuthor(),
+ $this->renderObject());
+ } else {
+ return pht(
+ '%s enabled %s.',
+ $this->renderAuthor(),
+ $this->renderObject());
+ }
+ }
+
+}
diff --git a/src/applications/drydock/xaction/DrydockBlueprintNameTransaction.php b/src/applications/drydock/xaction/DrydockBlueprintNameTransaction.php
new file mode 100644
--- /dev/null
+++ b/src/applications/drydock/xaction/DrydockBlueprintNameTransaction.php
@@ -0,0 +1,60 @@
+<?php
+
+final class DrydockBlueprintNameTransaction
+ extends DrydockBlueprintTransactionType {
+
+ const TRANSACTIONTYPE = 'drydock:blueprint:name';
+
+ public function generateOldValue($object) {
+ return $object->getBlueprintName();
+ }
+
+ public function applyInternalEffects($object, $value) {
+ $object->setBlueprintName($value);
+ }
+
+ public function getTitle() {
+ return pht(
+ '%s renamed this blueprint from %s to %s.',
+ $this->renderAuthor(),
+ $this->renderOldValue(),
+ $this->renderNewValue());
+ }
+
+ public function getTitleForFeed() {
+ $old = $this->getOldValue();
+ $new = $this->getNewValue();
+
+ return pht(
+ '%s renamed %s from %s to %s.',
+ $this->renderAuthor(),
+ $this->renderObject(),
+ $this->renderOldValue(),
+ $this->renderNewValue());
+ }
+
+ public function validateTransactions($object, array $xactions) {
+ $errors = array();
+
+ $name = $object->getBlueprintName();
+ if ($this->isEmptyTextTransaction($name, $xactions)) {
+ $errors[] = $this->newRequiredError(
+ pht('Blueprints must have a name.'));
+ }
+
+ $max_length = $object->getColumnMaximumByteLength('blueprintName');
+ foreach ($xactions as $xaction) {
+ $new_value = $xaction->getNewValue();
+
+ $new_length = strlen($new_value);
+ if ($new_length > $max_length) {
+ $errors[] = $this->newInvalidError(
+ pht('Blueprint names can be no longer than %s characters.',
+ new PhutilNumber($max_length)));
+ }
+ }
+
+ return $errors;
+ }
+
+}
diff --git a/src/applications/drydock/xaction/DrydockBlueprintTransactionType.php b/src/applications/drydock/xaction/DrydockBlueprintTransactionType.php
new file mode 100644
--- /dev/null
+++ b/src/applications/drydock/xaction/DrydockBlueprintTransactionType.php
@@ -0,0 +1,4 @@
+<?php
+
+abstract class DrydockBlueprintTransactionType
+ extends PhabricatorModularTransactionType {}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Oct 20, 4:45 PM (3 w, 6 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6736980
Default Alt Text
D18845.diff (13 KB)
Attached To
Mode
D18845: Modularize transactions for Drydock Blueprints
Attached
Detach File
Event Timeline
Log In to Comment