@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Modularize HeraldRule transactions

Summary:
Ref T13249. See PHI1115. I initially wanted to make `bin/policy unlock --owner <user> H123` work to transfer ownership of a Herald rule, although I'm no longer really sure this makes much sense.

In any case, this makes things a little better and more modern.

I removed the storage table for rule comments. Adding comments to Herald rules doesn't work and probably doesn't make much sense.

Test Plan: Created and edited Herald rules, grepped for all the transaction type constants.

Reviewers: amckinley

Reviewed By: amckinley

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13249

Differential Revision: https://secure.phabricator.com/D20258

+166 -211
+1
resources/sql/autopatches/20190307.herald.01.comments.sql
··· 1 + DROP TABLE {$NAMESPACE}_herald.herald_ruletransaction_comment;
+9 -3
src/__phutil_library_map__.php
··· 1535 1535 'HeraldRuleAdapterField' => 'applications/herald/field/rule/HeraldRuleAdapterField.php', 1536 1536 'HeraldRuleController' => 'applications/herald/controller/HeraldRuleController.php', 1537 1537 'HeraldRuleDatasource' => 'applications/herald/typeahead/HeraldRuleDatasource.php', 1538 + 'HeraldRuleDisableTransaction' => 'applications/herald/xaction/HeraldRuleDisableTransaction.php', 1539 + 'HeraldRuleEditTransaction' => 'applications/herald/xaction/HeraldRuleEditTransaction.php', 1538 1540 'HeraldRuleEditor' => 'applications/herald/editor/HeraldRuleEditor.php', 1539 1541 'HeraldRuleField' => 'applications/herald/field/rule/HeraldRuleField.php', 1540 1542 'HeraldRuleFieldGroup' => 'applications/herald/field/rule/HeraldRuleFieldGroup.php', 1541 1543 'HeraldRuleListController' => 'applications/herald/controller/HeraldRuleListController.php', 1544 + 'HeraldRuleNameTransaction' => 'applications/herald/xaction/HeraldRuleNameTransaction.php', 1542 1545 'HeraldRulePHIDType' => 'applications/herald/phid/HeraldRulePHIDType.php', 1543 1546 'HeraldRuleQuery' => 'applications/herald/query/HeraldRuleQuery.php', 1544 1547 'HeraldRuleReplyHandler' => 'applications/herald/mail/HeraldRuleReplyHandler.php', ··· 1546 1549 'HeraldRuleSerializer' => 'applications/herald/editor/HeraldRuleSerializer.php', 1547 1550 'HeraldRuleTestCase' => 'applications/herald/storage/__tests__/HeraldRuleTestCase.php', 1548 1551 'HeraldRuleTransaction' => 'applications/herald/storage/HeraldRuleTransaction.php', 1549 - 'HeraldRuleTransactionComment' => 'applications/herald/storage/HeraldRuleTransactionComment.php', 1552 + 'HeraldRuleTransactionType' => 'applications/herald/xaction/HeraldRuleTransactionType.php', 1550 1553 'HeraldRuleTranscript' => 'applications/herald/storage/transcript/HeraldRuleTranscript.php', 1551 1554 'HeraldRuleTypeConfig' => 'applications/herald/config/HeraldRuleTypeConfig.php', 1552 1555 'HeraldRuleTypeDatasource' => 'applications/herald/typeahead/HeraldRuleTypeDatasource.php', ··· 7188 7191 'HeraldRuleAdapterField' => 'HeraldRuleField', 7189 7192 'HeraldRuleController' => 'HeraldController', 7190 7193 'HeraldRuleDatasource' => 'PhabricatorTypeaheadDatasource', 7194 + 'HeraldRuleDisableTransaction' => 'HeraldRuleTransactionType', 7195 + 'HeraldRuleEditTransaction' => 'HeraldRuleTransactionType', 7191 7196 'HeraldRuleEditor' => 'PhabricatorApplicationTransactionEditor', 7192 7197 'HeraldRuleField' => 'HeraldField', 7193 7198 'HeraldRuleFieldGroup' => 'HeraldFieldGroup', 7194 7199 'HeraldRuleListController' => 'HeraldController', 7200 + 'HeraldRuleNameTransaction' => 'HeraldRuleTransactionType', 7195 7201 'HeraldRulePHIDType' => 'PhabricatorPHIDType', 7196 7202 'HeraldRuleQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 7197 7203 'HeraldRuleReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler', 7198 7204 'HeraldRuleSearchEngine' => 'PhabricatorApplicationSearchEngine', 7199 7205 'HeraldRuleSerializer' => 'Phobject', 7200 7206 'HeraldRuleTestCase' => 'PhabricatorTestCase', 7201 - 'HeraldRuleTransaction' => 'PhabricatorApplicationTransaction', 7202 - 'HeraldRuleTransactionComment' => 'PhabricatorApplicationTransactionComment', 7207 + 'HeraldRuleTransaction' => 'PhabricatorModularTransaction', 7208 + 'HeraldRuleTransactionType' => 'PhabricatorModularTransactionType', 7203 7209 'HeraldRuleTranscript' => 'Phobject', 7204 7210 'HeraldRuleTypeConfig' => 'Phobject', 7205 7211 'HeraldRuleTypeDatasource' => 'PhabricatorTypeaheadDatasource',
+1 -1
src/applications/herald/controller/HeraldDisableController.php
··· 31 31 32 32 if ($request->isFormPost()) { 33 33 $xaction = id(new HeraldRuleTransaction()) 34 - ->setTransactionType(HeraldRuleTransaction::TYPE_DISABLE) 34 + ->setTransactionType(HeraldRuleDisableTransaction::TRANSACTIONTYPE) 35 35 ->setNewValue($is_disable); 36 36 37 37 id(new HeraldRuleEditor())
+12 -2
src/applications/herald/controller/HeraldRuleController.php
··· 359 359 $repetition_policy); 360 360 361 361 $xactions = array(); 362 + 363 + // Until this moves to EditEngine, manually add a "CREATE" transaction 364 + // if we're creating a new rule. This improves rendering of the initial 365 + // group of transactions. 366 + $is_new = (bool)(!$rule->getID()); 367 + if ($is_new) { 368 + $xactions[] = id(new HeraldRuleTransaction()) 369 + ->setTransactionType(PhabricatorTransactions::TYPE_CREATE); 370 + } 371 + 362 372 $xactions[] = id(new HeraldRuleTransaction()) 363 - ->setTransactionType(HeraldRuleTransaction::TYPE_EDIT) 373 + ->setTransactionType(HeraldRuleEditTransaction::TRANSACTIONTYPE) 364 374 ->setNewValue($new_state); 365 375 $xactions[] = id(new HeraldRuleTransaction()) 366 - ->setTransactionType(HeraldRuleTransaction::TYPE_NAME) 376 + ->setTransactionType(HeraldRuleNameTransaction::TRANSACTIONTYPE) 367 377 ->setNewValue($new_name); 368 378 369 379 try {
-77
src/applications/herald/editor/HeraldRuleEditor.php
··· 11 11 return pht('Herald Rules'); 12 12 } 13 13 14 - public function getTransactionTypes() { 15 - $types = parent::getTransactionTypes(); 16 - 17 - $types[] = PhabricatorTransactions::TYPE_COMMENT; 18 - $types[] = HeraldRuleTransaction::TYPE_EDIT; 19 - $types[] = HeraldRuleTransaction::TYPE_NAME; 20 - $types[] = HeraldRuleTransaction::TYPE_DISABLE; 21 - 22 - return $types; 23 - } 24 - 25 - protected function getCustomTransactionOldValue( 26 - PhabricatorLiskDAO $object, 27 - PhabricatorApplicationTransaction $xaction) { 28 - 29 - switch ($xaction->getTransactionType()) { 30 - case HeraldRuleTransaction::TYPE_DISABLE: 31 - return (int)$object->getIsDisabled(); 32 - case HeraldRuleTransaction::TYPE_EDIT: 33 - return id(new HeraldRuleSerializer()) 34 - ->serializeRule($object); 35 - case HeraldRuleTransaction::TYPE_NAME: 36 - return $object->getName(); 37 - } 38 - 39 - } 40 - 41 - protected function getCustomTransactionNewValue( 42 - PhabricatorLiskDAO $object, 43 - PhabricatorApplicationTransaction $xaction) { 44 - 45 - switch ($xaction->getTransactionType()) { 46 - case HeraldRuleTransaction::TYPE_DISABLE: 47 - return (int)$xaction->getNewValue(); 48 - case HeraldRuleTransaction::TYPE_EDIT: 49 - case HeraldRuleTransaction::TYPE_NAME: 50 - return $xaction->getNewValue(); 51 - } 52 - } 53 - 54 - protected function applyCustomInternalTransaction( 55 - PhabricatorLiskDAO $object, 56 - PhabricatorApplicationTransaction $xaction) { 57 - 58 - switch ($xaction->getTransactionType()) { 59 - case HeraldRuleTransaction::TYPE_DISABLE: 60 - return $object->setIsDisabled($xaction->getNewValue()); 61 - case HeraldRuleTransaction::TYPE_NAME: 62 - return $object->setName($xaction->getNewValue()); 63 - case HeraldRuleTransaction::TYPE_EDIT: 64 - $new_state = id(new HeraldRuleSerializer()) 65 - ->deserializeRuleComponents($xaction->getNewValue()); 66 - $object->setMustMatchAll((int)$new_state['match_all']); 67 - $object->attachConditions($new_state['conditions']); 68 - $object->attachActions($new_state['actions']); 69 - 70 - $new_repetition = $new_state['repetition_policy']; 71 - $object->setRepetitionPolicyStringConstant($new_repetition); 72 - 73 - return $object; 74 - } 75 - 76 - } 77 - 78 - protected function applyCustomExternalTransaction( 79 - PhabricatorLiskDAO $object, 80 - PhabricatorApplicationTransaction $xaction) { 81 - switch ($xaction->getTransactionType()) { 82 - case HeraldRuleTransaction::TYPE_EDIT: 83 - $object->saveConditions($object->getConditions()); 84 - $object->saveActions($object->getActions()); 85 - break; 86 - } 87 - return; 88 - } 89 - 90 14 protected function shouldApplyHeraldRules( 91 15 PhabricatorLiskDAO $object, 92 16 array $xactions) { ··· 136 60 protected function getMailSubjectPrefix() { 137 61 return pht('[Herald]'); 138 62 } 139 - 140 63 141 64 protected function buildMailBody( 142 65 PhabricatorLiskDAO $object,
+3 -118
src/applications/herald/storage/HeraldRuleTransaction.php
··· 1 1 <?php 2 2 3 3 final class HeraldRuleTransaction 4 - extends PhabricatorApplicationTransaction { 4 + extends PhabricatorModularTransaction { 5 5 6 6 const TYPE_EDIT = 'herald:edit'; 7 - const TYPE_NAME = 'herald:name'; 8 - const TYPE_DISABLE = 'herald:disable'; 9 7 10 8 public function getApplicationName() { 11 9 return 'herald'; ··· 15 13 return HeraldRulePHIDType::TYPECONST; 16 14 } 17 15 18 - public function getApplicationTransactionCommentObject() { 19 - return new HeraldRuleTransactionComment(); 20 - } 21 - 22 - public function getColor() { 23 - $old = $this->getOldValue(); 24 - $new = $this->getNewValue(); 25 - 26 - switch ($this->getTransactionType()) { 27 - case self::TYPE_DISABLE: 28 - if ($new) { 29 - return 'red'; 30 - } else { 31 - return 'green'; 32 - } 33 - } 34 - 35 - return parent::getColor(); 36 - } 37 - 38 - public function getActionName() { 39 - $old = $this->getOldValue(); 40 - $new = $this->getNewValue(); 41 - 42 - switch ($this->getTransactionType()) { 43 - case self::TYPE_DISABLE: 44 - if ($new) { 45 - return pht('Disabled'); 46 - } else { 47 - return pht('Enabled'); 48 - } 49 - case self::TYPE_NAME: 50 - return pht('Renamed'); 51 - } 52 - 53 - return parent::getActionName(); 54 - } 55 - 56 - public function getIcon() { 57 - $old = $this->getOldValue(); 58 - $new = $this->getNewValue(); 59 - 60 - switch ($this->getTransactionType()) { 61 - case self::TYPE_DISABLE: 62 - if ($new) { 63 - return 'fa-ban'; 64 - } else { 65 - return 'fa-check'; 66 - } 67 - } 68 - 69 - return parent::getIcon(); 70 - } 71 - 72 - 73 - public function getTitle() { 74 - $author_phid = $this->getAuthorPHID(); 75 - 76 - $old = $this->getOldValue(); 77 - $new = $this->getNewValue(); 78 - 79 - switch ($this->getTransactionType()) { 80 - case self::TYPE_DISABLE: 81 - if ($new) { 82 - return pht( 83 - '%s disabled this rule.', 84 - $this->renderHandleLink($author_phid)); 85 - } else { 86 - return pht( 87 - '%s enabled this rule.', 88 - $this->renderHandleLink($author_phid)); 89 - } 90 - case self::TYPE_NAME: 91 - if ($old == null) { 92 - return pht( 93 - '%s created this rule.', 94 - $this->renderHandleLink($author_phid)); 95 - } else { 96 - return pht( 97 - '%s renamed this rule from "%s" to "%s".', 98 - $this->renderHandleLink($author_phid), 99 - $old, 100 - $new); 101 - } 102 - case self::TYPE_EDIT: 103 - return pht( 104 - '%s edited this rule.', 105 - $this->renderHandleLink($author_phid)); 106 - } 107 - 108 - return parent::getTitle(); 109 - } 110 - 111 - public function hasChangeDetails() { 112 - switch ($this->getTransactionType()) { 113 - case self::TYPE_EDIT: 114 - return true; 115 - } 116 - return parent::hasChangeDetails(); 117 - } 118 - 119 - public function renderChangeDetails(PhabricatorUser $viewer) { 120 - $json = new PhutilJSON(); 121 - switch ($this->getTransactionType()) { 122 - case self::TYPE_EDIT: 123 - return $this->renderTextCorpusChangeDetails( 124 - $viewer, 125 - $json->encodeFormatted($this->getOldValue()), 126 - $json->encodeFormatted($this->getNewValue())); 127 - } 128 - 129 - return $this->renderTextCorpusChangeDetails( 130 - $viewer, 131 - $this->getOldValue(), 132 - $this->getNewValue()); 16 + public function getBaseTransactionClass() { 17 + return 'HeraldRuleTransactionType'; 133 18 } 134 19 135 20 }
-10
src/applications/herald/storage/HeraldRuleTransactionComment.php
··· 1 - <?php 2 - 3 - final class HeraldRuleTransactionComment 4 - extends PhabricatorApplicationTransactionComment { 5 - 6 - public function getApplicationTransactionObject() { 7 - return new HeraldRuleTransaction(); 8 - } 9 - 10 - }
+32
src/applications/herald/xaction/HeraldRuleDisableTransaction.php
··· 1 + <?php 2 + 3 + final class HeraldRuleDisableTransaction 4 + extends HeraldRuleTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'herald:disable'; 7 + 8 + public function generateOldValue($object) { 9 + return (bool)$object->getIsDisabled(); 10 + } 11 + 12 + public function generateNewValue($object, $value) { 13 + return (bool)$value; 14 + } 15 + 16 + public function applyInternalEffects($object, $value) { 17 + $object->setIsDisabled((int)$value); 18 + } 19 + 20 + public function getTitle() { 21 + if ($this->getNewValue()) { 22 + return pht( 23 + '%s disabled this rule.', 24 + $this->renderAuthor()); 25 + } else { 26 + return pht( 27 + '%s enabled this rule.', 28 + $this->renderAuthor()); 29 + } 30 + } 31 + 32 + }
+56
src/applications/herald/xaction/HeraldRuleEditTransaction.php
··· 1 + <?php 2 + 3 + final class HeraldRuleEditTransaction 4 + extends HeraldRuleTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'herald:edit'; 7 + 8 + public function generateOldValue($object) { 9 + return id(new HeraldRuleSerializer()) 10 + ->serializeRule($object); 11 + } 12 + 13 + public function applyInternalEffects($object, $value) { 14 + $new_state = id(new HeraldRuleSerializer()) 15 + ->deserializeRuleComponents($value); 16 + 17 + $object->setMustMatchAll((int)$new_state['match_all']); 18 + $object->attachConditions($new_state['conditions']); 19 + $object->attachActions($new_state['actions']); 20 + 21 + $new_repetition = $new_state['repetition_policy']; 22 + $object->setRepetitionPolicyStringConstant($new_repetition); 23 + } 24 + 25 + public function applyExternalEffects($object, $value) { 26 + $object->saveConditions($object->getConditions()); 27 + $object->saveActions($object->getActions()); 28 + } 29 + 30 + public function getTitle() { 31 + return pht( 32 + '%s edited this rule.', 33 + $this->renderAuthor()); 34 + } 35 + 36 + public function hasChangeDetailView() { 37 + return true; 38 + } 39 + 40 + public function newChangeDetailView() { 41 + $viewer = $this->getViewer(); 42 + 43 + $old = $this->getOldValue(); 44 + $new = $this->getNewValue(); 45 + 46 + $json = new PhutilJSON(); 47 + $old_json = $json->encodeFormatted($old); 48 + $new_json = $json->encodeFormatted($new); 49 + 50 + return id(new PhabricatorApplicationTransactionTextDiffDetailView()) 51 + ->setViewer($viewer) 52 + ->setOldText($old_json) 53 + ->setNewText($new_json); 54 + } 55 + 56 + }
+48
src/applications/herald/xaction/HeraldRuleNameTransaction.php
··· 1 + <?php 2 + 3 + final class HeraldRuleNameTransaction 4 + extends HeraldRuleTransactionType { 5 + 6 + const TRANSACTIONTYPE = 'herald:name'; 7 + 8 + public function generateOldValue($object) { 9 + return $object->getName(); 10 + } 11 + 12 + public function applyInternalEffects($object, $value) { 13 + $object->setName($value); 14 + } 15 + 16 + public function getTitle() { 17 + return pht( 18 + '%s renamed this rule from %s to %s.', 19 + $this->renderAuthor(), 20 + $this->renderOldValue(), 21 + $this->renderNewValue()); 22 + } 23 + 24 + public function validateTransactions($object, array $xactions) { 25 + $errors = array(); 26 + 27 + if ($this->isEmptyTextTransaction($object->getName(), $xactions)) { 28 + $errors[] = $this->newRequiredError( 29 + pht('Rules must have a name.')); 30 + } 31 + 32 + $max_length = $object->getColumnMaximumByteLength('name'); 33 + foreach ($xactions as $xaction) { 34 + $new_value = $xaction->getNewValue(); 35 + 36 + $new_length = strlen($new_value); 37 + if ($new_length > $max_length) { 38 + $errors[] = $this->newInvalidError( 39 + pht( 40 + 'Rule names can be no longer than %s characters.', 41 + new PhutilNumber($max_length))); 42 + } 43 + } 44 + 45 + return $errors; 46 + } 47 + 48 + }
+4
src/applications/herald/xaction/HeraldRuleTransactionType.php
··· 1 + <?php 2 + 3 + abstract class HeraldRuleTransactionType 4 + extends PhabricatorModularTransactionType {}