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 @@ -1485,12 +1485,14 @@ 'HeraldRemarkupFieldValue' => 'applications/herald/value/HeraldRemarkupFieldValue.php', 'HeraldRemarkupRule' => 'applications/herald/remarkup/HeraldRemarkupRule.php', 'HeraldRule' => 'applications/herald/storage/HeraldRule.php', + 'HeraldRuleAdapter' => 'applications/herald/adapter/HeraldRuleAdapter.php', 'HeraldRuleController' => 'applications/herald/controller/HeraldRuleController.php', 'HeraldRuleDatasource' => 'applications/herald/typeahead/HeraldRuleDatasource.php', 'HeraldRuleEditor' => 'applications/herald/editor/HeraldRuleEditor.php', 'HeraldRuleListController' => 'applications/herald/controller/HeraldRuleListController.php', 'HeraldRulePHIDType' => 'applications/herald/phid/HeraldRulePHIDType.php', 'HeraldRuleQuery' => 'applications/herald/query/HeraldRuleQuery.php', + 'HeraldRuleReplyHandler' => 'applications/herald/mail/HeraldRuleReplyHandler.php', 'HeraldRuleSearchEngine' => 'applications/herald/query/HeraldRuleSearchEngine.php', 'HeraldRuleSerializer' => 'applications/herald/editor/HeraldRuleSerializer.php', 'HeraldRuleTestCase' => 'applications/herald/storage/__tests__/HeraldRuleTestCase.php', @@ -6918,12 +6920,14 @@ 'PhabricatorDestructibleInterface', 'PhabricatorSubscribableInterface', ), + 'HeraldRuleAdapter' => 'HeraldAdapter', 'HeraldRuleController' => 'HeraldController', 'HeraldRuleDatasource' => 'PhabricatorTypeaheadDatasource', 'HeraldRuleEditor' => 'PhabricatorApplicationTransactionEditor', 'HeraldRuleListController' => 'HeraldController', 'HeraldRulePHIDType' => 'PhabricatorPHIDType', 'HeraldRuleQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', + 'HeraldRuleReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler', 'HeraldRuleSearchEngine' => 'PhabricatorApplicationSearchEngine', 'HeraldRuleSerializer' => 'Phobject', 'HeraldRuleTestCase' => 'PhabricatorTestCase', diff --git a/src/applications/herald/adapter/HeraldRuleAdapter.php b/src/applications/herald/adapter/HeraldRuleAdapter.php new file mode 100644 --- /dev/null +++ b/src/applications/herald/adapter/HeraldRuleAdapter.php @@ -0,0 +1,74 @@ +rule = $this->newObject(); + } + + public function supportsApplicationEmail() { + return true; + } + + 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 setRule(HeraldRule $rule) { + $this->rule = $rule; + return $this; + } + + public function getRule() { + return $this->rule; + } + + public function setObject($object) { + $this->rule = $object; + return $this; + } + + public function getObject() { + return $this->rule; + } + + public function getAdapterContentName() { + return pht('Herald Rules'); + } + + public function getHeraldName() { + return $this->getRule()->getMonogram(); + } + +} diff --git a/src/applications/herald/controller/HeraldRuleController.php b/src/applications/herald/controller/HeraldRuleController.php --- a/src/applications/herald/controller/HeraldRuleController.php +++ b/src/applications/herald/controller/HeraldRuleController.php @@ -374,6 +374,8 @@ ->applyTransactions($rule, $xactions); return array(null, null); } catch (Exception $ex) { + + phlog($ex); $errors[] = $ex->getMessage(); } } diff --git a/src/applications/herald/editor/HeraldRuleEditor.php b/src/applications/herald/editor/HeraldRuleEditor.php --- a/src/applications/herald/editor/HeraldRuleEditor.php +++ b/src/applications/herald/editor/HeraldRuleEditor.php @@ -87,4 +87,54 @@ return; } + protected function shouldApplyHeraldRules( + PhabricatorLiskDAO $object, + array $xactions) { + return true; + } + + protected function buildHeraldAdapter( + PhabricatorLiskDAO $object, + array $xactions) { + return id(new HeraldRuleAdapter()) + ->setRule($object); + } + + protected function shouldSendMail( + PhabricatorLiskDAO $object, + array $xactions) { + return true; + } + + protected function getMailTo(PhabricatorLiskDAO $object) { + $phids = array(); + + $phids[] = $this->getActingAsPHID(); + + if ($object->isPersonalRule()) { + $phids[] = $object->getAuthorPHID(); + } + + return $phids; + } + + protected function buildReplyHandler(PhabricatorLiskDAO $object) { + return id(new HeraldRuleReplyHandler()) + ->setMailReceiver($object); + } + + protected function buildMailTemplate(PhabricatorLiskDAO $object) { + $monogram = $object->getMonogram(); + $name = $object->getName(); + + $subject = pht('%s: %s', $monogram, $name); + + return id(new PhabricatorMetaMTAMail()) + ->setSubject($subject); + } + + protected function getMailSubjectPrefix() { + return pht('[Herald]'); + } + } diff --git a/src/applications/herald/mail/HeraldRuleReplyHandler.php b/src/applications/herald/mail/HeraldRuleReplyHandler.php new file mode 100644 --- /dev/null +++ b/src/applications/herald/mail/HeraldRuleReplyHandler.php @@ -0,0 +1,16 @@ +