1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 14:52:41 +01:00

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
This commit is contained in:
epriestley 2019-05-13 10:26:32 -07:00
parent bf2f3991d2
commit e5fe4dffe1
4 changed files with 77 additions and 0 deletions

View file

@ -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',

View file

@ -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;
}
}

View file

@ -0,0 +1,15 @@
<?php
final class HeraldTransactionsFieldGroup extends HeraldFieldGroup {
const FIELDGROUPKEY = 'transactions';
public function getGroupLabel() {
return pht('Transactions');
}
protected function getGroupOrder() {
return 2000;
}
}

View file

@ -0,0 +1,42 @@
<?php
final class PhrictionDocumentPublishedHeraldField
extends PhrictionDocumentHeraldField {
const FIELDCONST = 'phriction.document.published';
public function getHeraldFieldName() {
return pht('Published document changed');
}
public function getFieldGroupKey() {
return HeraldTransactionsFieldGroup::FIELDGROUPKEY;
}
public function getHeraldFieldValue($object) {
// The published document changes if we apply a "publish" transaction
// (which points the published document pointer at new content) or if we
// apply a "content" transaction.
// When a change affects only the draft document, it applies as a "draft"
// transaction.
$type_content = PhrictionDocumentContentTransaction::TRANSACTIONTYPE;
$type_publish = PhrictionDocumentPublishTransaction::TRANSACTIONTYPE;
if ($this->hasAppliedTransactionOfType($type_content)) {
return true;
}
if ($this->hasAppliedTransactionOfType($type_publish)) {
return true;
}
return false;
}
protected function getHeraldFieldStandardType() {
return self::STANDARD_BOOL;
}
}