password = $password; } /** * {@inheritdoc} */ public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { return new static( $entity_type, $container->get('database'), $container->get('entity.manager'), $container->get('cache.entity'), $container->get('password'), $container->get('language_manager') ); } /** * {@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(array('login' => $account->getLastLoginTime())) ->condition('uid', $account->id()) ->execute(); // Ensure that the entity cache is cleared. $this->resetCache(array($account->id())); } /** * {@inheritdoc} */ public function updateLastAccessTimestamp(AccountInterface $account, $timestamp) { $this->database->update('users_field_data') ->fields(array( 'access' => $timestamp, )) ->condition('uid', $account->id()) ->execute(); // Ensure that the entity cache is cleared. $this->resetCache(array($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(); } }