You are here

function acquia_lift_sync_option_sets in Acquia Lift Connector 7

Makes sure all option set changes are sync'd to Acquia Lift.

Parameters

$agent: The agent whose option sets have changed.

$old_option_sets: THe old option sets that Acquia Lift knew about.

$new_option_sets: The new option sets.

2 calls to acquia_lift_sync_option_sets()
acquia_lift_personalize_option_set_delete in ./acquia_lift.module
Implements hook_personalize_option_set_delete().
acquia_lift_personalize_option_set_save in ./acquia_lift.module
Implements hook_personalize_option_set_save().

File

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

Code

function acquia_lift_sync_option_sets($agent, $old_option_sets, $new_option_sets, $sync_only_on_changes = FALSE) {
  if ($agent_instance = personalize_agent_load_agent($agent->machine_name)) {
    if (!$agent_instance instanceof AcquiaLiftAgentInterface) {
      return;
    }
    try {

      // Tell Acquia Lift about the change to the decision structure.
      $old_decisions = AcquiaLiftAgent::convertOptionSetsToDecisions($old_option_sets);
      $new_decisions = AcquiaLiftAgent::convertOptionSetsToDecisions($new_option_sets);
      if (!$sync_only_on_changes || $old_decisions != $new_decisions) {
        $agent_instance
          ->syncDecisions($old_decisions, $new_decisions);
      }

      // Save the agent data to the db.
      $agent->data['decisions'] = $new_option_sets;
      personalize_agent_save($agent);
    } catch (Exception $e) {
      drupal_set_message($e
        ->getMessage(), 'error');
    }
  }
}