Mercurial > hg > isophonics-drupal-site
diff core/modules/user/src/UserStorage.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 129ea1e6d783 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/modules/user/src/UserStorage.php Wed Nov 29 16:09:58 2017 +0000 @@ -0,0 +1,76 @@ +<?php + +namespace Drupal\user; + +use Drupal\Core\Entity\ContentEntityInterface; +use Drupal\Core\Entity\Sql\SqlContentEntityStorage; +use Drupal\Core\Session\AccountInterface; + +/** + * Controller class for users. + * + * This extends the Drupal\Core\Entity\Sql\SqlContentEntityStorage class, + * adding required special handling for user objects. + */ +class UserStorage extends SqlContentEntityStorage implements UserStorageInterface { + + /** + * {@inheritdoc} + */ + protected function doSaveFieldItems(ContentEntityInterface $entity, array $names = []) { + // The anonymous user account is saved with the fixed user ID of 0. + // Therefore we need to check for NULL explicitly. + if ($entity->id() === NULL) { + $entity->uid->value = $this->database->nextId($this->database->query('SELECT MAX(uid) FROM {users}')->fetchField()); + $entity->enforceIsNew(); + } + return parent::doSaveFieldItems($entity, $names); + } + + /** + * {@inheritdoc} + */ + protected function isColumnSerial($table_name, $schema_name) { + // User storage does not use a serial column for the user id. + return $table_name == $this->revisionTable && $schema_name == $this->revisionKey; + } + + /** + * {@inheritdoc} + */ + public function updateLastLoginTimestamp(UserInterface $account) { + $this->database->update('users_field_data') + ->fields(['login' => $account->getLastLoginTime()]) + ->condition('uid', $account->id()) + ->execute(); + // Ensure that the entity cache is cleared. + $this->resetCache([$account->id()]); + } + + /** + * {@inheritdoc} + */ + public function updateLastAccessTimestamp(AccountInterface $account, $timestamp) { + $this->database->update('users_field_data') + ->fields([ + 'access' => $timestamp, + ]) + ->condition('uid', $account->id()) + ->execute(); + // Ensure that the entity cache is cleared. + $this->resetCache([$account->id()]); + } + + /** + * {@inheritdoc} + */ + public function deleteRoleReferences(array $rids) { + // Remove the role from all users. + $this->database->delete('user__roles') + ->condition('roles_target_id', $rids) + ->execute(); + + $this->resetCache(); + } + +}