You are here

function _account_sync_send_update in Account Sync 6

Same name and namespace in other branches
  1. 7.2 account_sync.sender.inc \_account_sync_send_update()
2 calls to _account_sync_send_update()
account_sync_send_update in ./account_sync.sender.inc
@file Handler inc for sending account data to other sites
account_sync_sync_all in ./account_sync.admin.inc

File

./account_sync.sender.inc, line 30
Handler inc for sending account data to other sites

Code

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;
}