}
+ /**
+ * 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;
+ }
+
}
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));
*/
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);
*/
private static $defaultComponent;
+ /**
+ * Mailing Types
+ * @var array
+ */
+ private static $mailingTypes;
+
/**
* @return array
*/
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.
*
-- 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
$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);
+
}
/**
// 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};
<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>