diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index f7ab2d7..aa21673 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -1898,8 +1898,8 @@ function drupal_get_user_timezone() { global $user; $config = config('system.timezone'); - if ($user && $config->get('user.configurable') && $user->id() && $user->timezone) { - return $user->timezone; + if ($user && $config->get('user.configurable') && $user->id() && $user->getTimezone()) { + return $user->getTimezone(); } else { // Ignore PHP strict notice if time zone has not yet been set in the php.ini diff --git a/core/includes/session.inc b/core/includes/session.inc index ae37211..049d46e 100644 --- a/core/includes/session.inc +++ b/core/includes/session.inc @@ -122,14 +122,14 @@ function _drupal_session_read($sid) { // The user is anonymous or blocked. Only preserve two fields from the // {sessions} table. $account = drupal_anonymous_user(); - $account->session = $user->session; - $account->timestamp = $user->timestamp; + $account->setSessionData($user->getSessionData()); + $account->setLastAccessedTime($user->getLastAccessedTime()); $user = $account; } else { // The session has expired. $user = drupal_anonymous_user(); - $user->session = ''; + $user->setSessionData(array()); } // Store the session that was read for comparison in _drupal_session_write(). diff --git a/core/lib/Drupal/Core/Session/AccountInterface.php b/core/lib/Drupal/Core/Session/AccountInterface.php index 62420a2..c57b6eb 100644 --- a/core/lib/Drupal/Core/Session/AccountInterface.php +++ b/core/lib/Drupal/Core/Session/AccountInterface.php @@ -132,4 +132,12 @@ public function getEmail(); */ public function getLastAccessedTime(); + /** + * Returns the timezone of the user. + * + * @return string + * Name of the timezone. + */ + public function getTimeZone(); + } diff --git a/core/lib/Drupal/Core/Session/UserSession.php b/core/lib/Drupal/Core/Session/UserSession.php index 0745db1..bc64e51 100644 --- a/core/lib/Drupal/Core/Session/UserSession.php +++ b/core/lib/Drupal/Core/Session/UserSession.php @@ -94,6 +94,13 @@ class UserSession implements AccountInterface { protected $mail; /** + * The timezone of this account. + * + * @var string + */ + protected $timezone; + + /** * Constructs a new user session. * * @param array $values @@ -203,5 +210,32 @@ public function getLastAccessedTime() { return $this->timestamp; } + /** + * {@inheritdoc} + */ + public function getTimeZone() { + return $this->timezone; + } + + /** + * Sets the last accessed time of this account. + * + * @param int $timestamp + * The last accessed timestamp. + */ + public function setLastAccessedTime($timestamp) { + $this->timestamp = $timestamp; + } + + /** + * Sets current session. + * + * @param array $session + * The session data. + */ + public function setSessionData($session) { + $this->session = $session; + } + } diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 060f4db..280d529 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -2427,7 +2427,7 @@ function system_user_presave(UserInterface $account) { function system_user_login($account) { $config = config('system.timezone'); // If the user has a NULL time zone, notify them to set a time zone. - if (!$account->timezone && $config->get('user.configurable') && $config->get('user.warn')) { + if (!$account->getTimezone() && $config->get('user.configurable') && $config->get('user.warn')) { drupal_set_message(t('Configure your account time zone setting.', array('@user-edit' => url("user/$account->id()/edit", array('query' => drupal_get_destination(), 'fragment' => 'edit-timezone'))))); } } @@ -2451,7 +2451,7 @@ function system_user_timezone(&$form, &$form_state) { '#options' => system_time_zones($account->id() != $user->id()), '#description' => t('Select the desired local time and time zone. Dates and times throughout this site will be displayed using this time zone.'), ); - if (!isset($account->timezone) && $account->id() == $user->id() && empty($form_state['input']['timezone'])) { + if (!$account->getTimezone() && $account->id() == $user->id() && empty($form_state['input']['timezone'])) { $form['timezone']['#description'] = t('Your time zone setting will be automatically detected if possible. Confirm the selection and click save.'); $form['timezone']['timezone']['#attributes'] = array('class' => array('timezone-detect')); drupal_add_library('system', 'drupal.timezone'); diff --git a/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php b/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php index 7028261..f975664 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php @@ -184,7 +184,7 @@ function testRegistrationDefaultValues() { $this->assertEqual($new_user->getSignature(), '', 'Correct signature field.'); $this->assertTrue(($new_user->getCreatedTime() > REQUEST_TIME - 20 ), 'Correct creation time.'); $this->assertEqual($new_user->isActive(), $config_user_settings->get('register') == USER_REGISTER_VISITORS ? 1 : 0, 'Correct status field.'); - $this->assertEqual($new_user->timezone->value, $config_system_timezone->get('default'), 'Correct time zone field.'); + $this->assertEqual($new_user->getTimezone(), $config_system_timezone->get('default'), 'Correct time zone field.'); $this->assertEqual($new_user->langcode->value, language_default()->id, 'Correct language field.'); $this->assertEqual($new_user->preferred_langcode->value, language_default()->id, 'Correct preferred language field.'); $this->assertEqual($new_user->init->value, $mail, 'Correct init field.'); diff --git a/core/modules/user/lib/Drupal/user/UserInterface.php b/core/modules/user/lib/Drupal/user/UserInterface.php index 4a3950d..e0bf1f9 100644 --- a/core/modules/user/lib/Drupal/user/UserInterface.php +++ b/core/modules/user/lib/Drupal/user/UserInterface.php @@ -176,14 +176,6 @@ public function activate(); public function block(); /** - * Returns the timezone of the user. - * - * @return string - * Name of the timezone. - */ - public function getTimeZone(); - - /** * Returns the e-mail that was used when the user was registered. * * @return string diff --git a/core/modules/user/user.api.php b/core/modules/user/user.api.php index 9e9fcaf..2e8fb8d 100644 --- a/core/modules/user/user.api.php +++ b/core/modules/user/user.api.php @@ -286,7 +286,7 @@ function hook_user_update($account) { function hook_user_login($account) { $config = config('system.timezone'); // If the user has a NULL time zone, notify them to set a time zone. - if (!$account->timezone && $config->get('user.configurable') && $config->get('user.warn')) { + if (!$account->getTimezone() && $config->get('user.configurable') && $config->get('user.warn')) { drupal_set_message(t('Configure your account time zone setting.', array('@user-edit' => url("user/" . $account->id() . "/edit", array('query' => drupal_get_destination(), 'fragment' => 'edit-timezone'))))); } }