Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15414185
D19320.id46226.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
12 KB
Referenced Files
None
Subscribers
None
D19320.id46226.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
@@ -75,11 +75,13 @@
'AlmanacNamespaceEditor' => 'applications/almanac/editor/AlmanacNamespaceEditor.php',
'AlmanacNamespaceListController' => 'applications/almanac/controller/AlmanacNamespaceListController.php',
'AlmanacNamespaceNameNgrams' => 'applications/almanac/storage/AlmanacNamespaceNameNgrams.php',
+ 'AlmanacNamespaceNameTransaction' => 'applications/almanac/xaction/AlmanacNamespaceNameTransaction.php',
'AlmanacNamespacePHIDType' => 'applications/almanac/phid/AlmanacNamespacePHIDType.php',
'AlmanacNamespaceQuery' => 'applications/almanac/query/AlmanacNamespaceQuery.php',
'AlmanacNamespaceSearchEngine' => 'applications/almanac/query/AlmanacNamespaceSearchEngine.php',
'AlmanacNamespaceTransaction' => 'applications/almanac/storage/AlmanacNamespaceTransaction.php',
'AlmanacNamespaceTransactionQuery' => 'applications/almanac/query/AlmanacNamespaceTransactionQuery.php',
+ 'AlmanacNamespaceTransactionType' => 'applications/almanac/xaction/AlmanacNamespaceTransactionType.php',
'AlmanacNamespaceViewController' => 'applications/almanac/controller/AlmanacNamespaceViewController.php',
'AlmanacNetwork' => 'applications/almanac/storage/AlmanacNetwork.php',
'AlmanacNetworkController' => 'applications/almanac/controller/AlmanacNetworkController.php',
@@ -5262,11 +5264,13 @@
'AlmanacNamespaceEditor' => 'PhabricatorApplicationTransactionEditor',
'AlmanacNamespaceListController' => 'AlmanacNamespaceController',
'AlmanacNamespaceNameNgrams' => 'PhabricatorSearchNgrams',
+ 'AlmanacNamespaceNameTransaction' => 'AlmanacNamespaceTransactionType',
'AlmanacNamespacePHIDType' => 'PhabricatorPHIDType',
'AlmanacNamespaceQuery' => 'AlmanacQuery',
'AlmanacNamespaceSearchEngine' => 'PhabricatorApplicationSearchEngine',
- 'AlmanacNamespaceTransaction' => 'PhabricatorApplicationTransaction',
+ 'AlmanacNamespaceTransaction' => 'PhabricatorModularTransaction',
'AlmanacNamespaceTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
+ 'AlmanacNamespaceTransactionType' => 'AlmanacTransactionType',
'AlmanacNamespaceViewController' => 'AlmanacNamespaceController',
'AlmanacNetwork' => array(
'AlmanacDAO',
diff --git a/src/applications/almanac/editor/AlmanacNamespaceEditEngine.php b/src/applications/almanac/editor/AlmanacNamespaceEditEngine.php
--- a/src/applications/almanac/editor/AlmanacNamespaceEditEngine.php
+++ b/src/applications/almanac/editor/AlmanacNamespaceEditEngine.php
@@ -81,7 +81,7 @@
->setKey('name')
->setLabel(pht('Name'))
->setDescription(pht('Name of the namespace.'))
- ->setTransactionType(AlmanacNamespaceTransaction::TYPE_NAME)
+ ->setTransactionType(AlmanacNamespaceNameTransaction::TRANSACTIONTYPE)
->setIsRequired(true)
->setValue($object->getName()),
);
diff --git a/src/applications/almanac/editor/AlmanacNamespaceEditor.php b/src/applications/almanac/editor/AlmanacNamespaceEditor.php
--- a/src/applications/almanac/editor/AlmanacNamespaceEditor.php
+++ b/src/applications/almanac/editor/AlmanacNamespaceEditor.php
@@ -11,6 +11,14 @@
return pht('Almanac Namespace');
}
+ public function getCreateObjectTitle($author, $object) {
+ return pht('%s created this namespace.', $author);
+ }
+
+ public function getCreateObjectTitleForFeed($author, $object) {
+ return pht('%s created %s.', $author, $object);
+ }
+
protected function supportsSearch() {
return true;
}
@@ -18,149 +26,12 @@
public function getTransactionTypes() {
$types = parent::getTransactionTypes();
- $types[] = AlmanacNamespaceTransaction::TYPE_NAME;
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
return $types;
}
- protected function getCustomTransactionOldValue(
- PhabricatorLiskDAO $object,
- PhabricatorApplicationTransaction $xaction) {
- switch ($xaction->getTransactionType()) {
- case AlmanacNamespaceTransaction::TYPE_NAME:
- return $object->getName();
- }
-
- return parent::getCustomTransactionOldValue($object, $xaction);
- }
-
- protected function getCustomTransactionNewValue(
- PhabricatorLiskDAO $object,
- PhabricatorApplicationTransaction $xaction) {
-
- switch ($xaction->getTransactionType()) {
- case AlmanacNamespaceTransaction::TYPE_NAME:
- return $xaction->getNewValue();
- }
-
- return parent::getCustomTransactionNewValue($object, $xaction);
- }
-
- protected function applyCustomInternalTransaction(
- PhabricatorLiskDAO $object,
- PhabricatorApplicationTransaction $xaction) {
-
- switch ($xaction->getTransactionType()) {
- case AlmanacNamespaceTransaction::TYPE_NAME:
- $object->setName($xaction->getNewValue());
- return;
- }
-
- return parent::applyCustomInternalTransaction($object, $xaction);
- }
-
- protected function applyCustomExternalTransaction(
- PhabricatorLiskDAO $object,
- PhabricatorApplicationTransaction $xaction) {
-
- switch ($xaction->getTransactionType()) {
- case AlmanacNamespaceTransaction::TYPE_NAME:
- return;
- }
-
- return parent::applyCustomExternalTransaction($object, $xaction);
- }
-
- protected function validateTransaction(
- PhabricatorLiskDAO $object,
- $type,
- array $xactions) {
-
- $errors = parent::validateTransaction($object, $type, $xactions);
-
- switch ($type) {
- case AlmanacNamespaceTransaction::TYPE_NAME:
- $missing = $this->validateIsEmptyTextField(
- $object->getName(),
- $xactions);
-
- if ($missing) {
- $error = new PhabricatorApplicationTransactionValidationError(
- $type,
- pht('Required'),
- pht('Namespace name is required.'),
- nonempty(last($xactions), null));
-
- $error->setIsMissingFieldError(true);
- $errors[] = $error;
- } else {
- foreach ($xactions as $xaction) {
- $name = $xaction->getNewValue();
-
- $message = null;
- try {
- AlmanacNames::validateName($name);
- } catch (Exception $ex) {
- $message = $ex->getMessage();
- }
-
- if ($message !== null) {
- $error = new PhabricatorApplicationTransactionValidationError(
- $type,
- pht('Invalid'),
- $message,
- $xaction);
- $errors[] = $error;
- continue;
- }
-
- $other = id(new AlmanacNamespaceQuery())
- ->setViewer(PhabricatorUser::getOmnipotentUser())
- ->withNames(array($name))
- ->executeOne();
- if ($other && ($other->getID() != $object->getID())) {
- $error = new PhabricatorApplicationTransactionValidationError(
- $type,
- pht('Not Unique'),
- pht(
- 'The namespace name "%s" is already in use by another '.
- 'namespace. Each namespace must have a unique name.',
- $name),
- $xaction);
- $errors[] = $error;
- continue;
- }
-
- if ($name === $object->getName()) {
- continue;
- }
-
- $namespace = AlmanacNamespace::loadRestrictedNamespace(
- $this->getActor(),
- $name);
- if ($namespace) {
- $error = new PhabricatorApplicationTransactionValidationError(
- $type,
- pht('Restricted'),
- pht(
- 'You do not have permission to create Almanac namespaces '.
- 'within the "%s" namespace.',
- $namespace->getName()),
- $xaction);
- $errors[] = $error;
- continue;
- }
- }
- }
-
- break;
- }
-
- return $errors;
- }
-
protected function didCatchDuplicateKeyException(
PhabricatorLiskDAO $object,
array $xactions,
diff --git a/src/applications/almanac/storage/AlmanacNamespaceTransaction.php b/src/applications/almanac/storage/AlmanacNamespaceTransaction.php
--- a/src/applications/almanac/storage/AlmanacNamespaceTransaction.php
+++ b/src/applications/almanac/storage/AlmanacNamespaceTransaction.php
@@ -1,9 +1,7 @@
<?php
final class AlmanacNamespaceTransaction
- extends PhabricatorApplicationTransaction {
-
- const TYPE_NAME = 'almanac:namespace:name';
+ extends PhabricatorModularTransaction {
public function getApplicationName() {
return 'almanac';
@@ -17,27 +15,8 @@
return null;
}
- public function getTitle() {
- $author_phid = $this->getAuthorPHID();
-
- $old = $this->getOldValue();
- $new = $this->getNewValue();
-
- switch ($this->getTransactionType()) {
- case PhabricatorTransactions::TYPE_CREATE:
- return pht(
- '%s created this namespace.',
- $this->renderHandleLink($author_phid));
- break;
- case self::TYPE_NAME:
- return pht(
- '%s renamed this namespace from "%s" to "%s".',
- $this->renderHandleLink($author_phid),
- $old,
- $new);
- }
-
- return parent::getTitle();
+ public function getBaseTransactionClass() {
+ return 'AlmanacNamespaceTransactionType';
}
}
diff --git a/src/applications/almanac/xaction/AlmanacNamespaceNameTransaction.php b/src/applications/almanac/xaction/AlmanacNamespaceNameTransaction.php
new file mode 100644
--- /dev/null
+++ b/src/applications/almanac/xaction/AlmanacNamespaceNameTransaction.php
@@ -0,0 +1,91 @@
+<?php
+
+final class AlmanacNamespaceNameTransaction
+ extends AlmanacNamespaceTransactionType {
+
+ const TRANSACTIONTYPE = 'almanac:namespace:name';
+
+ public function generateOldValue($object) {
+ return $object->getName();
+ }
+
+ public function applyInternalEffects($object, $value) {
+ $object->setName($value);
+ }
+
+ public function getTitle() {
+ return pht(
+ '%s renamed this namespace from %s to %s.',
+ $this->renderAuthor(),
+ $this->renderOldValue(),
+ $this->renderNewValue());
+ }
+
+ public function getTitleForFeed() {
+ 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();
+
+ if ($this->isEmptyTextTransaction($object->getName(), $xactions)) {
+ $errors[] = $this->newRequiredError(
+ pht('Namespace name is required.'));
+ }
+
+ foreach ($xactions as $xaction) {
+ $name = $xaction->getNewValue();
+
+ $message = null;
+ try {
+ AlmanacNames::validateName($name);
+ } catch (Exception $ex) {
+ $message = $ex->getMessage();
+ }
+
+ if ($message !== null) {
+ $errors[] = $this->newInvalidError($message, $xaction);
+ continue;
+ }
+
+ if ($name === $object->getName()) {
+ continue;
+ }
+
+ $other = id(new AlmanacNamespaceQuery())
+ ->setViewer(PhabricatorUser::getOmnipotentUser())
+ ->withNames(array($name))
+ ->executeOne();
+ if ($other && ($other->getID() != $object->getID())) {
+ $errors[] = $this->newInvalidError(
+ pht(
+ 'The namespace name "%s" is already in use by another '.
+ 'namespace. Each namespace must have a unique name.',
+ $name),
+ $xaction);
+ continue;
+ }
+
+ $namespace = AlmanacNamespace::loadRestrictedNamespace(
+ $this->getActor(),
+ $name);
+ if ($namespace) {
+ $errors[] = $this->newInvalidError(
+ pht(
+ 'You do not have permission to create Almanac namespaces '.
+ 'within the "%s" namespace.',
+ $namespace->getName()),
+ $xaction);
+ continue;
+ }
+ }
+
+ return $errors;
+ }
+
+}
diff --git a/src/applications/almanac/xaction/AlmanacNamespaceTransactionType.php b/src/applications/almanac/xaction/AlmanacNamespaceTransactionType.php
new file mode 100644
--- /dev/null
+++ b/src/applications/almanac/xaction/AlmanacNamespaceTransactionType.php
@@ -0,0 +1,4 @@
+<?php
+
+abstract class AlmanacNamespaceTransactionType
+ extends AlmanacTransactionType {}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Mar 20, 11:17 PM (5 d, 9 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7714600
Default Alt Text
D19320.id46226.diff (12 KB)
Attached To
Mode
D19320: Modularize Almanac Namespace transactions
Attached
Detach File
Event Timeline
Log In to Comment