You are here

function acquia_lift_batch_finished in Acquia Lift Connector 7.2

Same name and namespace in other branches
  1. 7 acquia_lift.batch.inc \acquia_lift_batch_finished()

Batch API callback for when processing of all items is complete.

Parameters

$success: Whether or not the batch completed successfully.

$results: An array holding the results of each operation.

$operations: An array of unprocessed operations.

$next_status: An optional next status to set the campaign to, if a single campaign was being sync'd.

2 calls to acquia_lift_batch_finished()
acquia_lift_batch_finish_and_schedule_campaign in ./acquia_lift.batch.inc
Batch API callback that also schedules an agent after syncing items.
acquia_lift_batch_finish_and_start_campaign in ./acquia_lift.batch.inc
Batch API callback that also starts an agent after syncing items.
1 string reference to 'acquia_lift_batch_finished'
acquia_lift_batch_sync_tests_for_agent in ./acquia_lift.batch.inc
Batch syncs the nested tests for the specified agent.

File

./acquia_lift.batch.inc, line 169
acquia_lift.batch.inc

Code

function acquia_lift_batch_finished($success, $results, $operations, $elapsed_time, $next_status = NULL) {
  if ($success) {

    // See if any of the results contains an error.
    $errors = array();
    foreach ($results as $result) {
      if (strpos($result, ACQUIA_LIFT_OPERATION_ERROR_PREFIX) === 0) {
        $errors[] = substr($result, strlen(ACQUIA_LIFT_OPERATION_ERROR_PREFIX));
      }
    }
    if (empty($errors)) {
      if (!empty($next_status)) {
        if ($agent = $_SESSION['acquia_lift_agent_sync']) {
          $updated = personalize_agent_set_status($agent, $next_status);
          if ($updated && $next_status == PERSONALIZE_STATUS_RUNNING) {
            drupal_set_message(t('Congratulations! You have started your personalization.'));
          }
          else {
            if ($updated && $next_status == PERSONALIZE_STATUS_SCHEDULED) {
              module_load_include('inc', 'personalize', 'personalize.admin.campaign');
              $start_date = personalize_agent_get_start_date($agent);
              drupal_set_message(t('Congratulations!  You have scheduled your personalization to start on @date', array(
                '@date' => _personalize_campaign_wizard_date($start_date),
              )));
            }
          }
        }
      }
    }
    else {
      $message_type = 'error';
      $message = t('Some errors occurred while syncing personalizations to Acquia Lift:');
      $message .= theme('item_list', array(
        'items' => $errors,
      ));
      drupal_set_message($message, $message_type);
    }
  }
  if (isset($_SESSION['acquia_lift_agent_sync'])) {
    unset($_SESSION['acquia_lift_agent_sync']);
  }
}