You are here

function acquia_lift_personalize_option_set_delete in Acquia Lift Connector 7

Same name and namespace in other branches
  1. 7.2 acquia_lift.module \acquia_lift_personalize_option_set_delete()

Implements hook_personalize_option_set_delete().

File

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

Code

function acquia_lift_personalize_option_set_delete($option_set) {
  $agent = personalize_agent_load($option_set->agent);
  if (!acquia_lift_is_testing_agent($agent)) {
    return;
  }

  // Acquia Lift agents store their option set info in the db so that they can
  // sync any changes with Acquia Lift.
  $old_option_sets = isset($agent->data['decisions']) ? $agent->data['decisions'] : array();

  // We can't rely on the fact that the only difference between what we previously
  // stored and the current set of option sets is the option set now being saved,
  // as option sets may have been altered outside of the save/delete api calls.
  // Reload the option sets for this agent.
  $new_option_sets = personalize_option_set_load_by_agent($agent->machine_name);

  // Take the data on this option set from what was passed in, rather than from the
  // db.
  if (isset($new_option_sets[$option_set->osid])) {
    unset($new_option_sets[$option_set->osid]);
  }
  acquia_lift_sync_option_sets($agent, $old_option_sets, $new_option_sets);
  acquia_lift_sync_fixed_targeting($agent, $new_option_sets);

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

  // The only reason deletion of the option set would mean the agent needs to be
  // paused is if there are no more option sets.
  if (count($new_option_sets) == 0) {
    personalize_pause_if_running($agent->machine_name);
  }
}