diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 0026cb0..0155b10 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -3408,3 +3408,30 @@ function _drupal_shutdown_function() { } } } + +/** + * Forms an associative array from a linear array. + * + * This function walks through the provided array and constructs an associative + * array out of it. The keys of the resulting array will be the values of the + * input array. The values will be the same as the keys unless a function is + * specified, in which case the output of the function is used for the values + * instead. + * + * @param $array + * A linear array. + * @param $function + * A name of a function to apply to all values before output. + * + * @return + * An associative array. + */ +function drupal_map_assoc($array, $function = NULL) { + // array_combine() fails with empty arrays: + // http://bugs.php.net/bug.php?id=34857. + $array = !empty($array) ? array_combine($array, $array) : array(); + if (is_callable($function)) { + $array = array_map($function, $array); + } + return $array; +} \ No newline at end of file diff --git a/core/includes/common.inc b/core/includes/common.inc index 3d19d3e..f4190ed 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -2602,33 +2602,6 @@ function drupal_exit($destination = NULL) { } /** - * Forms an associative array from a linear array. - * - * This function walks through the provided array and constructs an associative - * array out of it. The keys of the resulting array will be the values of the - * input array. The values will be the same as the keys unless a function is - * specified, in which case the output of the function is used for the values - * instead. - * - * @param $array - * A linear array. - * @param $function - * A name of a function to apply to all values before output. - * - * @return - * An associative array. - */ -function drupal_map_assoc($array, $function = NULL) { - // array_combine() fails with empty arrays: - // http://bugs.php.net/bug.php?id=34857. - $array = !empty($array) ? array_combine($array, $array) : array(); - if (is_callable($function)) { - $array = array_map($function, $array); - } - return $array; -} - -/** * Attempts to set the PHP maximum execution time. * * This function is a wrapper around the PHP function set_time_limit(). @@ -7009,6 +6982,12 @@ function drupal_write_record($table, &$record, $primary_keys = array()) { $fields = array(); $default_fields = array(); + if (isset($object->picture)) { + //debug_print_backtrace(); + //exit(); + } + + // Go through the schema to determine fields to write. foreach ($schema['fields'] as $field => $info) { if ($info['type'] == 'serial') { diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index 6bdbf4d..d5786f9 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -1862,8 +1862,13 @@ function install_configure_form_submit($form, &$form_state) { // We precreated user 1 with placeholder values. Let's save the real values. $account = user_load(1); - $merge_data = array('init' => $form_state['values']['account']['mail'], 'roles' => !empty($account->roles) ? $account->roles : array(), 'status' => 1, 'timezone' => $form_state['values']['date_default_timezone']); - user_save($account, array_merge($form_state['values']['account'], $merge_data)); + $account->init = $account->mail = $form_state['values']['account']['mail']; + $account->roles = !empty($account->roles) ? $account->roles : array(); + $account->status = 1; + $account->timezone = $form_state['values']['date_default_timezone']; + $account->pass = $form_state['values']['account']['pass']; + $account->name = $form_state['values']['account']['name']; + $account->save(); // Load global $user and perform final login tasks. $user = user_load(1); user_login_finalize(); diff --git a/core/includes/password.inc b/core/includes/password.inc index b052a4a..eac2d20 100644 --- a/core/includes/password.inc +++ b/core/includes/password.inc @@ -228,6 +228,7 @@ function user_hash_password($password, $count_log2 = 0) { * TRUE or FALSE. */ function user_check_password($password, $account) { + debug($account->pass); if (substr($account->pass, 0, 2) == 'U$') { // This may be an updated password from user_update_7000(). Such hashes // have 'U' added as the first character and need an extra md5() (see the diff --git a/core/modules/block/block.module b/core/modules/block/block.module index 4d942ed..3a5694c 100644 --- a/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -631,9 +631,9 @@ function block_form_user_profile_form_alter(&$form, &$form_state) { /** * Implements hook_user_presave(). */ -function block_user_presave(&$edit, $account) { - if (isset($edit['block'])) { - $edit['data']['block'] = $edit['block']; +function block_user_presave(User $account) { + if (isset($account->block)) { + $account->data['block'] = $account->block; } } diff --git a/core/modules/block/block.test b/core/modules/block/block.test index dbd7dc4..6eb9ec6 100644 --- a/core/modules/block/block.test +++ b/core/modules/block/block.test @@ -513,8 +513,8 @@ class BlockCacheTestCase extends DrupalWebTestCase { $this->normal_user_alt = $this->drupalCreateUser(); // Sync the roles, since drupalCreateUser() creates separate roles for // the same permission sets. - user_save($this->normal_user_alt, array('roles' => $this->normal_user->roles)); $this->normal_user_alt->roles = $this->normal_user->roles; + user_save($this->normal_user_alt); // Enable our test block. $edit['blocks[block_test_test_cache][region]'] = 'sidebar_first'; diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index e5e636b..1a6ae0f 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -1381,7 +1381,7 @@ function comment_node_search_result($node) { /** * Implements hook_user_cancel(). */ -function comment_user_cancel($edit, $account, $method) { +function comment_user_cancel($edit, User $account, $method) { switch ($method) { case 'user_cancel_block_unpublish': $comments = comment_load_multiple(array(), array('uid' => $account->uid)); @@ -1404,7 +1404,7 @@ function comment_user_cancel($edit, $account, $method) { /** * Implements hook_user_predelete(). */ -function comment_user_predelete($account) { +function comment_user_predelete(User $account) { $cids = db_query('SELECT c.cid FROM {comment} c WHERE uid = :uid', array(':uid' => $account->uid))->fetchCol(); comment_delete_multiple($cids); } diff --git a/core/modules/contact/contact.module b/core/modules/contact/contact.module index b782c25..6569130 100644 --- a/core/modules/contact/contact.module +++ b/core/modules/contact/contact.module @@ -235,8 +235,8 @@ function contact_form_user_profile_form_alter(&$form, &$form_state) { /** * Implements hook_user_presave(). */ -function contact_user_presave(&$edit, $account) { - $edit['data']['contact'] = isset($edit['contact']) ? $edit['contact'] : variable_get('contact_default_status', 1); +function contact_user_presave(User $account) { + $account->data['contact'] = isset($account->contact) ? $account->contact : variable_get('contact_default_status', 1); } /** diff --git a/core/modules/contact/contact.test b/core/modules/contact/contact.test index 48c8bb0..2348332 100644 --- a/core/modules/contact/contact.test +++ b/core/modules/contact/contact.test @@ -374,7 +374,8 @@ class ContactPersonalTestCase extends DrupalWebTestCase { // Re-create our contacted user as a blocked user. $this->contact_user = $this->drupalCreateUser(); - user_save($this->contact_user, array('status' => 0)); + $this->contact_user->status = 0; + user_save($this->contact_user); // Test that blocked users can still be contacted by admin. $this->drupalGet('user/' . $this->contact_user->uid . '/contact'); diff --git a/core/modules/entity/entity.class.inc b/core/modules/entity/entity.class.inc index 1dec8ee..95ee37b 100644 --- a/core/modules/entity/entity.class.inc +++ b/core/modules/entity/entity.class.inc @@ -163,7 +163,11 @@ class Entity implements EntityInterface { * Sets up the object instance on construction or unserialization. */ protected function setUp() { - $this->entityInfo = entity_get_info($this->entityType); + // @todo: entity_get_info() is not yet defined if this function is called + // too early. This happens e.g. when saving entities with variable_set(). + if (function_exists('entity_get_info')) { + $this->entityInfo = entity_get_info($this->entityType); + } $this->idKey = $this->entityInfo['entity keys']['id']; $this->bundleKey = isset($this->entityInfo['entity keys']['bundle']) ? $this->entityInfo['entity keys']['bundle'] : NULL; } diff --git a/core/modules/entity/tests/entity_crud_hook_test.test b/core/modules/entity/tests/entity_crud_hook_test.test index 2bb459f..8630dac 100644 --- a/core/modules/entity/tests/entity_crud_hook_test.test +++ b/core/modules/entity/tests/entity_crud_hook_test.test @@ -347,16 +347,15 @@ class EntityCrudHookTestCase extends DrupalWebTestCase { * Test hook invocations for CRUD operations on users. */ public function testUserHooks() { - $edit = array( + $account = entity_create('user', array( 'name' => 'Test user', 'mail' => 'test@example.com', 'created' => REQUEST_TIME, 'status' => 1, 'language' => 'en', - ); - $account = (object) $edit; + )); $_SESSION['entity_crud_hook_test'] = array(); - $account = user_save($account, $edit); + $account = user_save($account); $this->assertHookMessageOrder(array( 'entity_crud_hook_test_user_presave called', @@ -366,7 +365,7 @@ class EntityCrudHookTestCase extends DrupalWebTestCase { )); $_SESSION['entity_crud_hook_test'] = array(); - $account = user_load($account->uid); + user_load($account->uid); $this->assertHookMessageOrder(array( 'entity_crud_hook_test_entity_load called for type user', @@ -374,8 +373,8 @@ class EntityCrudHookTestCase extends DrupalWebTestCase { )); $_SESSION['entity_crud_hook_test'] = array(); - $edit['name'] = 'New name'; - $account = user_save($account, $edit); + $account->name = 'New name'; + $account = user_save($account); $this->assertHookMessageOrder(array( 'entity_crud_hook_test_user_presave called', diff --git a/core/modules/file/tests/file.test b/core/modules/file/tests/file.test index 7ff738a..76c075a 100644 --- a/core/modules/file/tests/file.test +++ b/core/modules/file/tests/file.test @@ -703,9 +703,8 @@ class FileFieldRevisionTestCase extends FileFieldTestCase { // Attach the second file to a user. $user = $this->drupalCreateUser(); - $edit = (array) $user; - $edit[$field_name][LANGUAGE_NONE][0] = (array) $node_file_r3; - user_save($user, $edit); + $user->$field_name[LANGUAGE_NONE][0] = (array) $node_file_r3; + user_save($user); $this->drupalGet('user/' . $user->uid . '/edit'); // Delete the third revision and check that the file is not deleted yet. diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 2910e1a..41f4841 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -1792,7 +1792,7 @@ function node_ranking() { /** * Implements hook_user_cancel(). */ -function node_user_cancel($edit, $account, $method) { +function node_user_cancel($edit, User $account, $method) { switch ($method) { case 'user_cancel_block_unpublish': // Unpublish nodes (current revisions). @@ -1830,7 +1830,7 @@ function node_user_cancel($edit, $account, $method) { /** * Implements hook_user_predelete(). */ -function node_user_predelete($account) { +function node_user_predelete(User $account) { // Delete nodes (current revisions). // @todo Introduce node_mass_delete() or make node_mass_update() more flexible. $nodes = db_select('node', 'n') diff --git a/core/modules/openid/openid.module b/core/modules/openid/openid.module index 433ffee..6b2a118 100644 --- a/core/modules/openid/openid.module +++ b/core/modules/openid/openid.module @@ -83,15 +83,15 @@ function openid_help($path, $arg) { /** * Implements hook_user_insert(). */ -function openid_user_insert(&$edit, $account) { - if (!empty($edit['openid_claimed_id'])) { +function openid_user_insert(User $account) { + if (!empty($account->openid_claimed_id)) { // The user has registered after trying to log in via OpenID. if (variable_get('user_email_verification', TRUE)) { drupal_set_message(t('Once you have verified your e-mail address, you may log in via OpenID.')); } - user_set_authmaps($account, array('authname_openid' => $edit['openid_claimed_id'])); + user_set_authmaps($account, array('authname_openid' => $account->openid_claimed_id)); unset($_SESSION['openid']); - unset($edit['openid_claimed_id']); + unset($account->openid_claimed_id); } } @@ -100,7 +100,7 @@ function openid_user_insert(&$edit, $account) { * * Save openid_identifier to visitor cookie. */ -function openid_user_login(&$edit, $account) { +function openid_user_login(&$form_state, User $account) { if (isset($_SESSION['openid'])) { // The user has logged in via OpenID. user_cookie_save(array_intersect_key($_SESSION['openid']['user_login_values'], array_flip(array('openid_identifier')))); @@ -113,7 +113,7 @@ function openid_user_login(&$edit, $account) { * * Delete any openid_identifier in visitor cookie. */ -function openid_user_logout($account) { +function openid_user_logout(User $account) { if (isset($_COOKIE['Drupal_visitor_openid_identifier'])) { user_cookie_delete('openid_identifier'); } diff --git a/core/modules/openid/openid.test b/core/modules/openid/openid.test index 5c6ca69..115b50e 100644 --- a/core/modules/openid/openid.test +++ b/core/modules/openid/openid.test @@ -158,9 +158,9 @@ class OpenIDFunctionalTestCase extends OpenIDWebTestCase { $identity = url('openid-test/yadis/xrds', array('absolute' => TRUE)); $this->addIdentity($identity); $response = variable_get('openid_test_hook_openid_response_response'); - $account = variable_get('openid_test_hook_openid_response_account'); + $account_uid = variable_get('openid_test_hook_openid_response_account'); $this->assertEqual($response['openid.claimed_id'], $identity, t('hook_openid_response() was invoked.')); - $this->assertEqual($account->uid, $this->web_user->uid, t('Proper user object passed to hook_openid_response().')); + $this->assertEqual($account_uid, $this->web_user->uid, t('Proper user object passed to hook_openid_response().')); $this->drupalLogout(); @@ -170,9 +170,9 @@ class OpenIDFunctionalTestCase extends OpenIDWebTestCase { $this->submitLoginForm($identity); $this->assertLink(t('Log out'), 0, t('User was logged in.')); $response = variable_get('openid_test_hook_openid_response_response'); - $account = variable_get('openid_test_hook_openid_response_account'); + $account_uid = variable_get('openid_test_hook_openid_response_account'); $this->assertEqual($response['openid.claimed_id'], $identity, t('hook_openid_response() was invoked.')); - $this->assertEqual($account->uid, $this->web_user->uid, t('Proper user object passed to hook_openid_response().')); + $this->assertEqual($account_uid, $this->web_user->uid, t('Proper user object passed to hook_openid_response().')); $this->drupalLogout(); diff --git a/core/modules/openid/tests/openid_test.module b/core/modules/openid/tests/openid_test.module index 8b37d47..31f3e87 100644 --- a/core/modules/openid/tests/openid_test.module +++ b/core/modules/openid/tests/openid_test.module @@ -366,5 +366,5 @@ function openid_test_openid_request_alter(&$request, $service) { */ function openid_test_openid_response($response, $account) { variable_set('openid_test_hook_openid_response_response', $response); - variable_set('openid_test_hook_openid_response_account', $account ? $account : FALSE); + variable_set('openid_test_hook_openid_response_account', $account ? $account->uid : FALSE); } diff --git a/core/modules/overlay/overlay.module b/core/modules/overlay/overlay.module index 5433d3e..e814efd 100644 --- a/core/modules/overlay/overlay.module +++ b/core/modules/overlay/overlay.module @@ -102,9 +102,9 @@ function overlay_form_user_profile_form_alter(&$form, &$form_state) { /** * Implements hook_user_presave(). */ -function overlay_user_presave(&$edit, $account) { - if (isset($edit['overlay'])) { - $edit['data']['overlay'] = $edit['overlay']; +function overlay_user_presave(User $account) { + if (isset($account->overlay)) { + $account->data['overlay'] = $account->overlay; } } @@ -311,7 +311,9 @@ function overlay_user_dismiss_message() { return MENU_ACCESS_DENIED; } else { - user_save(user_load($user->uid), array('data' => array('overlay_message_dismissed' => 1))); + $account = user_load($user->uid); + $account->data['overlay_message_dismissed'] = 1; + user_save($account); drupal_set_message(t('The message has been dismissed. You can change your overlay settings at any time by visiting your profile page.')); // Destination is normally given. Go to the user profile as a fallback. drupal_goto('user/' . $user->uid . '/edit'); diff --git a/core/modules/poll/poll.module b/core/modules/poll/poll.module index ef19dd9..7ea2e8c 100644 --- a/core/modules/poll/poll.module +++ b/core/modules/poll/poll.module @@ -976,7 +976,7 @@ function poll_cancel($form, &$form_state) { /** * Implements hook_user_cancel(). */ -function poll_user_cancel($edit, $account, $method) { +function poll_user_cancel($edit, User $account, $method) { switch ($method) { case 'user_cancel_reassign': db_update('poll_vote') @@ -990,7 +990,7 @@ function poll_user_cancel($edit, $account, $method) { /** * Implements hook_user_predelete(). */ -function poll_user_predelete($account) { +function poll_user_predelete(User $account) { db_delete('poll_vote') ->condition('uid', $account->uid) ->execute(); diff --git a/core/modules/simpletest/drupal_web_test_case.php b/core/modules/simpletest/drupal_web_test_case.php index a5fb606..9bf9fe8 100644 --- a/core/modules/simpletest/drupal_web_test_case.php +++ b/core/modules/simpletest/drupal_web_test_case.php @@ -1123,7 +1123,8 @@ class DrupalWebTestCase extends DrupalTestCase { $edit['roles'] = array($rid => $rid); } - $account = user_save(drupal_anonymous_user(), $edit); + $account = entity_create('user', $edit); + $account->save(); $this->assertTrue(!empty($account->uid), t('User created with name %name and pass %pass', array('%name' => $edit['name'], '%pass' => $edit['pass'])), t('User login')); if (empty($account->uid)) { @@ -1227,7 +1228,7 @@ class DrupalWebTestCase extends DrupalTestCase { * * @see drupalCreateUser() */ - protected function drupalLogin(stdClass $user) { + protected function drupalLogin(User $user) { if ($this->loggedInUser) { $this->drupalLogout(); } diff --git a/core/modules/simpletest/tests/session.test b/core/modules/simpletest/tests/session.test index 846f6d3..b833189 100644 --- a/core/modules/simpletest/tests/session.test +++ b/core/modules/simpletest/tests/session.test @@ -41,8 +41,8 @@ class SessionTestCase extends DrupalWebTestCase { // Verify that the session is regenerated if a module calls exit // in hook_user_login(). - user_save($user, array('name' => 'session_test_user')); $user->name = 'session_test_user'; + user_save($user); $this->drupalGet('session-test/id'); $matches = array(); preg_match('/\s*session_id:(.*)\n/', $this->drupalGetContent(), $matches); @@ -455,7 +455,7 @@ class SessionHttpsTestCase extends DrupalWebTestCase { } } - // Test that session data saved before login is not available using the + // Test that session data saved before login is not available using the // pre-login anonymous cookie. $this->cookies = array(); $this->drupalGet('session-test/get', array('Cookie: ' . $anonymous_cookie)); diff --git a/core/modules/statistics/statistics.module b/core/modules/statistics/statistics.module index 191d82b..46ef633 100644 --- a/core/modules/statistics/statistics.module +++ b/core/modules/statistics/statistics.module @@ -206,7 +206,7 @@ function statistics_menu() { /** * Implements hook_user_cancel(). */ -function statistics_user_cancel($edit, $account, $method) { +function statistics_user_cancel($edit, User $account, $method) { switch ($method) { case 'user_cancel_reassign': db_update('accesslog') @@ -220,7 +220,7 @@ function statistics_user_cancel($edit, $account, $method) { /** * Implements hook_user_predelete(). */ -function statistics_user_predelete($account) { +function statistics_user_predelete(User $account) { db_delete('accesslog') ->condition('uid', $account->uid) ->execute(); diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 725cad7..a036fe4 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -1979,7 +1979,7 @@ function system_form_user_register_form_alter(&$form, &$form_state) { /** * Implements hook_user_insert(). */ -function system_user_presave(&$edit, $account) { +function system_user_presave(User $account) { if (variable_get('configurable_timezones', 1) && empty($account->timezone) && !variable_get('user_default_timezone', DRUPAL_USER_TIMEZONE_DEFAULT)) { $account->timezone = variable_get('date_default_timezone', ''); } @@ -1989,7 +1989,7 @@ function system_user_presave(&$edit, $account) { /** * Implements hook_user_login(). */ -function system_user_login(&$edit, $account) { +function system_user_login(&$form_state, User $account) { // If the user has a NULL time zone, notify them to set a time zone. if (!$account->timezone && variable_get('configurable_timezones', 1) && variable_get('empty_timezone_message', 0)) { drupal_set_message(t('Configure your account time zone setting.', array('@user-edit' => url("user/$account->uid/edit", array('query' => drupal_get_destination(), 'fragment' => 'edit-timezone'))))); diff --git a/core/modules/trigger/trigger.module b/core/modules/trigger/trigger.module index 75f0133..06f4b6d 100644 --- a/core/modules/trigger/trigger.module +++ b/core/modules/trigger/trigger.module @@ -463,39 +463,38 @@ function _trigger_normalize_user_context($type, $account) { /** * Implements hook_user_login(). */ -function trigger_user_login(&$edit, $account) { - _trigger_user('user_login', $edit, $account); +function trigger_user_login(&$form_state, User $account) { + _trigger_user('user_login', $account); } /** * Implements hook_user_logout(). */ -function trigger_user_logout($account) { - $edit = array(); - _trigger_user('user_logout', $edit, $account); +function trigger_user_logout(User $account) { + _trigger_user('user_logout', $account); } /** * Implements hook_user_insert(). */ -function trigger_user_insert(&$edit, $account) { - _trigger_user('user_insert', $edit, $account); +function trigger_user_insert(User $account) { + _trigger_user('user_insert', $account); } /** * Implements hook_user_update(). */ -function trigger_user_update(&$edit, $account) { - _trigger_user('user_update', $edit, $account); +function trigger_user_update($account) { + _trigger_user('user_update', $account); } /** * Implements hook_user_cancel(). */ -function trigger_user_cancel($edit, $account, $method) { +function trigger_user_cancel($edit, User $account, $method) { switch ($method) { case 'user_cancel_reassign': - _trigger_user('user_delete', $edit, $account, $method); + _trigger_user('user_delete', $account, $method); break; } } @@ -503,30 +502,27 @@ function trigger_user_cancel($edit, $account, $method) { /** * Implements hook_user_predelete(). */ -function trigger_user_predelete($account) { - $edit = array(); - _trigger_user('user_delete', $edit, $account); +function trigger_user_predelete(User $account) { + _trigger_user('user_delete', $account); } /** * Implements hook_user_view(). */ -function trigger_user_view($account) { - $edit = NULL; - _trigger_user('user_view', $edit, $account); +function trigger_user_view(User $account) { + _trigger_user('user_view', $account); } /** * Calls action functions for user triggers. */ -function _trigger_user($hook, &$edit, $account, $method = NULL) { +function _trigger_user($hook, $account, $method = NULL) { // Keep objects for reuse so that changes actions make to objects can persist. static $objects; $aids = trigger_get_assigned_actions($hook); $context = array( 'group' => 'user', 'hook' => $hook, - 'form_values' => &$edit, ); foreach ($aids as $aid => $info) { $type = $info['type']; diff --git a/core/modules/trigger/trigger.test b/core/modules/trigger/trigger.test index 9a9a4ba..f471cf2 100644 --- a/core/modules/trigger/trigger.test +++ b/core/modules/trigger/trigger.test @@ -519,7 +519,8 @@ class TriggerUserActionTestCase extends TriggerActionTestCase { $comment_author_uid = $account->uid; // Now rehabilitate the comment author so it can be be blocked again when // the comment is updated. - user_save($account, array('status' => TRUE)); + $account->status = 1; + user_save($account); $test_user = $this->drupalCreateUser(array('administer actions', 'create article content', 'access comments', 'administer comments', 'skip comment approval', 'edit own comments')); $this->drupalLogin($test_user); diff --git a/core/modules/user/user.api.php b/core/modules/user/user.api.php index 51237d7..0cbb705 100644 --- a/core/modules/user/user.api.php +++ b/core/modules/user/user.api.php @@ -46,7 +46,7 @@ function hook_user_load($users) { * @see hook_user_delete() * @see user_delete_multiple() */ -function hook_user_predelete($account) { +function hook_user_predelete(User $account) { db_delete('mytable') ->condition('uid', $account->uid) ->execute(); @@ -67,7 +67,7 @@ function hook_user_predelete($account) { * @see hook_user_predelete() * @see user_delete_multiple() */ -function hook_user_delete($account) { +function hook_user_delete(User $account) { drupal_set_message(t('User: @name has been deleted.', array('@name' => $account->name))); } @@ -97,7 +97,7 @@ function hook_user_delete($account) { * @see user_cancel_methods() * @see hook_user_cancel_methods_alter() */ -function hook_user_cancel($edit, $account, $method) { +function hook_user_cancel($edit, User $account, $method) { switch ($method) { case 'user_cancel_block_unpublish': // Unpublish nodes (current revisions). @@ -209,21 +209,19 @@ function hook_user_operations() { * * This hook is primarily intended for modules that want to store properties in * the serialized {users}.data column, which is automatically loaded whenever a - * user account object is loaded, modules may add to $edit['data'] in order + * user account object is loaded, modules may add to $account->data in order * to have their data serialized on save. * - * @param $edit - * The array of form values submitted by the user. * @param $account - * The user object on which the operation is performed. + * The User object on which the operation is performed. * * @see hook_user_insert() * @see hook_user_update() */ -function hook_user_presave(&$edit, $account) { +function hook_user_presave(User $account) { // Make sure that our form value 'mymodule_foo' is stored as 'mymodule_bar'. - if (isset($edit['mymodule_foo'])) { - $edit['data']['my_module_foo'] = $edit['my_module_foo']; + if (isset($account->mymodule_foo)) { + $account->data['my_module_foo'] = $account->my_module_foo; } } @@ -233,18 +231,16 @@ function hook_user_presave(&$edit, $account) { * The module should save its custom additions to the user object into the * database. * - * @param $edit - * The array of form values submitted by the user. * @param $account - * The user object on which the operation is being performed. + * The User object on which the operation is being performed. * * @see hook_user_presave() * @see hook_user_update() */ -function hook_user_insert(&$edit, $account) { +function hook_user_insert(User $account) { db_insert('mytable') ->fields(array( - 'myfield' => $edit['myfield'], + 'myfield' => $account->myfield, 'uid' => $account->uid, )) ->execute(); @@ -259,12 +255,12 @@ function hook_user_insert(&$edit, $account) { * @param $edit * The array of form values submitted by the user. * @param $account - * The user object on which the operation is performed. + * The User object on which the operation is performed. * * @see hook_user_presave() * @see hook_user_insert() */ -function hook_user_update(&$edit, $account) { +function hook_user_update(User $account) { db_insert('user_changes') ->fields(array( 'uid' => $account->uid, @@ -276,12 +272,12 @@ function hook_user_update(&$edit, $account) { /** * The user just logged in. * - * @param $edit - * The array of form values submitted by the user. + * @param $form_state + * The form_state array of the login form, can be empty. * @param $account * The user object on which the operation was just performed. */ -function hook_user_login(&$edit, $account) { +function hook_user_login(&$form_state, User $account) { // If the user has a NULL time zone, notify them to set a time zone. if (!$account->timezone && variable_get('configurable_timezones', 1) && variable_get('empty_timezone_message', 0)) { drupal_set_message(t('Configure your account time zone setting.', array('@user-edit' => url("user/$account->uid/edit", array('query' => drupal_get_destination(), 'fragment' => 'edit-timezone'))))); @@ -294,7 +290,7 @@ function hook_user_login(&$edit, $account) { * @param $account * The user object on which the operation was just performed. */ -function hook_user_logout($account) { +function hook_user_logout(User $account) { db_insert('logouts') ->fields(array( 'uid' => $account->uid, @@ -310,7 +306,7 @@ function hook_user_logout($account) { * $account->content array. * * @param $account - * The user object on which the operation is being performed. + * The User object on which the operation is being performed. * @param $view_mode * View mode, e.g. 'full'. * @param $langcode @@ -319,7 +315,7 @@ function hook_user_logout($account) { * @see hook_user_view_alter() * @see hook_entity_view() */ -function hook_user_view($account, $view_mode, $langcode) { +function hook_user_view(User $account, $view_mode, $langcode) { $account->content['user_picture'] = array( '#markup' => theme('user_picture', array('account' => $account)), '#weight' => -10, diff --git a/core/modules/user/user.entity.inc b/core/modules/user/user.entity.inc index 5549c77..86e21a4 100644 --- a/core/modules/user/user.entity.inc +++ b/core/modules/user/user.entity.inc @@ -5,12 +5,131 @@ */ /** + * Defines the user entity class. + */ +class User extends Entity { + + /** + * The user ID. + * + * @var integer + */ + public $uid; + + /** + * The unique user name. + * + * @var string + */ + public $name = ''; + + /** + * The user's password (hashed). + * + * @var string + */ + public $pass; + + /** + * The user's email address. + * + * @var string + */ + public $mail = ''; + + /** + * The user's default theme. + * + * @var string + */ + public $theme; + + /** + * The user's signature. + * + * @var string + */ + public $signature; + + /** + * The user's signature format. + * + * @var string + */ + public $signature_format = NULL; + + /** + * The timestamp when the user was created. + * + * @var integer + */ + public $created = 0; + + /** + * The timestamp when the user last accessed the site. + * + * @var integer + */ + public $access = 0; + + /** + * The timestamp when the user lasted logged in. + * + * @var integer + */ + public $login = 0; + + /** + * Whether the user is active(1) or blocked(0). + * + * @var integer + */ + public $status = 0; + + /** + * The user's timezone. + * + * @var string + */ + public $timezone = NULL; + + /** + * The user's default language. + * + * @var string + */ + public $language = ''; + + /** + * The fid of the user's picture. + * + * @var integer + */ + public $picture = 0; + + /** + * The email address used for initial account creation. + * + * @var string + */ + public $init = ''; + + /** + * The user's roles. + * + * @var array + */ + public $roles = array(); + +} + +/** * Controller class for users. * * This extends the DrupalDefaultEntityController class, adding required * special handling for user objects. */ -class UserController extends DrupalDefaultEntityController { +class UserController extends EntityDatabaseStorageController { function attachLoad(&$queried_users, $revision_id = FALSE) { // Build an array of user picture IDs so that these can be fetched later. @@ -49,4 +168,140 @@ class UserController extends DrupalDefaultEntityController { // hook_user_load(). parent::attachLoad($queried_users, $revision_id); } + + public function save(EntityInterface $entity) { + $entity->is_new = $entity->isNew(); + if (empty($entity->uid)) { + $entity->uid = db_next_id(db_query('SELECT MAX(uid) FROM {users}')->fetchField()); + } + parent::save($entity); + } + + protected function preSave(EntityInterface $entity) { + // Update the user password if it has changed. + if ($entity->is_new || $entity->pass != $entity->original->pass) { + // Allow alternate password hashing schemes. + require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'core/includes/password.inc'); + $entity->pass = user_hash_password(trim($entity->pass)); + // Abort if the hashing failed and returned FALSE. + if (!$entity->pass) { + return FALSE; + } + } + + if (!empty($entity->picture_upload)) { + $entity->picture = $entity->picture_upload; + } + // Delete picture if requested, and if no replacement picture was given. + elseif (!empty($entity->picture_delete)) { + $entity->picture = NULL; + } + + if (!$entity->isNew()) { + // Process picture uploads. + if (!empty($entity->picture->fid) && (!isset($entity->original->picture->fid) || $entity->picture->fid != $entity->original->picture->fid)) { + $picture = $entity->picture; + // If the picture is a temporary file move it to its final location and + // make it permanent. + if (!$picture->status) { + $info = image_get_info($picture->uri); + $picture_directory = file_default_scheme() . '://' . variable_get('user_picture_path', 'pictures'); + + // Prepare the pictures directory. + file_prepare_directory($picture_directory, FILE_CREATE_DIRECTORY); + $destination = file_stream_wrapper_uri_normalize($picture_directory . '/picture-' . $entity->uid . '-' . REQUEST_TIME . '.' . $info['extension']); + + // Move the temporary file into the final location. + if ($picture = file_move($picture, $destination, FILE_EXISTS_RENAME)) { + $picture->status = FILE_STATUS_PERMANENT; + $entity->picture = file_save($picture); + file_usage_add($picture, 'user', 'user', $entity->uid); + } + } + // Delete the previous picture if it was deleted or replaced. + if (!empty($entity->original->picture->fid)) { + file_usage_delete($entity->original->picture, 'user', 'user', $entity->uid); + file_delete($entity->original->picture); + } + } + $entity->picture = empty($entity->picture->fid) ? 0 : $entity->picture->fid; + + // Do not allow 'uid' to be changed. + $entity->uid = $entity->original->uid; + + // If the password changed, delete all open sessions and recreate + // the current one. + if ($entity->pass != $entity->original->pass) { + drupal_session_destroy_uid($entity->uid); + if ($entity->uid == $GLOBALS['user']->uid) { + drupal_session_regenerate(); + } + } + + // Reload user roles if provided. + if ($entity->roles != $entity->original->roles) { + db_delete('users_roles') + ->condition('uid', $entity->uid) + ->execute(); + + $query = db_insert('users_roles')->fields(array('uid', 'rid')); + foreach (array_keys($entity->roles) as $rid) { + if (!in_array($rid, array(DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID))) { + $query->values(array( + 'uid' => $entity->uid, + 'rid' => $rid, + )); + } + } + $query->execute(); + } + + // Delete a blocked user's sessions to kick them if they are online. + if ($entity->original->status != $entity->status && $entity->status == 0) { + drupal_session_destroy_uid($entity->uid); + } + + // Send emails after we have the new user object. + if ($entity->status != $entity->original->status) { + // The user's status is changing; conditionally send notification email. + $op = $entity->status == 1 ? 'status_activated' : 'status_blocked'; + _user_mail_notify($op, $entity); + } + } + else { + // Allow 'created' to be set by the caller. + if (!isset($entity->created)) { + $entity->created = REQUEST_TIME; + } + + // Make sure $account is properly initialized. + $entity->roles[DRUPAL_AUTHENTICATED_RID] = 'authenticated user'; + + // Save user roles. + if (count($entity->roles) > 1) { + $query = db_insert('users_roles')->fields(array('uid', 'rid')); + foreach (array_keys($entity->roles) as $rid) { + if (!in_array($rid, array(DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID))) { + $query->values(array( + 'uid' => $entity->uid, + 'rid' => $rid, + )); + } + } + $query->execute(); + } + } + + // Prepare user roles. + if (isset($entity->roles)) { + $entity->roles = array_filter($entity->roles); + } + + // Move account cancellation information into $user->data. + foreach (array('user_cancel_method', 'user_cancel_notify') as $key) { + if (isset($entity->{$key})) { + $entity->data[$key] = $entity->{$key}; + } + } + } } diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 009a716..f19125a 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -143,7 +143,7 @@ function user_theme() { * Implements hook_entity_info(). */ function user_entity_info() { - $return = array( + return array( 'user' => array( 'label' => t('User'), 'controller class' => 'UserController', @@ -151,6 +151,7 @@ function user_entity_info() { 'uri callback' => 'user_uri', 'label callback' => 'user_label', 'fieldable' => TRUE, + 'entity class' => 'User', 'entity keys' => array( 'id' => 'uid', ), @@ -171,7 +172,6 @@ function user_entity_info() { ), ), ); - return $return; } /** @@ -361,213 +361,10 @@ function user_load_by_name($name) { * Save changes to a user account or add a new user. * * @param $account - * (optional) The user object to modify or add. If you want to modify - * an existing user account, you will need to ensure that (a) $account - * is an object, and (b) you have set $account->uid to the numeric - * user ID of the user account you wish to modify. If you - * want to create a new user account, you can set $account->is_new to - * TRUE or omit the $account->uid field. - * @param $edit - * An array of fields and values to save. For example array('name' - * => 'My name'). Key / value pairs added to the $edit['data'] will be - * serialized and saved in the {users.data} column. - * - * @return - * A fully-loaded $user object upon successful save or FALSE if the save failed. - * - * @todo D8: Drop $edit and fix user_save() to be consistent with others. + * A User object. */ -function user_save($account, $edit = array()) { - $transaction = db_transaction(); - try { - if (!empty($edit['pass'])) { - // Allow alternate password hashing schemes. - require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'core/includes/password.inc'); - $edit['pass'] = user_hash_password(trim($edit['pass'])); - // Abort if the hashing failed and returned FALSE. - if (!$edit['pass']) { - return FALSE; - } - } - else { - // Avoid overwriting an existing password with a blank password. - unset($edit['pass']); - } - if (isset($edit['mail'])) { - $edit['mail'] = trim($edit['mail']); - } - - // Load the stored entity, if any. - if (!empty($account->uid) && !isset($account->original)) { - $account->original = entity_load_unchanged('user', $account->uid); - } - - if (empty($account)) { - $account = new stdClass(); - } - if (!isset($account->is_new)) { - $account->is_new = empty($account->uid); - } - // Prepopulate $edit['data'] with the current value of $account->data. - // Modules can add to or remove from this array in hook_user_presave(). - if (!empty($account->data)) { - $edit['data'] = !empty($edit['data']) ? array_merge($account->data, $edit['data']) : $account->data; - } - - // Invoke hook_user_presave() for all modules. - user_module_invoke('presave', $edit, $account); - - // Invoke presave operations of Field Attach API and Entity API. Those APIs - // require a fully-fledged and updated entity object. Therefore, we need to - // copy any new property values of $edit into it. - foreach ($edit as $key => $value) { - $account->$key = $value; - } - field_attach_presave('user', $account); - module_invoke_all('entity_presave', $account, 'user'); - - if (is_object($account) && !$account->is_new) { - // Process picture uploads. - if (!empty($account->picture->fid) && (!isset($account->original->picture->fid) || $account->picture->fid != $account->original->picture->fid)) { - $picture = $account->picture; - // If the picture is a temporary file move it to its final location and - // make it permanent. - if (!$picture->status) { - $info = image_get_info($picture->uri); - $picture_directory = file_default_scheme() . '://' . variable_get('user_picture_path', 'pictures'); - - // Prepare the pictures directory. - file_prepare_directory($picture_directory, FILE_CREATE_DIRECTORY); - $destination = file_stream_wrapper_uri_normalize($picture_directory . '/picture-' . $account->uid . '-' . REQUEST_TIME . '.' . $info['extension']); - - // Move the temporary file into the final location. - if ($picture = file_move($picture, $destination, FILE_EXISTS_RENAME)) { - $picture->status = FILE_STATUS_PERMANENT; - $account->picture = file_save($picture); - file_usage_add($picture, 'user', 'user', $account->uid); - } - } - // Delete the previous picture if it was deleted or replaced. - if (!empty($account->original->picture->fid)) { - file_usage_delete($account->original->picture, 'user', 'user', $account->uid); - file_delete($account->original->picture); - } - } - $account->picture = empty($account->picture->fid) ? 0 : $account->picture->fid; - - // Do not allow 'uid' to be changed. - $account->uid = $account->original->uid; - // Save changes to the user table. - $success = drupal_write_record('users', $account, 'uid'); - if ($success === FALSE) { - // The query failed - better to abort the save than risk further - // data loss. - return FALSE; - } - - // Reload user roles if provided. - if ($account->roles != $account->original->roles) { - db_delete('users_roles') - ->condition('uid', $account->uid) - ->execute(); - - $query = db_insert('users_roles')->fields(array('uid', 'rid')); - foreach (array_keys($account->roles) as $rid) { - if (!in_array($rid, array(DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID))) { - $query->values(array( - 'uid' => $account->uid, - 'rid' => $rid, - )); - } - } - $query->execute(); - } - - // Delete a blocked user's sessions to kick them if they are online. - if ($account->original->status != $account->status && $account->status == 0) { - drupal_session_destroy_uid($account->uid); - } - - // If the password changed, delete all open sessions and recreate - // the current one. - if ($account->pass != $account->original->pass) { - drupal_session_destroy_uid($account->uid); - if ($account->uid == $GLOBALS['user']->uid) { - drupal_session_regenerate(); - } - } - - // Save Field data. - field_attach_update('user', $account); - - // Send emails after we have the new user object. - if ($account->status != $account->original->status) { - // The user's status is changing; conditionally send notification email. - $op = $account->status == 1 ? 'status_activated' : 'status_blocked'; - _user_mail_notify($op, $account); - } - - // Update $edit with any interim changes to $account. - foreach ($account as $key => $value) { - if (!property_exists($account->original, $key) || $value !== $account->original->$key) { - $edit[$key] = $value; - } - } - user_module_invoke('update', $edit, $account); - module_invoke_all('entity_update', $account, 'user'); - } - else { - // Allow 'uid' to be set by the caller. There is no danger of writing an - // existing user as drupal_write_record will do an INSERT. - if (empty($account->uid)) { - $account->uid = db_next_id(db_query('SELECT MAX(uid) FROM {users}')->fetchField()); - } - // Allow 'created' to be set by the caller. - if (!isset($account->created)) { - $account->created = REQUEST_TIME; - } - $success = drupal_write_record('users', $account); - if ($success === FALSE) { - // On a failed INSERT some other existing user's uid may be returned. - // We must abort to avoid overwriting their account. - return FALSE; - } - - // Make sure $account is properly initialized. - $account->roles[DRUPAL_AUTHENTICATED_RID] = 'authenticated user'; - - field_attach_insert('user', $account); - $edit = (array) $account; - user_module_invoke('insert', $edit, $account); - module_invoke_all('entity_insert', $account, 'user'); - - // Save user roles. - if (count($account->roles) > 1) { - $query = db_insert('users_roles')->fields(array('uid', 'rid')); - foreach (array_keys($account->roles) as $rid) { - if (!in_array($rid, array(DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID))) { - $query->values(array( - 'uid' => $account->uid, - 'rid' => $rid, - )); - } - } - $query->execute(); - } - } - // Clear internal properties. - unset($account->is_new); - unset($account->original); - // Clear the static loading cache. - entity_get_controller('user')->resetCache(array($account->uid)); - - return $account; - } - catch (Exception $e) { - $transaction->rollback(); - watchdog_exception('user', $e); - throw $e; - } +function user_save(User $account) { + $account->save(); } /** @@ -913,7 +710,7 @@ function user_search_execute($keys = NULL, $conditions = NULL) { /** * Implements hook_user_view(). */ -function user_user_view($account) { +function user_user_view(User $account) { $account->content['user_picture'] = array( '#markup' => theme('user_picture', array('account' => $account)), '#weight' => -10, @@ -1181,30 +978,6 @@ function user_account_form_validate($form, &$form_state) { } } -/** - * Implements hook_user_presave(). - */ -function user_user_presave(&$edit, $account) { - if (!empty($edit['picture_upload'])) { - $edit['picture'] = $edit['picture_upload']; - } - // Delete picture if requested, and if no replacement picture was given. - elseif (!empty($edit['picture_delete'])) { - $edit['picture'] = NULL; - } - // Prepare user roles. - if (isset($edit['roles'])) { - $edit['roles'] = array_filter($edit['roles']); - } - - // Move account cancellation information into $user->data. - foreach (array('user_cancel_method', 'user_cancel_notify') as $key) { - if (isset($edit[$key])) { - $edit['data'][$key] = $edit[$key]; - } - } -} - function user_login_block($form) { $form['#action'] = url($_GET['q'], array('query' => drupal_get_destination())); $form['#id'] = 'user-login-form'; @@ -2184,7 +1957,8 @@ function user_authenticate($name, $password) { // Update user to new password scheme if needed. if (user_needs_new_hash($account)) { - user_save($account, array('pass' => $password)); + $account->pass = $password; + user_save($account); } } } @@ -2239,16 +2013,16 @@ function user_external_login_register($name, $module) { $account = user_external_load($name); if (!$account) { // Register this new user. - $userinfo = array( + $account = entity_create('user', array( 'name' => $name, 'pass' => user_password(), 'init' => $name, 'status' => 1, 'access' => REQUEST_TIME - ); - $account = user_save(drupal_anonymous_user(), $userinfo); + )); + $status = user_save($account); // Terminate if an error occurred during user_save(). - if (!$account) { + if ($status != SAVED_NEW) { drupal_set_message(t("Error saving user account."), 'error'); return; } @@ -2396,7 +2170,8 @@ function _user_cancel($edit, $account, $method) { if (!empty($edit['user_cancel_notify'])) { _user_mail_notify('status_blocked', $account); } - user_save($account, array('status' => 0)); + $account->status = 0; + user_save($account); drupal_set_message(t('%name has been disabled.', array('%name' => $account->name))); watchdog('user', 'Blocked user: %name %email.', array('%name' => $account->name, '%email' => '<' . $account->mail . '>'), WATCHDOG_NOTICE); break; @@ -3150,7 +2925,8 @@ function user_user_operations_unblock($accounts) { foreach ($accounts as $account) { // Skip unblocking user if they are already unblocked. if ($account !== FALSE && $account->status == 0) { - user_save($account, array('status' => 1)); + $account->status = 1; + user_save($account); } } } @@ -3166,7 +2942,8 @@ function user_user_operations_block($accounts) { // For efficiency manually save the original account before applying any // changes. $account->original = clone $account; - user_save($account, array('status' => 0)); + $account->status = 0; + user_save($account); } } } @@ -3189,7 +2966,8 @@ function user_multiple_role_edit($accounts, $operation, $rid) { // For efficiency manually save the original account before applying // any changes. $account->original = clone $account; - user_save($account, array('roles' => $roles)); + $account->roles = $roles; + user_save($account); } } break; @@ -3202,7 +2980,8 @@ function user_multiple_role_edit($accounts, $operation, $rid) { // For efficiency manually save the original account before applying // any changes. $account->original = clone $account; - user_save($account, array('roles' => $roles)); + $account->roles = $roles; + user_save($account); } } break; @@ -3292,7 +3071,7 @@ function user_multiple_cancel_confirm_submit($form, &$form_state) { if ($uid == $user->uid) { $admin_form_state = $form_state; unset($admin_form_state['values']['user_cancel_confirm']); - $admin_form_state['values']['_account'] = $user; + $admin_form_state['values']['_account'] = user_load($user->uid); user_cancel_confirm_form_submit(array(), $admin_form_state); } else { @@ -3617,7 +3396,8 @@ function user_block_user_action(&$entity, $context = array()) { $uid = $GLOBALS['user']->uid; } $account = user_load($uid); - $account = user_save($account, array('status' => 0)); + $account->status = 0; + $account = user_save($account); watchdog('action', 'Blocked user %name.', array('%name' => $account->name)); } @@ -3688,7 +3468,7 @@ function user_register_form($form, &$form_state) { drupal_goto('user/' . $user->uid); } - $form['#user'] = drupal_anonymous_user(); + $form['#user'] = entity_create('user', array()); $form['#attached']['library'][] = array('system', 'jquery.cookie'); $form['#attributes']['class'][] = 'user-info-from-cookie'; @@ -3759,14 +3539,10 @@ function user_register_submit($form, &$form_state) { $account = $form['#user']; entity_form_submit_build_entity('user', $account, $form, $form_state); - - // Populate $edit with the properties of $account, which have been edited on - // this form by taking over all values, which appear in the form values too. - $edit = array_intersect_key((array) $account, $form_state['values']); - $account = user_save($account, $edit); + $status = user_save($account); // Terminate if an error occurred during user_save(). - if (!$account) { + if ($status =! SAVED_NEW) { drupal_set_message(t("Error saving user account."), 'error'); $form_state['redirect'] = ''; return; diff --git a/core/modules/user/user.pages.inc b/core/modules/user/user.pages.inc index 8239c53..7c48b11 100644 --- a/core/modules/user/user.pages.inc +++ b/core/modules/user/user.pages.inc @@ -270,12 +270,7 @@ function user_profile_form_submit($form, &$form_state) { $account_unchanged = clone $account; entity_form_submit_build_entity('user', $account, $form, $form_state); - - // Populate $edit with the properties of $account, which have been edited on - // this form by taking over all values, which appear in the form values too. - $edit = array_intersect_key((array) $account, $form_state['values']); - - user_save($account_unchanged, $edit); + user_save($account); $form_state['values']['uid'] = $account->uid; if (!empty($edit['pass'])) { @@ -399,11 +394,9 @@ function user_cancel_confirm_form_submit($form, &$form_state) { else { // Store cancelling method and whether to notify the user in $account for // user_cancel_confirm(). - $edit = array( - 'user_cancel_method' => $form_state['values']['user_cancel_method'], - 'user_cancel_notify' => $form_state['values']['user_cancel_notify'], - ); - $account = user_save($account, $edit); + $account->user_cancel_method = $form_state['values']['user_cancel_method']; + $account->user_cancel_notify = $form_state['values']['user_cancel_notify']; + user_save($account); _user_mail_notify('cancel_confirm', $account); drupal_set_message(t('A confirmation request to cancel your account has been sent to your e-mail address.')); watchdog('user', 'Sent account cancellation request to %name %email.', array('%name' => $account->name, '%email' => '<' . $account->mail . '>'), WATCHDOG_NOTICE); diff --git a/core/modules/user/user.test b/core/modules/user/user.test index 39d90d1..149ddac 100644 --- a/core/modules/user/user.test +++ b/core/modules/user/user.test @@ -1532,16 +1532,15 @@ class UserSaveTestCase extends DrupalWebTestCase { $test_name = $this->randomName(); // Create the base user, based on drupalCreateUser(). - $user = array( + $user = entity_create('user', array( 'name' => $test_name, 'uid' => $test_uid, 'mail' => $test_name . '@example.com', 'is_new' => TRUE, 'pass' => user_password(), 'status' => 1, - ); - $user_by_return = user_save(drupal_anonymous_user(), $user); - $this->assertTrue($user_by_return, t('Loading user by return of user_save().')); + )); + user_save($user); // Test if created user exists. $user_by_uid = user_load($test_uid);