From e81bac46c1884203f179ddf9411041dd75a2bcda Mon Sep 17 00:00:00 2001 From: atif-shaikh Date: Tue, 3 Mar 2015 10:31:53 +0530 Subject: [PATCH] CRM-15979 - Differentiate standalone mailings from A/B test mailings ---------------------------------------- * CRM-15979: Differentiate standalone mailings from A/B test mailings https://issues.civicrm.org/jira/browse/CRM-15979 --- CRM/Mailing/BAO/MailingAB.php | 21 +++++++++++++++++++ CRM/Mailing/Controller/Send.php | 10 ++++++++- CRM/Mailing/Page/Report.php | 6 +++++- CRM/Mailing/PseudoConstant.php | 20 ++++++++++++++++++ .../Incremental/sql/4.6.beta2.mysql.tpl | 16 +++++++++++++- api/v3/Mailing.php | 4 ++++ js/angular-crmMailingAB/services.js | 4 +++- xml/schema/Mailing/Mailing.xml | 14 +++++++++++++ 8 files changed, 91 insertions(+), 4 deletions(-) diff --git a/CRM/Mailing/BAO/MailingAB.php b/CRM/Mailing/BAO/MailingAB.php index f56c74cd9e..89c1f9050b 100644 --- a/CRM/Mailing/BAO/MailingAB.php +++ b/CRM/Mailing/BAO/MailingAB.php @@ -164,4 +164,25 @@ class CRM_Mailing_BAO_MailingAB extends CRM_Mailing_DAO_MailingAB { } + /** + * get abtest based on Mailing ID + * + * @param int $mailingID + * Mailing ID. + * + * @return int + */ + + public static function getABTest($mailingID) { + $query = "SELECT * FROM `civicrm_mailing_abtest` ab + where (ab.mailing_id_a = %1 + OR ab.mailing_id_b = %1 + OR ab.mailing_id_c = %1) + GROUP BY ab.id"; + $params = array(1 => array($mailingID, 'Integer')); + $abTest = CRM_Core_DAO::executeQuery($query, $params); + $abTest->fetch(); + return $abTest; + } + } diff --git a/CRM/Mailing/Controller/Send.php b/CRM/Mailing/Controller/Send.php index 153e89eabb..e620c95cb6 100644 --- a/CRM/Mailing/Controller/Send.php +++ b/CRM/Mailing/Controller/Send.php @@ -56,8 +56,16 @@ class CRM_Mailing_Controller_Send extends CRM_Core_Controller { CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/a/', NULL, TRUE, '/mailing/new')); } if ($mid && $continue) { - CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/a/', NULL, TRUE, '/mailing/' . $mid)); + //CRM-15979 - check if abtest exist for mailing then redirect accordingly + $abtest = CRM_Mailing_BAO_MailingAB::getABTest($mid); + if (!empty($abtest) && !empty($abtest->id)) { + $redirect = CRM_Utils_System::url('civicrm/a/', NULL, TRUE, '/abtest/' . $abtest->id); + } + else { + $redirect = CRM_Utils_System::url('civicrm/a/', NULL, TRUE, '/mailing/' . $mid); + } } + CRM_Utils_System::redirect($redirect); if ($mid && !$continue) { CRM_Core_Error::fatal('Not implemented: Re-use mailing'); // CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/a/', NULL, TRUE, '/mailing/' . $mid)); diff --git a/CRM/Mailing/Page/Report.php b/CRM/Mailing/Page/Report.php index 03adcfa276..c7a639bd7c 100644 --- a/CRM/Mailing/Page/Report.php +++ b/CRM/Mailing/Page/Report.php @@ -97,7 +97,11 @@ class CRM_Mailing_Page_Report extends CRM_Core_Page_Basic { */ public function run() { $this->_mailing_id = CRM_Utils_Request::retrieve('mid', 'Positive', $this); - + //CRM-15979 - check if abtest exist for mailing then redirect accordingly + $abtest = CRM_Mailing_BAO_MailingAB::getABTest($this->_mailing_id); + if (!empty($abtest) && !empty($abtest->id)) { + CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/a/', NULL, TRUE, '/abtest/' . $abtest->id)); + } // check that the user has permission to access mailing id CRM_Mailing_BAO_Mailing::checkPermission($this->_mailing_id); diff --git a/CRM/Mailing/PseudoConstant.php b/CRM/Mailing/PseudoConstant.php index dad74ca0c8..3cc11c0ca9 100644 --- a/CRM/Mailing/PseudoConstant.php +++ b/CRM/Mailing/PseudoConstant.php @@ -80,6 +80,12 @@ class CRM_Mailing_PseudoConstant extends CRM_Core_PseudoConstant { */ private static $defaultComponent; + /** + * Mailing Types + * @var array + */ + private static $mailingTypes; + /** * @return array */ @@ -122,6 +128,20 @@ class CRM_Mailing_PseudoConstant extends CRM_Core_PseudoConstant { return self::$abWinnerCriteria; } + /** + * @return array + */ + public static function mailingTypes() { + if (!is_array(self::$mailingTypes)) { + self::$mailingTypes = array( + 'standalone' => ts('Standalone'), + 'experiment' => ts('Experimental'), + 'winner' => ts('Winner'), + ); + } + return self::$mailingTypes; + } + /** * Get all the mailing components of a particular type. * diff --git a/CRM/Upgrade/Incremental/sql/4.6.beta2.mysql.tpl b/CRM/Upgrade/Incremental/sql/4.6.beta2.mysql.tpl index 4ed06c94ec..f2f5139464 100644 --- a/CRM/Upgrade/Incremental/sql/4.6.beta2.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/4.6.beta2.mysql.tpl @@ -5,4 +5,18 @@ ALTER TABLE `civicrm_membership_block` CHANGE `membership_types` `membership_ -- CRM-15578 Require access CiviMail permission for A/B Testing feature UPDATE civicrm_navigation SET permission = 'access CivMail', permission_operator = '' -WHERE name = 'New A/B Test' OR name = 'Manage A/B Tests' \ No newline at end of file +WHERE name = 'New A/B Test' OR name = 'Manage A/B Tests' +{*--CRM-15979 - differentiate between standalone mailings, A/B tests, and A/B final-winner *} +ALTER TABLE `civicrm_mailing` ADD mailing_type varchar(32) CHARACTER SET utf8 COLLATE utf8_unicode_ci COMMENT 'differentiate between standalone mailings, A/B tests, and A/B final-winner'; + +UPDATE `civicrm_mailing`cm +LEFT JOIN civicrm_mailing_abtest ab +ON cm.id = ab.mailing_id_a + OR cm.id = ab.mailing_id_b + OR cm.id = ab.mailing_id_c + SET `mailing_type` = CASE + WHEN cm.id IN (ab.mailing_id_a,ab.mailing_id_b) THEN 'experiment' + WHEN cm.id IN (ab.mailing_id_c) THEN 'winner' + ELSE 'standalone' + END +WHERE cm.id IS NOT NULL diff --git a/api/v3/Mailing.php b/api/v3/Mailing.php index 5d4e060802..3656a15948 100755 --- a/api/v3/Mailing.php +++ b/api/v3/Mailing.php @@ -64,7 +64,11 @@ function civicrm_api3_mailing_create($params) { $safeParams = $params; } $safeParams['_evil_bao_validator_'] = 'CRM_Mailing_BAO_Mailing::checkSendable'; + if (empty($params['mailing_type'])) { + $params['mailing_type'] = 'standalone'; + } return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $safeParams); + } /** diff --git a/js/angular-crmMailingAB/services.js b/js/angular-crmMailingAB/services.js index c9c14b9a56..67345291da 100644 --- a/js/angular-crmMailingAB/services.js +++ b/js/angular-crmMailingAB/services.js @@ -80,10 +80,12 @@ // Most defaults provided by Mailing.create API, but we // want to force-enable tracking. open_tracking: "1", - url_tracking: "1" + url_tracking: "1", + mailing_type:"experiment", }; crmMailingAB.mailings.a = crmMailingMgr.create(mailingDefaults); crmMailingAB.mailings.b = crmMailingMgr.create(mailingDefaults); + mailingDefaults.mailing_type = 'winner'; crmMailingAB.mailings.c = crmMailingMgr.create(mailingDefaults); crmMailingAB.attachments.a = new CrmAttachments(function () { return {entity_table: 'civicrm_mailing', entity_id: crmMailingAB.ab.mailing_id_a}; diff --git a/xml/schema/Mailing/Mailing.xml b/xml/schema/Mailing/Mailing.xml index a92582723b..ca61d15cc3 100644 --- a/xml/schema/Mailing/Mailing.xml +++ b/xml/schema/Mailing/Mailing.xml @@ -116,6 +116,20 @@ Text + + mailing_type + varchar + Mailing Type + 32 + differentiate between standalone mailings, A/B tests, and A/B final-winner + + CRM_Mailing_PseudoConstant::mailingTypes + + 4.6 + + Select + + from_name Mailing From Name -- 2.25.1