You are here

function acquia_lift_personalize_goal_delete in Acquia Lift Connector 7

Implements hook_personalize_goal_delete().

File

./acquia_lift.module, line 904
acquia_lift.module Provides Acquia Lift-specific personalization functionality.

Code

function acquia_lift_personalize_goal_delete($goal_info) {
  $agent = personalize_agent_load($goal_info['agent']);
  if (!acquia_lift_is_testing_agent($agent)) {
    return;
  }
  $old_goals = isset($agent->data['goals']) ? $agent->data['goals'] : array();
  $new_goals = array();
  $goals = personalize_goal_load_by_conditions(array(
    'agent' => $agent->machine_name,
  ));
  foreach ($goals as $goal) {
    $new_goals[$goal->action] = $goal->value;
  }
  if (isset($new_goals[$goal_info['action']])) {
    unset($new_goals[$goal_info['action']]);
  }
  acquia_lift_sync_goals($agent, $old_goals, $new_goals, TRUE);

  // Clear the verified status of the agent.
  acquia_lift_agent_clear_verified_status($agent->machine_name);

  // If we now have no goals, the agent needs to be paused.
  if (count($new_goals) == 0) {
    personalize_pause_if_running($agent->machine_name);
  }
}