diff --git a/src/applications/herald/adapter/HeraldAdapter.php b/src/applications/herald/adapter/HeraldAdapter.php index a478284231..b8a13a12ec 100644 --- a/src/applications/herald/adapter/HeraldAdapter.php +++ b/src/applications/herald/adapter/HeraldAdapter.php @@ -244,7 +244,7 @@ abstract class HeraldAdapter { } protected function newTransaction() { - $object = $this->getObject(); + $object = $this->newObject(); if (!($object instanceof PhabricatorApplicationTransactionInterface)) { throw new Exception( @@ -258,8 +258,6 @@ abstract class HeraldAdapter { } - - /** * NOTE: You generally should not override this; it exists to support legacy * adapters which had hard-coded content types. @@ -273,6 +271,26 @@ abstract class HeraldAdapter { abstract public function getAdapterApplicationClass(); abstract public function getObject(); + + /** + * Return a new characteristic object for this adapter. + * + * The adapter will use this object to test for interfaces, generate + * transactions, and interact with custom fields. + * + * Adapters must return an object from this method to enable custom + * field rules and various implicit actions. + * + * Normally, you'll return an empty version of the adapted object: + * + * return new ApplicationObject(); + * + * @return null|object Template object. + */ + protected function newObject() { + return null; + } + public function supportsRuleType($rule_type) { return false; } @@ -771,7 +789,19 @@ abstract class HeraldAdapter { public function getActions($rule_type) { $custom_actions = $this->getCustomActionsForRuleType($rule_type); - return mpull($custom_actions, 'getActionKey'); + $custom_actions = mpull($custom_actions, 'getActionKey'); + + $actions = $custom_actions; + + $object = $this->newObject(); + + if (($object instanceof PhabricatorProjectInterface)) { + if ($rule_type == HeraldRuleTypeConfig::RULE_TYPE_GLOBAL) { + $actions[] = self::ACTION_ADD_PROJECTS; + } + } + + return $actions; } public function getActionNameMap($rule_type) { @@ -1291,27 +1321,6 @@ abstract class HeraldAdapter { /* -( Custom Field Integration )------------------------------------------- */ - /** - * Return an object which custom fields can be generated from while editing - * rules. Adapters must return an object from this method to enable custom - * field rules. - * - * Normally, you'll return an empty version of the adapted object, assuming - * it implements @{interface:PhabricatorCustomFieldInterface}: - * - * return new ApplicationObject(); - * - * This is normally the only adapter method you need to override to enable - * Herald rules to run against custom fields. - * - * @return null|PhabricatorCustomFieldInterface Template object. - * @task customfield - */ - protected function getCustomFieldTemplateObject() { - return null; - } - - /** * Returns the prefix used to namespace Herald fields which are based on * custom fields. @@ -1363,8 +1372,8 @@ abstract class HeraldAdapter { $this->customFields = null; - $template_object = $this->getCustomFieldTemplateObject(); - if ($template_object) { + $template_object = $this->newObject(); + if ($template_object instanceof PhabricatorCustomFieldInterface) { $object = $this->getObject(); if (!$object) { $object = $template_object; diff --git a/src/applications/herald/adapter/HeraldCommitAdapter.php b/src/applications/herald/adapter/HeraldCommitAdapter.php index e697d99bbf..4ca916d13a 100644 --- a/src/applications/herald/adapter/HeraldCommitAdapter.php +++ b/src/applications/herald/adapter/HeraldCommitAdapter.php @@ -26,6 +26,10 @@ final class HeraldCommitAdapter extends HeraldAdapter { return 'PhabricatorDiffusionApplication'; } + public function newObject() { + return new PhabricatorRepositoryCommit(); + } + public function getObject() { return $this->commit; } diff --git a/src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php b/src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php index 28404744b1..3ad5c4722e 100644 --- a/src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php +++ b/src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php @@ -24,6 +24,10 @@ final class HeraldDifferentialRevisionAdapter return 'PhabricatorDifferentialApplication'; } + public function newObject() { + return new DifferentialRevision(); + } + public function getObject() { return $this->revision; } diff --git a/src/applications/herald/adapter/HeraldManiphestTaskAdapter.php b/src/applications/herald/adapter/HeraldManiphestTaskAdapter.php index f25d5fa296..cb4c7988c0 100644 --- a/src/applications/herald/adapter/HeraldManiphestTaskAdapter.php +++ b/src/applications/herald/adapter/HeraldManiphestTaskAdapter.php @@ -6,6 +6,10 @@ final class HeraldManiphestTaskAdapter extends HeraldAdapter { private $ccPHIDs = array(); private $assignPHID; + protected function newObject() { + return new ManiphestTask(); + } + public function getAdapterApplicationClass() { return 'PhabricatorManiphestApplication'; } @@ -90,7 +94,6 @@ final class HeraldManiphestTaskAdapter extends HeraldAdapter { self::ACTION_ADD_CC, self::ACTION_EMAIL, self::ACTION_ASSIGN_TASK, - self::ACTION_ADD_PROJECTS, self::ACTION_NOTHING, ), parent::getActions($rule_type)); @@ -180,8 +183,4 @@ final class HeraldManiphestTaskAdapter extends HeraldAdapter { return $result; } - protected function getCustomFieldTemplateObject() { - return new ManiphestTask(); - } - } diff --git a/src/applications/herald/adapter/HeraldPholioMockAdapter.php b/src/applications/herald/adapter/HeraldPholioMockAdapter.php index 974ac3e669..1ba96c56ed 100644 --- a/src/applications/herald/adapter/HeraldPholioMockAdapter.php +++ b/src/applications/herald/adapter/HeraldPholioMockAdapter.php @@ -13,6 +13,10 @@ final class HeraldPholioMockAdapter extends HeraldAdapter { return pht('React to mocks being created or updated.'); } + public function newObject() { + return new PholioMock(); + } + public function getObject() { return $this->mock; } diff --git a/src/applications/phriction/herald/PhrictionDocumentHeraldAdapter.php b/src/applications/phriction/herald/PhrictionDocumentHeraldAdapter.php index 0a14410ac2..3946f191cb 100644 --- a/src/applications/phriction/herald/PhrictionDocumentHeraldAdapter.php +++ b/src/applications/phriction/herald/PhrictionDocumentHeraldAdapter.php @@ -13,6 +13,10 @@ final class PhrictionDocumentHeraldAdapter extends HeraldAdapter { return pht('React to wiki documents being created or updated.'); } + public function newObject() { + return new PhrictionDocument(); + } + public function getObject() { return $this->document; }