Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14477597
D10830.id25994.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
9 KB
Referenced Files
None
Subscribers
None
D10830.id25994.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -2767,6 +2767,7 @@
'PhrictionDiffController' => 'applications/phriction/controller/PhrictionDiffController.php',
'PhrictionDocument' => 'applications/phriction/storage/PhrictionDocument.php',
'PhrictionDocumentController' => 'applications/phriction/controller/PhrictionDocumentController.php',
+ 'PhrictionDocumentHeraldAdapter' => 'applications/phriction/herald/PhrictionDocumentHeraldAdapter.php',
'PhrictionDocumentPHIDType' => 'applications/phriction/phid/PhrictionDocumentPHIDType.php',
'PhrictionDocumentPreviewController' => 'applications/phriction/controller/PhrictionDocumentPreviewController.php',
'PhrictionDocumentQuery' => 'applications/phriction/query/PhrictionDocumentQuery.php',
@@ -5976,8 +5977,10 @@
'PhabricatorFlaggableInterface',
'PhabricatorTokenReceiverInterface',
'PhabricatorDestructibleInterface',
+ 'PhabricatorApplicationTransactionInterface',
),
'PhrictionDocumentController' => 'PhrictionController',
+ 'PhrictionDocumentHeraldAdapter' => 'HeraldAdapter',
'PhrictionDocumentPHIDType' => 'PhabricatorPHIDType',
'PhrictionDocumentPreviewController' => 'PhrictionController',
'PhrictionDocumentQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
diff --git a/src/applications/herald/controller/HeraldTestConsoleController.php b/src/applications/herald/controller/HeraldTestConsoleController.php
--- a/src/applications/herald/controller/HeraldTestConsoleController.php
+++ b/src/applications/herald/controller/HeraldTestConsoleController.php
@@ -47,6 +47,9 @@
} else if ($object instanceof PholioMock) {
$adapter = id(new HeraldPholioMockAdapter())
->setMock($object);
+ } else if ($object instanceof PhrictionDocument) {
+ $adapter = id(new PhrictionDocumentHeraldAdapter())
+ ->setDocument($object);
} else {
throw new Exception('Can not build adapter for object!');
}
diff --git a/src/applications/phriction/editor/PhrictionTransactionEditor.php b/src/applications/phriction/editor/PhrictionTransactionEditor.php
--- a/src/applications/phriction/editor/PhrictionTransactionEditor.php
+++ b/src/applications/phriction/editor/PhrictionTransactionEditor.php
@@ -10,6 +10,7 @@
private $skipAncestorCheck;
private $contentVersion;
private $processContentVersionError = true;
+ private $heraldEmailPHIDs = array();
public function setDescription($description) {
$this->description = $description;
@@ -359,6 +360,16 @@
);
}
+ protected function getMailCC(PhabricatorLiskDAO $object) {
+ $phids = array();
+
+ foreach ($this->heraldEmailPHIDs as $phid) {
+ $phids[] = $phid;
+ }
+
+ return $phids;
+ }
+
public function getMailTagsMap() {
return array(
PhrictionTransaction::MAILTAG_TITLE =>
@@ -595,7 +606,35 @@
protected function shouldApplyHeraldRules(
PhabricatorLiskDAO $object,
array $xactions) {
- return false;
+ return true;
+ }
+
+ protected function buildHeraldAdapter(
+ PhabricatorLiskDAO $object,
+ array $xactions) {
+
+ return id(new PhrictionDocumentHeraldAdapter())
+ ->setDocument($object);
+ }
+
+ protected function didApplyHeraldRules(
+ PhabricatorLiskDAO $object,
+ HeraldAdapter $adapter,
+ HeraldTranscript $transcript) {
+
+ $xactions = array();
+
+ $cc_phids = $adapter->getCcPHIDs();
+ if ($cc_phids) {
+ $value = array_fuse($cc_phids);
+ $xactions[] = id(new PhrictionTransaction())
+ ->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS)
+ ->setNewValue(array('+' => $value));
+ }
+
+ $this->heraldEmailPHIDs = $adapter->getEmailPHIDs();
+
+ return $xactions;
}
private function buildNewContentTemplate(
diff --git a/src/applications/phriction/herald/PhrictionDocumentHeraldAdapter.php b/src/applications/phriction/herald/PhrictionDocumentHeraldAdapter.php
new file mode 100644
--- /dev/null
+++ b/src/applications/phriction/herald/PhrictionDocumentHeraldAdapter.php
@@ -0,0 +1,167 @@
+<?php
+
+final class PhrictionDocumentHeraldAdapter extends HeraldAdapter {
+
+ private $document;
+ private $ccPHIDs = array();
+ private $emailPHIDs = array();
+
+ public function getAdapterApplicationClass() {
+ return 'PhabricatorPhrictionApplication';
+ }
+
+ public function getAdapterContentDescription() {
+ return pht('React to wikis being created or updated.');
+ }
+
+ public function getObject() {
+ return $this->document;
+ }
+
+ public function setDocument(PhrictionDocument $document) {
+ $this->document = $document;
+ return $this;
+ }
+ public function getDocument() {
+ return $this->document;
+ }
+
+ private function setCcPHIDs(array $cc_phids) {
+ $this->ccPHIDs = $cc_phids;
+ return $this;
+ }
+ public function getCcPHIDs() {
+ return $this->ccPHIDs;
+ }
+
+ public function getEmailPHIDs() {
+ return $this->emailPHIDs;
+ }
+
+
+ public function getAdapterContentName() {
+ return pht('Phriction Documents');
+ }
+
+ public function supportsRuleType($rule_type) {
+ switch ($rule_type) {
+ case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL:
+ case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL:
+ return true;
+ case HeraldRuleTypeConfig::RULE_TYPE_OBJECT:
+ default:
+ return false;
+ }
+ }
+
+ public function getFields() {
+ return array_merge(
+ array(
+ self::FIELD_TITLE,
+ self::FIELD_BODY,
+ self::FIELD_AUTHOR,
+ self::FIELD_IS_NEW_OBJECT,
+ self::FIELD_CC,
+ // self::FIELD_PATH,
+ ),
+ parent::getFields());
+ }
+
+ public function getActions($rule_type) {
+ switch ($rule_type) {
+ case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL:
+ return array_merge(
+ array(
+ self::ACTION_ADD_CC,
+ self::ACTION_NOTHING,
+ self::ACTION_EMAIL,
+ ),
+ parent::getActions($rule_type));
+ case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL:
+ return array_merge(
+ array(
+ self::ACTION_ADD_CC,
+ self::ACTION_FLAG,
+ self::ACTION_NOTHING,
+ self::ACTION_EMAIL,
+ ),
+ parent::getActions($rule_type));
+ }
+ }
+
+ public function getPHID() {
+ return $this->getDocument()->getPHID();
+ }
+
+ public function getHeraldName() {
+ return 'W'.$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_CC:
+ return PhabricatorSubscribersQuery::loadSubscribersForPHID(
+ $this->getDocument()->getPHID());
+ }
+
+ return parent::getHeraldField($field);
+ }
+
+ public function applyHeraldEffects(array $effects) {
+ assert_instances_of($effects, 'HeraldEffect');
+
+ $result = array();
+ foreach ($effects as $effect) {
+ $action = $effect->getAction();
+ switch ($action) {
+ case self::ACTION_NOTHING:
+ $result[] = new HeraldApplyTranscript(
+ $effect,
+ true,
+ pht('Great success at doing nothing.'));
+ break;
+ case self::ACTION_ADD_CC:
+ foreach ($effect->getTarget() as $phid) {
+ $this->ccPHIDs[] = $phid;
+ }
+ $result[] = new HeraldApplyTranscript(
+ $effect,
+ true,
+ pht('Added address to cc list.'));
+ break;
+ case self::ACTION_FLAG:
+ $result[] = parent::applyFlagEffect(
+ $effect,
+ $this->getDocument()->getPHID());
+ break;
+ case self::ACTION_EMAIL:
+ foreach ($effect->getTarget() as $phid) {
+ $this->emailPHIDs[] = $phid;
+ }
+ $result[] = new HeraldApplyTranscript(
+ $effect,
+ true,
+ pht('Added addresses to email list.'));
+ break;
+ default:
+ $custom_result = parent::handleCustomHeraldEffect($effect);
+ if ($custom_result === null) {
+ throw new Exception(pht(
+ "No rules to handle action '%s'.",
+ $action));
+ }
+
+ $result[] = $custom_result;
+ break;
+ }
+ }
+ return $result;
+ }
+
+}
diff --git a/src/applications/phriction/storage/PhrictionDocument.php b/src/applications/phriction/storage/PhrictionDocument.php
--- a/src/applications/phriction/storage/PhrictionDocument.php
+++ b/src/applications/phriction/storage/PhrictionDocument.php
@@ -6,7 +6,8 @@
PhabricatorSubscribableInterface,
PhabricatorFlaggableInterface,
PhabricatorTokenReceiverInterface,
- PhabricatorDestructibleInterface {
+ PhabricatorDestructibleInterface,
+ PhabricatorApplicationTransactionInterface {
protected $slug;
protected $depth;
@@ -234,6 +235,22 @@
return true;
}
+/* -( PhabricatorApplicationTransactionInterface )------------------------- */
+
+
+ public function getApplicationTransactionEditor() {
+ return new PhrictionTransactionEditor();
+ }
+
+ public function getApplicationTransactionObject() {
+ return $this;
+ }
+
+ public function getApplicationTransactionTemplate() {
+ return new PhrictionTransaction();
+ }
+
+
/* -( PhabricatorTokenReceiverInterface )---------------------------------- */
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Dec 29, 2:47 PM (7 h, 21 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6942568
Default Alt Text
D10830.id25994.diff (9 KB)
Attached To
Mode
D10830: T4666, Support Herald in Phriction
Attached
Detach File
Event Timeline
Log In to Comment