You are here

account_sync.sender.inc in Account Sync 6

Same filename and directory in other branches
  1. 7.2 account_sync.sender.inc

Handler inc for sending account data to other sites

File

account_sync.sender.inc
View source
<?php

/**
 * @file
 * Handler inc for sending account data to other sites
 */
function account_sync_send_update($op, &$edit, $account, $category = NULL) {
  global $_account_sync_;
  static $original_username;

  // Ensure syncing is enabled and check the account_sync flag (no recursion)
  if (!variable_get('account_sync_enabled', FALSE) || $_account_sync_) {
    return;
  }

  // Only supports basic profile information right now
  if ($op == 'after_update' || $op == 'insert') {
    _account_sync_send_update($edit, $account, $category, $original_username);
  }
  elseif ($op == 'update') {

    // Save the original username so that if it's changed it can still be
    // matched on the syncing sites.
    $original_username = $account->name;
  }
}
function _account_sync_send_update($edit, $account, $category, $username = NULL) {

  // Validate the category being updated
  if ($category != 'account' && !in_array($category, variable_get('account_sync_profile_categories', array()))) {
    return;
  }

  // Check sync account permission and don't sync user with uid 0 or
  // 1 (unless permitted)
  if (!$account->uid || !user_access('sync account', $account) || $account->uid == 1 && !variable_get('account_sync_uid1', FALSE)) {
    return;
  }

  // No need to send a plain text password across. It can be set using the md5.
  unset($edit['pass']);
  $data_sent = FALSE;

  // Flag to verify that account data was sent somewhere.
  // Send the data to all target servers
  foreach (account_sync_servers($account) as $server_url) {
    $results = xmlrpc($server_url . '/xmlrpc.php', 'account_sync.updateUser', variable_get('account_sync_server_key', ''), $username ? $username : $account->name, $edit, (array) $account, $category, user_roles());
    if ($errmsg = xmlrpc_error_msg()) {
      watchdog('account_sync', 'XMLRPC error received while syncing users to @server: ' . $errmsg, array(
        '@server' => $server_url,
      ), WATCHDOG_ERROR);
    }
    if (is_array($results)) {
      $data_sent = TRUE;
      $vars = is_array($results[2]) ? $results[2] : array();
      $vars['@server'] = $server_url;
      watchdog('account_sync', '@server: ' . $results[1], $vars, $results[0]);
    }
  }
  return $data_sent;
}

Functions

Namesort descending Description
account_sync_send_update @file Handler inc for sending account data to other sites
_account_sync_send_update