diff --git a/core/includes/common.inc b/core/includes/common.inc diff --git a/core/modules/block/block.module b/core/modules/block/block.module index 55b0b40..e827bc0 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($edit) { + if (isset($edit->block)) { + $edit->data['block'] = $edit->block; } } diff --git a/core/modules/entity/entity.controller.inc b/core/modules/entity/entity.controller.inc diff --git a/core/modules/entity/entity.module b/core/modules/entity/entity.module diff --git a/core/modules/overlay/overlay.module b/core/modules/overlay/overlay.module index 5433d3e..293426d 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($edit) { + if (isset($edit->overlay)) { + $edit->data['overlay'] = $edit->overlay; } } diff --git a/core/modules/simpletest/drupal_web_test_case.php b/core/modules/simpletest/drupal_web_test_case.php index 5c711fb..a7aaad3 100644 --- a/core/modules/simpletest/drupal_web_test_case.php +++ b/core/modules/simpletest/drupal_web_test_case.php @@ -1116,16 +1116,18 @@ class DrupalWebTestCase extends DrupalTestCase { $edit['pass'] = user_password(); $edit['status'] = 1; - $account = user_save(drupal_anonymous_user(), $edit); + $User = entity_create('user', $edit); - $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)) { + $User->save(); + + $this->assertTrue(!empty($User->uid), t('User created with name %name and pass %pass', array('%name' => $edit['name'], '%pass' => $edit['pass'])), t('User login')); + if (empty($User->uid)) { return FALSE; } // Add the raw password so that we can log in as this user. - $account->pass_raw = $edit['pass']; - return $account; + $User->pass_raw = $edit['pass']; + return $User; } /** @@ -1220,7 +1222,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/user/user.entity.inc b/core/modules/user/user.entity.inc index 5549c77..92a2f4b 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,11 @@ class UserController extends DrupalDefaultEntityController { // hook_user_load(). parent::attachLoad($queried_users, $revision_id); } + + function save(EntityInterface $entity) { + if (empty($entity->uid)) { + $entity->uid = db_next_id(db_query('SELECT MAX(uid) FROM {users}')->fetchField()); + } + parent::save($entity); + } } diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 2dded35..f84dea7 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; } /** @@ -1184,23 +1184,23 @@ 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']; +function user_user_presave($edit) { + 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; + elseif (!empty($edit->picture_delete)) { + $edit->picture = NULL; } // Prepare user roles. - if (isset($edit['roles'])) { - $edit['roles'] = array_filter($edit['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]; + if (isset($edit->{$key})) { + $edit->data[$key] = $edit->{$key}; } } }