@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

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

+77
+4
src/__phutil_library_map__.php
··· 1581 1581 'HeraldTextFieldValue' => 'applications/herald/value/HeraldTextFieldValue.php', 1582 1582 'HeraldTokenizerFieldValue' => 'applications/herald/value/HeraldTokenizerFieldValue.php', 1583 1583 'HeraldTransactionQuery' => 'applications/herald/query/HeraldTransactionQuery.php', 1584 + 'HeraldTransactionsFieldGroup' => 'applications/herald/field/HeraldTransactionsFieldGroup.php', 1584 1585 'HeraldTranscript' => 'applications/herald/storage/transcript/HeraldTranscript.php', 1585 1586 'HeraldTranscriptController' => 'applications/herald/controller/HeraldTranscriptController.php', 1586 1587 'HeraldTranscriptDestructionEngineExtension' => 'applications/herald/engineextension/HeraldTranscriptDestructionEngineExtension.php', ··· 5334 5335 'PhrictionDocumentPathHeraldField' => 'applications/phriction/herald/PhrictionDocumentPathHeraldField.php', 5335 5336 'PhrictionDocumentPolicyCodex' => 'applications/phriction/codex/PhrictionDocumentPolicyCodex.php', 5336 5337 'PhrictionDocumentPublishTransaction' => 'applications/phriction/xaction/PhrictionDocumentPublishTransaction.php', 5338 + 'PhrictionDocumentPublishedHeraldField' => 'applications/phriction/herald/PhrictionDocumentPublishedHeraldField.php', 5337 5339 'PhrictionDocumentQuery' => 'applications/phriction/query/PhrictionDocumentQuery.php', 5338 5340 'PhrictionDocumentSearchConduitAPIMethod' => 'applications/phriction/conduit/PhrictionDocumentSearchConduitAPIMethod.php', 5339 5341 'PhrictionDocumentSearchEngine' => 'applications/phriction/query/PhrictionDocumentSearchEngine.php', ··· 7372 7374 'HeraldTextFieldValue' => 'HeraldFieldValue', 7373 7375 'HeraldTokenizerFieldValue' => 'HeraldFieldValue', 7374 7376 'HeraldTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 7377 + 'HeraldTransactionsFieldGroup' => 'HeraldFieldGroup', 7375 7378 'HeraldTranscript' => array( 7376 7379 'HeraldDAO', 7377 7380 'PhabricatorPolicyInterface', ··· 11815 11818 'PhrictionDocumentPathHeraldField' => 'PhrictionDocumentHeraldField', 11816 11819 'PhrictionDocumentPolicyCodex' => 'PhabricatorPolicyCodex', 11817 11820 'PhrictionDocumentPublishTransaction' => 'PhrictionDocumentTransactionType', 11821 + 'PhrictionDocumentPublishedHeraldField' => 'PhrictionDocumentHeraldField', 11818 11822 'PhrictionDocumentQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 11819 11823 'PhrictionDocumentSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod', 11820 11824 'PhrictionDocumentSearchEngine' => 'PhabricatorApplicationSearchEngine',
+16
src/applications/herald/field/HeraldField.php
··· 202 202 ->execute(); 203 203 } 204 204 205 + final protected function hasAppliedTransactionOfType($type) { 206 + $xactions = $this->getAdapter()->getAppliedTransactions(); 207 + 208 + if (!$xactions) { 209 + return false; 210 + } 211 + 212 + foreach ($xactions as $xaction) { 213 + if ($xaction->getTransactionType() === $type) { 214 + return true; 215 + } 216 + } 217 + 218 + return false; 219 + } 220 + 205 221 }
+15
src/applications/herald/field/HeraldTransactionsFieldGroup.php
··· 1 + <?php 2 + 3 + final class HeraldTransactionsFieldGroup extends HeraldFieldGroup { 4 + 5 + const FIELDGROUPKEY = 'transactions'; 6 + 7 + public function getGroupLabel() { 8 + return pht('Transactions'); 9 + } 10 + 11 + protected function getGroupOrder() { 12 + return 2000; 13 + } 14 + 15 + }
+42
src/applications/phriction/herald/PhrictionDocumentPublishedHeraldField.php
··· 1 + <?php 2 + 3 + final class PhrictionDocumentPublishedHeraldField 4 + extends PhrictionDocumentHeraldField { 5 + 6 + const FIELDCONST = 'phriction.document.published'; 7 + 8 + public function getHeraldFieldName() { 9 + return pht('Published document changed'); 10 + } 11 + 12 + public function getFieldGroupKey() { 13 + return HeraldTransactionsFieldGroup::FIELDGROUPKEY; 14 + } 15 + 16 + public function getHeraldFieldValue($object) { 17 + // The published document changes if we apply a "publish" transaction 18 + // (which points the published document pointer at new content) or if we 19 + // apply a "content" transaction. 20 + 21 + // When a change affects only the draft document, it applies as a "draft" 22 + // transaction. 23 + 24 + $type_content = PhrictionDocumentContentTransaction::TRANSACTIONTYPE; 25 + $type_publish = PhrictionDocumentPublishTransaction::TRANSACTIONTYPE; 26 + 27 + if ($this->hasAppliedTransactionOfType($type_content)) { 28 + return true; 29 + } 30 + 31 + if ($this->hasAppliedTransactionOfType($type_publish)) { 32 + return true; 33 + } 34 + 35 + return false; 36 + } 37 + 38 + protected function getHeraldFieldStandardType() { 39 + return self::STANDARD_BOOL; 40 + } 41 + 42 + }