You are here

function _services_raw_user_update in Services Client 7

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

Update user account using user_save

Parameters

$uid:

$account: Account that should be created

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 746
Custom services definition and implementation of all callbacks.

Code

function _services_raw_user_update($uid, $account) {

  // Adds backwards compatability 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);
    }

    // @TODO: REMOVE
    watchdog('cci_services_raw', 'Update user: Retrieved: <pre>@retrieved</pre> Saved: <pre>@saved</pre>', array(
      '@retrieved' => print_r($account_raw, TRUE),
      '@saved' => print_r($account, TRUE),
    ), WATCHDOG_NOTICE);

    // @TODO: /REMOVE
    // 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;
}