UserStorage.php in Drupal 8
File
core/modules/user/src/UserStorage.php
View source
<?php
namespace Drupal\user;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
use Drupal\Core\Session\AccountInterface;
class UserStorage extends SqlContentEntityStorage implements UserStorageInterface {
protected function doSaveFieldItems(ContentEntityInterface $entity, array $names = []) {
if ($entity
->id() === NULL) {
$entity->uid->value = $this->database
->nextId($this->database
->query('SELECT MAX(uid) FROM {' . $this
->getBaseTable() . '}')
->fetchField());
$entity
->enforceIsNew();
}
return parent::doSaveFieldItems($entity, $names);
}
protected function isColumnSerial($table_name, $schema_name) {
return $table_name == $this->revisionTable && $schema_name == $this->revisionKey;
}
public function updateLastLoginTimestamp(UserInterface $account) {
$this->database
->update($this
->getDataTable())
->fields([
'login' => $account
->getLastLoginTime(),
])
->condition('uid', $account
->id())
->execute();
$this
->resetCache([
$account
->id(),
]);
}
public function updateLastAccessTimestamp(AccountInterface $account, $timestamp) {
$this->database
->update($this
->getDataTable())
->fields([
'access' => $timestamp,
])
->condition('uid', $account
->id())
->execute();
$this
->resetCache([
$account
->id(),
]);
}
public function deleteRoleReferences(array $rids) {
$this->database
->delete('user__roles')
->condition('roles_target_id', $rids)
->execute();
$this
->resetCache();
}
}