You are here

function acquia_lift_sync_goals in Acquia Lift Connector 7

Syncs an agents goals to Lift.

Parameters

$agent: The agent whose goals are being sync'd.

$old_goals: The old goals that Lift knows about.

$new_goals: The new goals.

bool $sync_only_on_changes: Whether to sync only if there are changes.

2 calls to acquia_lift_sync_goals()
acquia_lift_personalize_goal_delete in ./acquia_lift.module
Implements hook_personalize_goal_delete().
acquia_lift_personalize_goal_save in ./acquia_lift.module
Implements hook_personalize_goal_save().

File

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

Code

function acquia_lift_sync_goals($agent, $old_goals, $new_goals, $sync_only_on_changes = FALSE) {
  if ($sync_only_on_changes && $new_goals == $old_goals) {
    return;
  }
  if ($agent_instance = personalize_agent_load_agent($agent->machine_name)) {
    if (!$agent_instance instanceof AcquiaLiftAgentInterface) {
      return;
    }
    try {

      // Now tell Acquia Lift about the change to the goals.
      $agent_instance
        ->syncGoals($old_goals, $new_goals);

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