From 321121a119d133d3faf802efaa5d495346da07db Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 17 Feb 2015 17:06:29 -0800 Subject: [PATCH] CRM-15970 - Convert A/B test option-groups to simple arrays (backend) --- CRM/Mailing/PseudoConstant.php | 60 +++++++++++++++++++ .../Incremental/sql/4.6.alpha7.mysql.tpl | 16 ++++- tests/phpunit/api/v3/MailingABTest.php | 4 +- xml/schema/Mailing/MailingAB.xml | 21 +++---- xml/templates/civicrm_data.tpl | 25 +------- 5 files changed, 90 insertions(+), 36 deletions(-) diff --git a/CRM/Mailing/PseudoConstant.php b/CRM/Mailing/PseudoConstant.php index 12e4889142..dad74ca0c8 100644 --- a/CRM/Mailing/PseudoConstant.php +++ b/CRM/Mailing/PseudoConstant.php @@ -39,6 +39,24 @@ */ class CRM_Mailing_PseudoConstant extends CRM_Core_PseudoConstant { + /** + * Status options for A/B tests. + * @var array + */ + private static $abStatus; + + /** + * Test criteria for A/B tests. + * @var array + */ + private static $abTestCriteria; + + /** + * Winner criteria for A/B tests. + * @var array + */ + private static $abWinnerCriteria; + /** * Mailing templates * @var array @@ -62,6 +80,48 @@ class CRM_Mailing_PseudoConstant extends CRM_Core_PseudoConstant { */ private static $defaultComponent; + /** + * @return array + */ + public static function abStatus() { + if (!is_array(self::$abStatus)) { + self::$abStatus = array( + 'Draft' => ts('Draft'), + 'Testing' => ts('Testing'), + 'Final' => ts('Final'), + ); + } + return self::$abStatus; + } + + /** + * @return array + */ + public static function abTestCriteria() { + if (!is_array(self::$abTestCriteria)) { + self::$abTestCriteria = array( + 'subject' => ts('Test different "Subject" lines'), + 'from' => ts('Test different "From" lines'), + 'full_email' => ts('Test entirely different emails'), + ); + } + return self::$abTestCriteria; + } + + /** + * @return array + */ + public static function abWinnerCriteria() { + if (!is_array(self::$abWinnerCriteria)) { + self::$abWinnerCriteria = array( + 'open' => ts('Open'), + 'unique_click' => ts('Total Unique Clicks'), + 'link_click' => ts('Total Clicks on a particular link'), + ); + } + return self::$abWinnerCriteria; + } + /** * Get all the mailing components of a particular type. * diff --git a/CRM/Upgrade/Incremental/sql/4.6.alpha7.mysql.tpl b/CRM/Upgrade/Incremental/sql/4.6.alpha7.mysql.tpl index 3109a25886..b915ce303a 100644 --- a/CRM/Upgrade/Incremental/sql/4.6.alpha7.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/4.6.alpha7.mysql.tpl @@ -3,9 +3,23 @@ -- location_type_id should have default NULL, not invalid id 0 ALTER TABLE civicrm_mailing CHANGE `location_type_id` `location_type_id` int(10) unsigned DEFAULT NULL COMMENT 'With email_selection_method, determines which email address to use'; - -- CRM-15970 - Track authorship of of A/B tests ALTER TABLE civicrm_mailing_abtest ADD COLUMN `created_id` int unsigned COMMENT 'FK to Contact ID', ADD COLUMN `created_date` datetime COMMENT 'When was this item created', + ADD COLUMN `testing_criteria` varchar(32) COLLATE utf8_unicode_ci DEFAULT NULL, + ADD COLUMN `winner_criteria` varchar(32) COLLATE utf8_unicode_ci DEFAULT NULL, ADD CONSTRAINT FK_civicrm_mailing_abtest_created_id FOREIGN KEY (`created_id`) REFERENCES `civicrm_contact`(`id`) ON DELETE SET NULL; + +-- Move A/B test option-values into code +DELETE FROM civicrm_option_group WHERE name IN ('mailing_ab_status', 'mailing_ab_testing_criteria', 'mailing_ab_winner_criteria'); +UPDATE civicrm_mailing_abtest SET testing_criteria = 'subject' WHERE testing_criteria_id = 1; +UPDATE civicrm_mailing_abtest SET testing_criteria = 'from' WHERE testing_criteria_id = 2; +UPDATE civicrm_mailing_abtest SET testing_criteria = 'full_email' WHERE testing_criteria_id = 3; +UPDATE civicrm_mailing_abtest SET winner_criteria = 'open' WHERE winner_criteria_id = 1; +UPDATE civicrm_mailing_abtest SET winner_criteria = 'unique_click' WHERE winner_criteria_id = 2; +UPDATE civicrm_mailing_abtest SET winner_criteria = 'link_click' WHERE winner_criteria_id = 3; + +ALTER TABLE civicrm_mailing_abtest + DROP COLUMN `testing_criteria_id`, + DROP COLUMN `winner_criteria_id`; diff --git a/tests/phpunit/api/v3/MailingABTest.php b/tests/phpunit/api/v3/MailingABTest.php index e317b60e47..17a81166cc 100755 --- a/tests/phpunit/api/v3/MailingABTest.php +++ b/tests/phpunit/api/v3/MailingABTest.php @@ -53,8 +53,8 @@ class api_v3_MailingABTest extends CiviUnitTestCase { 'mailing_id_a' => $this->_mailingID_A, 'mailing_id_b' => $this->_mailingID_B, 'mailing_id_c' => $this->_mailingID_C, - 'testing_criteria_id' => 1, - 'winner_criteria_id' => 1, + 'testing_criteria' => 'subject', + 'winner_criteria' => 'open', 'declare_winning_time' => '+2 days', 'group_percentage' => 10, ); diff --git a/xml/schema/Mailing/MailingAB.xml b/xml/schema/Mailing/MailingAB.xml index e965535603..8256aea135 100644 --- a/xml/schema/Mailing/MailingAB.xml +++ b/xml/schema/Mailing/MailingAB.xml @@ -31,8 +31,7 @@ Status Status - mailing_ab_status - name + CRM_Mailing_PseudoConstant::abStatus 4.6 @@ -65,20 +64,22 @@ 4.6 - testing_criteria_id - int unsigned - Testing Criteria ID + testing_criteria + varchar + 32 + Testing Criteria - mailing_ab_testing_criteria + CRM_Mailing_PseudoConstant::abTestCriteria 4.6 - winner_criteria_id - int unsigned - Winner Criteria ID + winner_criteria + varchar + 32 + Winner Criteria - mailing_ab_winner_criteria + CRM_Mailing_PseudoConstant::abWinnerCriteria 4.6 diff --git a/xml/templates/civicrm_data.tpl b/xml/templates/civicrm_data.tpl index def6d8e854..5bb218f0d4 100644 --- a/xml/templates/civicrm_data.tpl +++ b/xml/templates/civicrm_data.tpl @@ -208,10 +208,7 @@ VALUES ('name_badge' , '{ts escape="sql"}Name Badge Format{/ts}' , 1, 1, 0), ('communication_style' , '{ts escape="sql"}Communication Style{/ts}' , 1, 1, 0), ('msg_mode' , '{ts escape="sql"}Message Mode{/ts}' , 1, 1, 0), - ('contact_date_reminder_options' , '{ts escape="sql"}Contact Date Reminder Options{/ts}' , 1, 1, 1), - ('mailing_ab_status' , '{ts escape="sql"}Mailing A/B Status{/ts}' , 1, 1, 1), - ('mailing_ab_testing_criteria' , '{ts escape="sql"}Mailing A/B Testing Criteria{/ts}' , 1, 1, 1), - ('mailing_ab_winner_criteria' , '{ts escape="sql"}Mailing A/B Testing Winner Criteria{/ts}', 1, 1, 1); + ('contact_date_reminder_options' , '{ts escape="sql"}Contact Date Reminder Options{/ts}' , 1, 1, 1); SELECT @option_group_id_pcm := max(id) from civicrm_option_group where name = 'preferred_communication_method'; SELECT @option_group_id_act := max(id) from civicrm_option_group where name = 'activity_type'; @@ -289,9 +286,6 @@ SELECT @option_group_id_name_badge := max(id) from civicrm_option_group where na SELECT @option_group_id_communication_style := max(id) from civicrm_option_group where name = 'communication_style'; SELECT @option_group_id_msg_mode := max(id) from civicrm_option_group where name = 'msg_mode'; SELECT @option_group_id_contactDateMode := max(id) from civicrm_option_group where name = 'contact_date_reminder_options'; -SELECT @option_group_id_mailingABStatus := max(id) from civicrm_option_group where name = 'mailing_ab_status'; -SELECT @option_group_id_mailingABCriteria := max(id) from civicrm_option_group where name = 'mailing_ab_testing_criteria'; -SELECT @option_group_id_mailingABWinnerCriteria := max(id) from civicrm_option_group where name = 'mailing_ab_winner_criteria'; SELECT @contributeCompId := max(id) FROM civicrm_component where name = 'CiviContribute'; SELECT @eventCompId := max(id) FROM civicrm_component where name = 'CiviEvent'; @@ -951,22 +945,7 @@ VALUES -- Reminder Options for Contact Date Fields (@option_group_id_contactDateMode, '{ts escape="sql"}Actual date only{/ts}', '1', 'Actual date only', NULL, NULL, 0, 1, NULL, 0, 1, 1, NULL, NULL), -(@option_group_id_contactDateMode, '{ts escape="sql"}Each anniversary{/ts}', '2', 'Each anniversary', NULL, NULL, 0, 2, NULL, 0, 1, 1, NULL, NULL), - --- Mailing A/B Status -(@option_group_id_mailingABStatus, '{ts escape="sql"}Draft{/ts}', '1', 'Draft', NULL, NULL, 0, 1, NULL, 0, 1, 1, NULL, NULL), -(@option_group_id_mailingABStatus, '{ts escape="sql"}Testing{/ts}', '2', 'Testing', NULL, NULL, 0, 1, NULL, 0, 1, 1, NULL, NULL), -(@option_group_id_mailingABStatus, '{ts escape="sql"}Final{/ts}', '3', 'Final', NULL, NULL, 0, 1, NULL, 0, 1, 1, NULL, NULL), - --- Mailing A/B Testing Winner Criteria -(@option_group_id_mailingABWinnerCriteria, '{ts escape="sql"}Open{/ts}', '1', 'Open', NULL, NULL, 0, 1, NULL, 0, 1, 1, NULL, NULL), -(@option_group_id_mailingABWinnerCriteria, '{ts escape="sql"}Total Unique Clicks{/ts}', '2', 'Total Unique Clicks', NULL, NULL, 0, 2, NULL, 0, 1, 1, NULL, NULL), -(@option_group_id_mailingABWinnerCriteria, '{ts escape="sql"}Total Clicks on a particular link{/ts}', '3', 'Total Clicks on a particular link', NULL, NULL, 0, 3, NULL, 0, 1, 1, NULL, NULL), - --- Mailing A/B Testing Criteria -(@option_group_id_mailingABCriteria, '{ts escape="sql"}Subject Lines {/ts}', '1', 'Subject Lines', NULL, NULL, 0, 1, NULL, 0, 1, 1, NULL, NULL), -(@option_group_id_mailingABCriteria, '{ts escape="sql"}From Names {/ts}', '2', 'From Names', NULL, NULL, 0, 2, NULL, 0, 1, 1, NULL, NULL), -(@option_group_id_mailingABCriteria, '{ts escape="sql"}Two different Emails {/ts}', '3', 'Two different Emails ', NULL, NULL, 0, 3, NULL, 0, 1, 1, NULL, NULL); +(@option_group_id_contactDateMode, '{ts escape="sql"}Each anniversary{/ts}', '2', 'Each anniversary', NULL, NULL, 0, 2, NULL, 0, 1, 1, NULL, NULL); -- financial accounts SELECT @opval := value FROM civicrm_option_value WHERE name = 'Revenue' and option_group_id = @option_group_id_fat; -- 2.25.1