class UserStorage
Same name and namespace in other branches
- 11.x core/modules/user/src/UserStorage.php \Drupal\user\UserStorage
Controller class for users.
This extends the Drupal\Core\Entity\Sql\SqlContentEntityStorage class, adding required special handling for user objects.
Hierarchy
- class \Drupal\Core\Entity\EntityHandlerBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait
- class \Drupal\Core\Entity\EntityStorageBase extends \Drupal\Core\Entity\EntityStorageInterface, \Drupal\Core\Entity\EntityHandlerInterface implements \Drupal\Core\Entity\EntityHandlerBase
- class \Drupal\Core\Entity\ContentEntityStorageBase extends \Drupal\Core\Entity\ContentEntityStorageInterface, \Drupal\Core\Entity\DynamicallyFieldableEntityStorageInterface, \Drupal\Core\Entity\BundleEntityStorageInterface implements \Drupal\Core\Entity\EntityStorageBase
- class \Drupal\Core\Entity\Sql\SqlContentEntityStorage extends \Drupal\Core\Entity\Sql\SqlEntityStorageInterface, \Drupal\Core\Entity\Schema\DynamicallyFieldableEntityStorageSchemaInterface, \Drupal\Core\Entity\EntityBundleListenerInterface implements \Drupal\Core\Entity\ContentEntityStorageBase
- class \Drupal\user\UserStorage extends \Drupal\user\UserStorageInterface implements \Drupal\Core\Entity\Sql\SqlContentEntityStorage
- class \Drupal\Core\Entity\Sql\SqlContentEntityStorage extends \Drupal\Core\Entity\Sql\SqlEntityStorageInterface, \Drupal\Core\Entity\Schema\DynamicallyFieldableEntityStorageSchemaInterface, \Drupal\Core\Entity\EntityBundleListenerInterface implements \Drupal\Core\Entity\ContentEntityStorageBase
- class \Drupal\Core\Entity\ContentEntityStorageBase extends \Drupal\Core\Entity\ContentEntityStorageInterface, \Drupal\Core\Entity\DynamicallyFieldableEntityStorageInterface, \Drupal\Core\Entity\BundleEntityStorageInterface implements \Drupal\Core\Entity\EntityStorageBase
- class \Drupal\Core\Entity\EntityStorageBase extends \Drupal\Core\Entity\EntityStorageInterface, \Drupal\Core\Entity\EntityHandlerInterface implements \Drupal\Core\Entity\EntityHandlerBase
Expanded class hierarchy of UserStorage
File
-
core/
modules/ user/ src/ UserStorage.php, line 15
Namespace
Drupal\userView source
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. MySQL
// does not support inserting an ID of 0 into serial field unless the SQL
// mode is set to NO_AUTO_VALUE_ON_ZERO.
// @todo https://drupal.org/i/3222123 implement a generic fix for all entity
// types.
if ($entity->id() === 0) {
$database = \Drupal::database();
if ($database->databaseType() === 'mysql') {
$sql_mode = $database->query("SELECT @@sql_mode;")
->fetchField();
$database->query("SET sql_mode = '{$sql_mode},NO_AUTO_VALUE_ON_ZERO'");
}
}
parent::doSaveFieldItems($entity, $names);
// Reset the SQL mode if we've changed it.
if (isset($sql_mode, $database)) {
$database->query("SET sql_mode = '{$sql_mode}'");
}
}
/**
* {@inheritdoc}
*/
public function updateLastLoginTimestamp(UserInterface $account) {
$this->database
->update($this->getDataTable())
->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($this->getDataTable())
->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();
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.