You are here

function acquia_lift_ensure_default_agent in Acquia Lift Connector 7

Creates an Acquia Lift agent if none exists yet.

Does not yet create the agent on the Acquia Lift side as no decisions will have been set up for it yet.

1 call to acquia_lift_ensure_default_agent()
acquia_lift_admin_form_submit in ./acquia_lift.admin.inc
Submit handler for the Acquia Lift admin form.

File

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

Code

function acquia_lift_ensure_default_agent($account_info) {
  $agents = personalize_agent_load_by_type('acquia_lift');
  if (empty($agents)) {

    // Create a new agent. It will not get sent to Acquia Lift until it has
    // at least one option set added to it.
    $agent_data = new stdClass();
    $clean_site_name = drupal_clean_css_identifier(strtolower(variable_get('site_name')));
    $agent_name = ACQUIA_LIFT_DEFAULT_AGENT_NAME . '-' . $clean_site_name;

    // Although no Acquia Lift agents exist yet on the Drupal site, there may
    // be agents set up on the Acquia Lift side so we need to be sure not to
    // clash.
    $agent_name = AcquiaLiftAPI::getInstance($account_info)
      ->ensureUniqueAgentName($agent_name, PERSONALIZE_MACHINE_NAME_MAXLENGTH);
    $agent_data->machine_name = $agent_name;
    $agent_data->plugin = 'acquia_lift';
    $agent_data->label = 'Default Acquia Lift Agent';
    $agent_data->data = array(
      'decision_style' => 'adaptive',
    );
    personalize_agent_save($agent_data);
  }
}