From 9f220995b246a5da8823977ddcc03f37957d1d5d Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 6 Jul 2015 13:16:26 -0700 Subject: [PATCH] Modularize Application Email Herald field Summary: Ref T8726. There's no interface we can check for this, so the adapter needs to opt in. Also fix a spelling mistake. Test Plan: Created rules with "Application Email" fields. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T8726 Differential Revision: https://secure.phabricator.com/D13499 --- .../sql/autopatches/20150630.herald.1.sql | 5 +++ src/__phutil_library_map__.php | 2 + .../herald/adapter/HeraldAdapter.php | 28 +++---------- .../adapter/HeraldManiphestTaskAdapter.php | 5 ++- ...atorMetaMTAApplicationEmailHeraldField.php | 41 +++++++++++++++++++ 5 files changed, 57 insertions(+), 24 deletions(-) create mode 100644 resources/sql/autopatches/20150630.herald.1.sql create mode 100644 src/applications/metamta/herald/PhabricatorMetaMTAApplicationEmailHeraldField.php diff --git a/resources/sql/autopatches/20150630.herald.1.sql b/resources/sql/autopatches/20150630.herald.1.sql new file mode 100644 index 0000000000..e06532f640 --- /dev/null +++ b/resources/sql/autopatches/20150630.herald.1.sql @@ -0,0 +1,5 @@ +# NOTE: This is a spelling correction. + +UPDATE {$NAMESPACE}_herald.herald_condition + SET fieldName = 'application-email' + WHERE fieldName = 'applicaton-email'; diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index b46ffd5d07..2bb7a55ff3 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2112,6 +2112,7 @@ phutil_register_library_map(array( 'PhabricatorMetaMTAApplicationEmail' => 'applications/metamta/storage/PhabricatorMetaMTAApplicationEmail.php', 'PhabricatorMetaMTAApplicationEmailDatasource' => 'applications/metamta/typeahead/PhabricatorMetaMTAApplicationEmailDatasource.php', 'PhabricatorMetaMTAApplicationEmailEditor' => 'applications/metamta/editor/PhabricatorMetaMTAApplicationEmailEditor.php', + 'PhabricatorMetaMTAApplicationEmailHeraldField' => 'applications/metamta/herald/PhabricatorMetaMTAApplicationEmailHeraldField.php', 'PhabricatorMetaMTAApplicationEmailPHIDType' => 'applications/phid/PhabricatorMetaMTAApplicationEmailPHIDType.php', 'PhabricatorMetaMTAApplicationEmailPanel' => 'applications/metamta/applicationpanel/PhabricatorMetaMTAApplicationEmailPanel.php', 'PhabricatorMetaMTAApplicationEmailQuery' => 'applications/metamta/query/PhabricatorMetaMTAApplicationEmailQuery.php', @@ -5800,6 +5801,7 @@ phutil_register_library_map(array( ), 'PhabricatorMetaMTAApplicationEmailDatasource' => 'PhabricatorTypeaheadDatasource', 'PhabricatorMetaMTAApplicationEmailEditor' => 'PhabricatorApplicationTransactionEditor', + 'PhabricatorMetaMTAApplicationEmailHeraldField' => 'HeraldField', 'PhabricatorMetaMTAApplicationEmailPHIDType' => 'PhabricatorPHIDType', 'PhabricatorMetaMTAApplicationEmailPanel' => 'PhabricatorApplicationConfigurationPanel', 'PhabricatorMetaMTAApplicationEmailQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', diff --git a/src/applications/herald/adapter/HeraldAdapter.php b/src/applications/herald/adapter/HeraldAdapter.php index 4dbfe2281a..ec81de055c 100644 --- a/src/applications/herald/adapter/HeraldAdapter.php +++ b/src/applications/herald/adapter/HeraldAdapter.php @@ -29,7 +29,6 @@ abstract class HeraldAdapter extends Phobject { const FIELD_BRANCHES = 'branches'; const FIELD_AUTHOR_RAW = 'author-raw'; const FIELD_COMMITTER_RAW = 'committer-raw'; - const FIELD_APPLICATION_EMAIL = 'applicaton-email'; const FIELD_TASK_PRIORITY = 'taskpriority'; const FIELD_TASK_STATUS = 'taskstatus'; const FIELD_PUSHER_IS_COMMITTER = 'pusher-is-committer'; @@ -164,6 +163,10 @@ abstract class HeraldAdapter extends Phobject { return $this; } + public function supportsApplicationEmail() { + return false; + } + public function setApplicationEmail( PhabricatorMetaMTAApplicationEmail $email) { $this->applicationEmail = $email; @@ -183,18 +186,7 @@ abstract class HeraldAdapter extends Phobject { return $impl->getHeraldFieldValue($this->getObject()); } - switch ($field_name) { - case self::FIELD_APPLICATION_EMAIL: - $value = array(); - // while there is only one match by implementation, we do set - // comparisons on phids, so return an array with just the phid - if ($this->getApplicationEmail()) { - $value[] = $this->getApplicationEmail()->getPHID(); - } - return $value; - default: - throw new Exception(pht("Unknown field '%s'!", $field_name)); - } + throw new Exception(pht("Unknown field '%s'!", $field_name)); } abstract public function applyHeraldEffects(array $effects); @@ -391,7 +383,6 @@ abstract class HeraldAdapter extends Phobject { self::FIELD_BRANCHES => pht('Commit\'s branches'), self::FIELD_AUTHOR_RAW => pht('Raw author name'), self::FIELD_COMMITTER_RAW => pht('Raw committer name'), - self::FIELD_APPLICATION_EMAIL => pht('Receiving email address'), self::FIELD_TASK_PRIORITY => pht('Task priority'), self::FIELD_TASK_STATUS => pht('Task status'), self::FIELD_PUSHER_IS_COMMITTER => pht('Pusher same as committer'), @@ -481,13 +472,6 @@ abstract class HeraldAdapter extends Phobject { self::CONDITION_EXISTS, self::CONDITION_NOT_EXISTS, ); - case self::FIELD_APPLICATION_EMAIL: - return array( - self::CONDITION_INCLUDE_ANY, - self::CONDITION_INCLUDE_NONE, - self::CONDITION_EXISTS, - self::CONDITION_NOT_EXISTS, - ); case self::FIELD_DIFF_FILE: case self::FIELD_BRANCHES: return array( @@ -944,8 +928,6 @@ abstract class HeraldAdapter extends Phobject { return self::VALUE_PROJECT; case self::FIELD_REVIEWERS: return self::VALUE_USER_OR_PROJECT; - case self::FIELD_APPLICATION_EMAIL: - return self::VALUE_APPLICATION_EMAIL; default: return self::VALUE_USER; } diff --git a/src/applications/herald/adapter/HeraldManiphestTaskAdapter.php b/src/applications/herald/adapter/HeraldManiphestTaskAdapter.php index 451b84c6a2..391a261306 100644 --- a/src/applications/herald/adapter/HeraldManiphestTaskAdapter.php +++ b/src/applications/herald/adapter/HeraldManiphestTaskAdapter.php @@ -21,6 +21,10 @@ final class HeraldManiphestTaskAdapter extends HeraldAdapter { $this->task = $this->newObject(); } + public function supportsApplicationEmail() { + return true; + } + public function getRepetitionOptions() { return array( HeraldRepetitionPolicyConfig::EVERY, @@ -72,7 +76,6 @@ final class HeraldManiphestTaskAdapter extends HeraldAdapter { self::FIELD_ASSIGNEE, self::FIELD_TASK_PRIORITY, self::FIELD_TASK_STATUS, - self::FIELD_APPLICATION_EMAIL, ), parent::getFields()); } diff --git a/src/applications/metamta/herald/PhabricatorMetaMTAApplicationEmailHeraldField.php b/src/applications/metamta/herald/PhabricatorMetaMTAApplicationEmailHeraldField.php new file mode 100644 index 0000000000..8f8c985cf9 --- /dev/null +++ b/src/applications/metamta/herald/PhabricatorMetaMTAApplicationEmailHeraldField.php @@ -0,0 +1,41 @@ +getAdapter()->supportsApplicationEmail(); + } + + public function getHeraldFieldValue($object) { + $phids = array(); + + $email = $this->getAdapter()->getApplicationEmail(); + if ($email) { + $phids[] = $email; + } + + return $phids; + } + + protected function getHeraldFieldStandardConditions() { + return self::STANDARD_LIST; + } + + public function getHeraldFieldValueType($condition) { + switch ($condition) { + case HeraldAdapter::CONDITION_EXISTS: + case HeraldAdapter::CONDITION_NOT_EXISTS: + return HeraldAdapter::VALUE_NONE; + default: + return HeraldAdapter::VALUE_APPLICATION_EMAIL; + } + } + +}