CRM-15979 - Differentiate standalone mailings from A/B test mailings
authoratif-shaikh <shaikh388@gmail.com>
Tue, 3 Mar 2015 05:01:53 +0000 (10:31 +0530)
committeratif-shaikh <shaikh388@gmail.com>
Thu, 5 Mar 2015 06:33:20 +0000 (12:03 +0530)
----------------------------------------
* CRM-15979: Differentiate standalone mailings from A/B test mailings
  https://issues.civicrm.org/jira/browse/CRM-15979

CRM/Mailing/BAO/MailingAB.php
CRM/Mailing/Controller/Send.php
CRM/Mailing/Page/Report.php
CRM/Mailing/PseudoConstant.php
CRM/Upgrade/Incremental/sql/4.6.beta2.mysql.tpl
api/v3/Mailing.php
js/angular-crmMailingAB/services.js
xml/schema/Mailing/Mailing.xml

index f56c74cd9e67648fc787284c8183b79750e23d08..89c1f9050bd47c06a422516166d8d7cf4e29e31d 100644 (file)
@@ -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;
+  }
+
 }
index 153e89eabbf28bb678862a6f25ee6aa19fa971d2..e620c95cb6eadad82cd5fdb8e9d79f27571baf2a 100644 (file)
@@ -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));
index 03adcfa276b77fc13a4bd56971c79ab8230a96e5..c7a639bd7c28f706d22c4dda3fe84ef672aac924 100644 (file)
@@ -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);
 
index dad74ca0c8b8527d53cadba07ea32a19ce3c9eef..3cc11c0ca915bea50f99ed4a9612d344cab04b5d 100644 (file)
@@ -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.
    *
index 4ed06c94ecc78eb93ee14363830685e6caedda93..f2f51394645949a461cdc3bfdf8cfccea3e138cf 100644 (file)
@@ -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
index 5d4e0608025638ea76c9850a15af3a9b4d7d9565..3656a159489226625e67b1aa02f1d4c114354a3e 100755 (executable)
@@ -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);
+
 }
 
 /**
index c9c14b9a56a47c8da98970182a111cd666f676b6..67345291dae4c9e624c2f57d04fb6fa39d65a0e6 100644 (file)
             // 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};
index a92582723b468ff4d5e2722705c5d74b38b80f01..ca61d15cc356796dab53e106dede6e43747419e1 100644 (file)
       <type>Text</type>
     </html>
   </field>
+  <field>
+    <name>mailing_type</name>
+    <type>varchar</type>
+    <title>Mailing Type</title>
+    <length>32</length>
+    <comment>differentiate between standalone mailings, A/B tests, and A/B final-winner</comment>
+    <pseudoconstant>
+      <callback>CRM_Mailing_PseudoConstant::mailingTypes</callback>
+    </pseudoconstant>
+    <add>4.6</add>
+    <html>
+      <type>Select</type>
+    </html>
+  </field>
   <field>
     <name>from_name</name>
     <title>Mailing From Name</title>