function acquia_lift_implement_mvt in Acquia Lift Connector 7.2
Sets up a multivariate test as defined by the variation sets created.
2 calls to acquia_lift_implement_mvt()
- AcquiaLiftWebTestTarget::testMVTCreation in tests/
acquia_lift.test - acquia_lift_implement_test_structure in ./
acquia_lift.admin.inc - Implements the structure, including all sub-tests, required by the targeting.
File
- ./
acquia_lift.admin.inc, line 2080 - acquia_lift.admin.inc Provides functions needed for the admin UI.
Code
function acquia_lift_implement_mvt($agent) {
// There will only ever be one nested test for this campaign and it follows a
// naming convention (e.g. "{parent-campaign-name}-mvt"
$mvt_name = acquia_lift_get_mvt_name_for_agent($agent->machine_name);
// If this is our first time implementing this MVT, then the option sets will
// still be on the parent personalization and we'll need to move them.
$option_sets = personalize_option_set_load_by_agent($agent->machine_name);
if (empty($option_sets)) {
$option_sets = personalize_option_set_load_by_agent($mvt_name);
}
if (count($option_sets) < 2) {
throw new AcquiaLiftException('Cannot implement a multi-variate test with fewer than 2 variation sets');
}
$goals = array();
if ($mvt = personalize_agent_load($mvt_name)) {
$old_goals = personalize_goal_load_by_conditions(array(
'agent' => $mvt_name,
));
foreach ($old_goals as $goal) {
// This goal will get deleted so we'll just need to recreate it on the new
// agent.
$goal->id = NULL;
$goals[] = $goal;
}
// If this agent already exists delete it and recreate from scratch.
personalize_agent_delete($mvt_name);
// @todo Should it be deleted from Lift?
}
// Create a test agent for the MVT.
$mvt_agent = new stdClass();
$mvt_agent->label = 'MVT for ' . $agent->label;
$mvt_agent->plugin = ACQUIA_LIFT_TESTING_AGENT;
$mvt_agent->data = array();
$mvt_agent->machine_name = $mvt_name;
try {
personalize_agent_save($mvt_agent);
personalize_agent_set_status($mvt_name, PERSONALIZE_STATUS_RUNNING);
// Ensure the option sets are attached to the mvt, not the parent.
foreach ($option_sets as $os) {
$os->agent = $mvt_name;
$os->mvt = $mvt_name;
personalize_option_set_save($os);
}
// Ensure goals are attached to the mvt, not the parent.
$new_goals = personalize_goal_load_by_conditions(array(
'agent' => $agent->machine_name,
));
$goals += array_values($new_goals);
foreach ($goals as $goal) {
personalize_goal_save($mvt_name, $goal->action, $goal->value, $goal->id);
}
} catch (PersonalizeException $e) {
}
}