From e5fe4dffe1dc24df7a936a70db0eaaf93a3bf3f1 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 13 May 2019 10:26:32 -0700 Subject: [PATCH] Add a "Published document changed" rule to Herald for Phriction documents Summary: Depends on D20519. Ref T13283. See PHI1202. Add a new rule which triggers when the current/most-recent transaction group includes a "content" or "publish" transaction, which means the published document content has changed. Test Plan: - Wrote a Herald rule using this field. - Created a document (rule matched). - Edited a document (rule matched). - Edited a document, saving as a draft (no match). - Edited a draft, updating it (no match). - Published a draft docuemnt (rule matched). Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13283 Differential Revision: https://secure.phabricator.com/D20520 --- src/__phutil_library_map__.php | 4 ++ src/applications/herald/field/HeraldField.php | 16 +++++++ .../field/HeraldTransactionsFieldGroup.php | 15 +++++++ .../PhrictionDocumentPublishedHeraldField.php | 42 +++++++++++++++++++ 4 files changed, 77 insertions(+) create mode 100644 src/applications/herald/field/HeraldTransactionsFieldGroup.php create mode 100644 src/applications/phriction/herald/PhrictionDocumentPublishedHeraldField.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index b68dc107a6..5f28529e80 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1581,6 +1581,7 @@ phutil_register_library_map(array( 'HeraldTextFieldValue' => 'applications/herald/value/HeraldTextFieldValue.php', 'HeraldTokenizerFieldValue' => 'applications/herald/value/HeraldTokenizerFieldValue.php', 'HeraldTransactionQuery' => 'applications/herald/query/HeraldTransactionQuery.php', + 'HeraldTransactionsFieldGroup' => 'applications/herald/field/HeraldTransactionsFieldGroup.php', 'HeraldTranscript' => 'applications/herald/storage/transcript/HeraldTranscript.php', 'HeraldTranscriptController' => 'applications/herald/controller/HeraldTranscriptController.php', 'HeraldTranscriptDestructionEngineExtension' => 'applications/herald/engineextension/HeraldTranscriptDestructionEngineExtension.php', @@ -5334,6 +5335,7 @@ phutil_register_library_map(array( 'PhrictionDocumentPathHeraldField' => 'applications/phriction/herald/PhrictionDocumentPathHeraldField.php', 'PhrictionDocumentPolicyCodex' => 'applications/phriction/codex/PhrictionDocumentPolicyCodex.php', 'PhrictionDocumentPublishTransaction' => 'applications/phriction/xaction/PhrictionDocumentPublishTransaction.php', + 'PhrictionDocumentPublishedHeraldField' => 'applications/phriction/herald/PhrictionDocumentPublishedHeraldField.php', 'PhrictionDocumentQuery' => 'applications/phriction/query/PhrictionDocumentQuery.php', 'PhrictionDocumentSearchConduitAPIMethod' => 'applications/phriction/conduit/PhrictionDocumentSearchConduitAPIMethod.php', 'PhrictionDocumentSearchEngine' => 'applications/phriction/query/PhrictionDocumentSearchEngine.php', @@ -7372,6 +7374,7 @@ phutil_register_library_map(array( 'HeraldTextFieldValue' => 'HeraldFieldValue', 'HeraldTokenizerFieldValue' => 'HeraldFieldValue', 'HeraldTransactionQuery' => 'PhabricatorApplicationTransactionQuery', + 'HeraldTransactionsFieldGroup' => 'HeraldFieldGroup', 'HeraldTranscript' => array( 'HeraldDAO', 'PhabricatorPolicyInterface', @@ -11815,6 +11818,7 @@ phutil_register_library_map(array( 'PhrictionDocumentPathHeraldField' => 'PhrictionDocumentHeraldField', 'PhrictionDocumentPolicyCodex' => 'PhabricatorPolicyCodex', 'PhrictionDocumentPublishTransaction' => 'PhrictionDocumentTransactionType', + 'PhrictionDocumentPublishedHeraldField' => 'PhrictionDocumentHeraldField', 'PhrictionDocumentQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhrictionDocumentSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod', 'PhrictionDocumentSearchEngine' => 'PhabricatorApplicationSearchEngine', diff --git a/src/applications/herald/field/HeraldField.php b/src/applications/herald/field/HeraldField.php index 408a76f7fb..611ea2cdb3 100644 --- a/src/applications/herald/field/HeraldField.php +++ b/src/applications/herald/field/HeraldField.php @@ -202,4 +202,20 @@ abstract class HeraldField extends Phobject { ->execute(); } + final protected function hasAppliedTransactionOfType($type) { + $xactions = $this->getAdapter()->getAppliedTransactions(); + + if (!$xactions) { + return false; + } + + foreach ($xactions as $xaction) { + if ($xaction->getTransactionType() === $type) { + return true; + } + } + + return false; + } + } diff --git a/src/applications/herald/field/HeraldTransactionsFieldGroup.php b/src/applications/herald/field/HeraldTransactionsFieldGroup.php new file mode 100644 index 0000000000..6198578492 --- /dev/null +++ b/src/applications/herald/field/HeraldTransactionsFieldGroup.php @@ -0,0 +1,15 @@ +hasAppliedTransactionOfType($type_content)) { + return true; + } + + if ($this->hasAppliedTransactionOfType($type_publish)) { + return true; + } + + return false; + } + + protected function getHeraldFieldStandardType() { + return self::STANDARD_BOOL; + } + +}