You are here

function _services_raw_user_update in Services Client 7.2

Same name and namespace in other branches
  1. 7 services_raw/services_raw.inc \_services_raw_user_update()

Update user account using user_save

Parameters

$uid:

$account: Account that should be created

Return value

array|mixed

1 string reference to '_services_raw_user_update'
_services_raw_services_resources in services_raw/services_raw.inc
Provides API definition of provided services objects and operations.

File

services_raw/services_raw.inc, line 783
Custom services definition and implementation of all callbacks.

Code

function _services_raw_user_update($uid, $account) {

  // Adds backwards compatibility with regression fixed in #1083242
  $account = _services_arg_value($account, 'data');
  $original_account = user_load($uid);
  $account['uid'] = $uid;
  try {
    $account_raw = $account;
    if (!($account = user_save($original_account, $account))) {
      return services_error(t("Error when saving user account."), 406);
    }

    // Password is automatically rehashed by user module, manual sql update is required
    if (!empty($account_raw['pass'])) {
      db_update('users')
        ->fields(array(
        'pass' => $account_raw['pass'],
      ))
        ->condition('uid', $account->uid, '=')
        ->execute();
    }
  } catch (Exception $e) {
    return services_error(t("Error when saving user account."), 406, array(
      'error' => $e
        ->getMessage(),
    ));
  }
  $result = array(
    'uid' => $account->uid,
  );
  if ($uri = services_resource_uri(array(
    'user',
    $account->uid,
  ))) {
    $result['uri'] = $uri;
  }
  return $result;
}