From 68de3dae9ab03fea8ce7b3e0a75ced24292b4f65 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 6 Jul 2015 13:17:50 -0700 Subject: [PATCH] Modularize all remaining Phriction Herald fields Summary: Ref T8726. Test Plan: - Created a rule using all the fields. - Updated documents, saw rule apply, reviewed transcript. - Migrated stuff. Reviewers: btrahan Reviewed By: btrahan Subscribers: eadler, epriestley Maniphest Tasks: T8726 Differential Revision: https://secure.phabricator.com/D13514 --- .../sql/autopatches/20150701.herald.2.sql | 20 ++++++++++ src/__phutil_library_map__.php | 10 +++++ .../herald/adapter/HeraldAdapter.php | 8 ++-- .../herald/HeraldManiphestTaskAdapter.php | 4 -- .../pholio/herald/HeraldPholioMockAdapter.php | 4 -- .../PhrictionDocumentAuthorHeraldField.php | 24 +++++++++++ .../PhrictionDocumentContentHeraldField.php | 24 +++++++++++ .../herald/PhrictionDocumentHeraldAdapter.php | 40 ------------------- .../herald/PhrictionDocumentHeraldField.php | 9 +++++ .../PhrictionDocumentPathHeraldField.php | 24 +++++++++++ .../PhrictionDocumentTitleHeraldField.php | 24 +++++++++++ 11 files changed, 139 insertions(+), 52 deletions(-) create mode 100644 resources/sql/autopatches/20150701.herald.2.sql create mode 100644 src/applications/phriction/herald/PhrictionDocumentAuthorHeraldField.php create mode 100644 src/applications/phriction/herald/PhrictionDocumentContentHeraldField.php create mode 100644 src/applications/phriction/herald/PhrictionDocumentHeraldField.php create mode 100644 src/applications/phriction/herald/PhrictionDocumentPathHeraldField.php create mode 100644 src/applications/phriction/herald/PhrictionDocumentTitleHeraldField.php diff --git a/resources/sql/autopatches/20150701.herald.2.sql b/resources/sql/autopatches/20150701.herald.2.sql new file mode 100644 index 0000000000..e65cc2c971 --- /dev/null +++ b/resources/sql/autopatches/20150701.herald.2.sql @@ -0,0 +1,20 @@ +UPDATE {$NAMESPACE}_herald.herald_condition c + JOIN {$NAMESPACE}_herald.herald_rule r + ON c.ruleID = r.id + SET c.fieldName = 'phriction.document.title' + WHERE r.contentType = 'PhrictionDocumentHeraldAdapter' + AND c.fieldName = 'title'; + +UPDATE {$NAMESPACE}_herald.herald_condition c + JOIN {$NAMESPACE}_herald.herald_rule r + ON c.ruleID = r.id + SET c.fieldName = 'phriction.document.content' + WHERE r.contentType = 'PhrictionDocumentHeraldAdapter' + AND c.fieldName = 'body'; + +UPDATE {$NAMESPACE}_herald.herald_condition c + JOIN {$NAMESPACE}_herald.herald_rule r + ON c.ruleID = r.id + SET c.fieldName = 'phriction.document.author' + WHERE r.contentType = 'PhrictionDocumentHeraldAdapter' + AND c.fieldName = 'author'; diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index aa6883cbc8..93300389f5 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -3159,11 +3159,16 @@ phutil_register_library_map(array( 'PhrictionDeleteController' => 'applications/phriction/controller/PhrictionDeleteController.php', 'PhrictionDiffController' => 'applications/phriction/controller/PhrictionDiffController.php', 'PhrictionDocument' => 'applications/phriction/storage/PhrictionDocument.php', + 'PhrictionDocumentAuthorHeraldField' => 'applications/phriction/herald/PhrictionDocumentAuthorHeraldField.php', + 'PhrictionDocumentContentHeraldField' => 'applications/phriction/herald/PhrictionDocumentContentHeraldField.php', 'PhrictionDocumentController' => 'applications/phriction/controller/PhrictionDocumentController.php', 'PhrictionDocumentHeraldAdapter' => 'applications/phriction/herald/PhrictionDocumentHeraldAdapter.php', + 'PhrictionDocumentHeraldField' => 'applications/phriction/herald/PhrictionDocumentHeraldField.php', 'PhrictionDocumentPHIDType' => 'applications/phriction/phid/PhrictionDocumentPHIDType.php', + 'PhrictionDocumentPathHeraldField' => 'applications/phriction/herald/PhrictionDocumentPathHeraldField.php', 'PhrictionDocumentQuery' => 'applications/phriction/query/PhrictionDocumentQuery.php', 'PhrictionDocumentStatus' => 'applications/phriction/constants/PhrictionDocumentStatus.php', + 'PhrictionDocumentTitleHeraldField' => 'applications/phriction/herald/PhrictionDocumentTitleHeraldField.php', 'PhrictionEditConduitAPIMethod' => 'applications/phriction/conduit/PhrictionEditConduitAPIMethod.php', 'PhrictionEditController' => 'applications/phriction/controller/PhrictionEditController.php', 'PhrictionHistoryConduitAPIMethod' => 'applications/phriction/conduit/PhrictionHistoryConduitAPIMethod.php', @@ -7090,11 +7095,16 @@ phutil_register_library_map(array( 'PhabricatorDestructibleInterface', 'PhabricatorApplicationTransactionInterface', ), + 'PhrictionDocumentAuthorHeraldField' => 'PhrictionDocumentHeraldField', + 'PhrictionDocumentContentHeraldField' => 'PhrictionDocumentHeraldField', 'PhrictionDocumentController' => 'PhrictionController', 'PhrictionDocumentHeraldAdapter' => 'HeraldAdapter', + 'PhrictionDocumentHeraldField' => 'HeraldField', 'PhrictionDocumentPHIDType' => 'PhabricatorPHIDType', + 'PhrictionDocumentPathHeraldField' => 'PhrictionDocumentHeraldField', 'PhrictionDocumentQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhrictionDocumentStatus' => 'PhrictionConstants', + 'PhrictionDocumentTitleHeraldField' => 'PhrictionDocumentHeraldField', 'PhrictionEditConduitAPIMethod' => 'PhrictionConduitAPIMethod', 'PhrictionEditController' => 'PhrictionController', 'PhrictionHistoryConduitAPIMethod' => 'PhrictionConduitAPIMethod', diff --git a/src/applications/herald/adapter/HeraldAdapter.php b/src/applications/herald/adapter/HeraldAdapter.php index cb20ce417b..3f736a9762 100644 --- a/src/applications/herald/adapter/HeraldAdapter.php +++ b/src/applications/herald/adapter/HeraldAdapter.php @@ -29,7 +29,6 @@ abstract class HeraldAdapter extends Phobject { const FIELD_AUTHOR_RAW = 'author-raw'; const FIELD_COMMITTER_RAW = 'committer-raw'; const FIELD_PUSHER_IS_COMMITTER = 'pusher-is-committer'; - const FIELD_PATH = 'path'; const CONDITION_CONTAINS = 'contains'; const CONDITION_NOT_CONTAINS = '!contains'; @@ -174,7 +173,10 @@ abstract class HeraldAdapter extends Phobject { return $this->applicationEmail; } - abstract public function getPHID(); + public function getPHID() { + return $this->getObject()->getPHID(); + } + abstract public function getHeraldName(); public function getHeraldField($field_name) { @@ -389,7 +391,6 @@ abstract class HeraldAdapter extends Phobject { self::FIELD_AUTHOR_RAW => pht('Raw author name'), self::FIELD_COMMITTER_RAW => pht('Raw committer name'), self::FIELD_PUSHER_IS_COMMITTER => pht('Pusher same as committer'), - self::FIELD_PATH => pht('Path'), ); } @@ -436,7 +437,6 @@ abstract class HeraldAdapter extends Phobject { case self::FIELD_BODY: case self::FIELD_COMMITTER_RAW: case self::FIELD_AUTHOR_RAW: - case self::FIELD_PATH: return array( self::CONDITION_CONTAINS, self::CONDITION_NOT_CONTAINS, diff --git a/src/applications/maniphest/herald/HeraldManiphestTaskAdapter.php b/src/applications/maniphest/herald/HeraldManiphestTaskAdapter.php index adbd724868..eade548740 100644 --- a/src/applications/maniphest/herald/HeraldManiphestTaskAdapter.php +++ b/src/applications/maniphest/herald/HeraldManiphestTaskAdapter.php @@ -93,10 +93,6 @@ final class HeraldManiphestTaskAdapter extends HeraldAdapter { } } - public function getPHID() { - return $this->getTask()->getPHID(); - } - public function getHeraldName() { return 'T'.$this->getTask()->getID(); } diff --git a/src/applications/pholio/herald/HeraldPholioMockAdapter.php b/src/applications/pholio/herald/HeraldPholioMockAdapter.php index 62578fab7b..2c87c394e9 100644 --- a/src/applications/pholio/herald/HeraldPholioMockAdapter.php +++ b/src/applications/pholio/herald/HeraldPholioMockAdapter.php @@ -69,10 +69,6 @@ final class HeraldPholioMockAdapter extends HeraldAdapter { } } - public function getPHID() { - return $this->getMock()->getPHID(); - } - public function getHeraldName() { return 'M'.$this->getMock()->getID(); } diff --git a/src/applications/phriction/herald/PhrictionDocumentAuthorHeraldField.php b/src/applications/phriction/herald/PhrictionDocumentAuthorHeraldField.php new file mode 100644 index 0000000000..584c0f67cd --- /dev/null +++ b/src/applications/phriction/herald/PhrictionDocumentAuthorHeraldField.php @@ -0,0 +1,24 @@ +getContent()->getAuthorPHID(); + } + + protected function getHeraldFieldStandardConditions() { + return self::STANDARD_PHID; + } + + public function getHeraldFieldValueType($condition) { + return HeraldAdapter::VALUE_USER; + } + +} diff --git a/src/applications/phriction/herald/PhrictionDocumentContentHeraldField.php b/src/applications/phriction/herald/PhrictionDocumentContentHeraldField.php new file mode 100644 index 0000000000..ff0cda4d94 --- /dev/null +++ b/src/applications/phriction/herald/PhrictionDocumentContentHeraldField.php @@ -0,0 +1,24 @@ +getContent()->getContent(); + } + + protected function getHeraldFieldStandardConditions() { + return self::STANDARD_TEXT; + } + + public function getHeraldFieldValueType($condition) { + return HeraldAdapter::VALUE_TEXT; + } + +} diff --git a/src/applications/phriction/herald/PhrictionDocumentHeraldAdapter.php b/src/applications/phriction/herald/PhrictionDocumentHeraldAdapter.php index 6d7de8ba99..48f72d57db 100644 --- a/src/applications/phriction/herald/PhrictionDocumentHeraldAdapter.php +++ b/src/applications/phriction/herald/PhrictionDocumentHeraldAdapter.php @@ -48,17 +48,6 @@ final class PhrictionDocumentHeraldAdapter extends HeraldAdapter { } } - public function getFields() { - return array_merge( - array( - self::FIELD_TITLE, - self::FIELD_BODY, - self::FIELD_AUTHOR, - self::FIELD_PATH, - ), - parent::getFields()); - } - public function getActions($rule_type) { switch ($rule_type) { case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL: @@ -83,38 +72,9 @@ final class PhrictionDocumentHeraldAdapter extends HeraldAdapter { } } - public function getPHID() { - return $this->getDocument()->getPHID(); - } public function getHeraldName() { return pht('Wiki Document %d', $this->getDocument()->getID()); } - public function getHeraldField($field) { - switch ($field) { - case self::FIELD_TITLE: - return $this->getDocument()->getContent()->getTitle(); - case self::FIELD_BODY: - return $this->getDocument()->getContent()->getContent(); - case self::FIELD_AUTHOR: - return $this->getDocument()->getContent()->getAuthorPHID(); - case self::FIELD_PATH: - return $this->getDocument()->getContent()->getSlug(); - } - - return parent::getHeraldField($field); - } - - public function applyHeraldEffects(array $effects) { - assert_instances_of($effects, 'HeraldEffect'); - - $result = array(); - foreach ($effects as $effect) { - $result[] = $this->applyStandardEffect($effect); - } - - return $result; - } - } diff --git a/src/applications/phriction/herald/PhrictionDocumentHeraldField.php b/src/applications/phriction/herald/PhrictionDocumentHeraldField.php new file mode 100644 index 0000000000..0548d0d80d --- /dev/null +++ b/src/applications/phriction/herald/PhrictionDocumentHeraldField.php @@ -0,0 +1,9 @@ +getcontent()->getSlug(); + } + + protected function getHeraldFieldStandardConditions() { + return self::STANDARD_TEXT; + } + + public function getHeraldFieldValueType($condition) { + return HeraldAdapter::VALUE_TEXT; + } + +} diff --git a/src/applications/phriction/herald/PhrictionDocumentTitleHeraldField.php b/src/applications/phriction/herald/PhrictionDocumentTitleHeraldField.php new file mode 100644 index 0000000000..79f6ec6498 --- /dev/null +++ b/src/applications/phriction/herald/PhrictionDocumentTitleHeraldField.php @@ -0,0 +1,24 @@ +getContent()->getTitle(); + } + + protected function getHeraldFieldStandardConditions() { + return self::STANDARD_TEXT; + } + + public function getHeraldFieldValueType($condition) { + return HeraldAdapter::VALUE_TEXT; + } + +}