You are here

function acquia_lift_profiles_update_7002 in Acquia Lift Connector 7.2

Same name and namespace in other branches
  1. 7 acquia_lift_profiles/acquia_lift_profiles.install \acquia_lift_profiles_update_7002()

Ensure all defined visitor actions are sync'd to Lift Web.

File

acquia_lift_profiles/acquia_lift_profiles.install, line 110
Acquia Lift Profiles - Installation file.

Code

function acquia_lift_profiles_update_7002(&$sandbox) {
  drupal_load('module', 'acquia_lift_profiles');

  // Nothing to be done if the module hasn't been configured yet.
  if (!acquia_lift_profiles_is_configured(TRUE)) {
    return;
  }

  // We need actions defined in code as well as those in the db.
  $actions = module_invoke_all('visitor_actions_info');
  $result = db_query('SELECT machine_name, label FROM {visitor_actions_actions}');
  foreach ($result as $row) {
    $actions[$row->machine_name] = array(
      'machine_name' => $row->machine_name,
      'label' => $row->label,
    );
  }
  if (empty($actions)) {
    return;
  }

  // This update hook could get run when this module and all its dependencies
  // are disabled, so we need to explicitly load all the files we need.
  module_load_include('inc', 'personalize', 'includes/personalize.classes');
  module_load_include('inc', 'acquia_lift', 'includes/acquia_lift.classes');
  module_load_include('inc', 'acquia_lift_profiles', 'includes/acquia_lift_profiles.classes');
  $action_names = array_keys($actions);
  if (!isset($sandbox['progress'])) {

    // The count of actions processed so far.
    $sandbox['progress'] = 0;

    // Total actions that must be sync'd.
    $sandbox['max'] = count($actions);

    // Last action processed.
    $sandbox['current_action'] = 0;
  }

  // Process each action separately
  $action_name = $action_names[$sandbox['current_action']];
  $action = $actions[$action_name];
  $errors = array();
  acquia_lift_profiles_put_action($action['action_name'], $action['label'], $errors);

  // Update our progress information.
  $sandbox['progress']++;
  $sandbox['current_action']++;

  // Set the "finished" status, to tell batch engine whether this function
  // needs to run again. If you set a float, this will indicate the progress
  // of the batch so the progress bar will update.
  $sandbox['#finished'] = $sandbox['progress'] >= $sandbox['max'] ? TRUE : $sandbox['progress'] / $sandbox['max'];
  if ($sandbox['#finished']) {
    return t('All actions were synchronized to Lift Web');
  }
}