--- 2068329-convert_user_sql_queries_to_the_entity_query_api-48.patch 2013-11-24 10:56:23.000000000 +0100 +++ 2068329-convert_user_sql_queries_to_the_entity_query_api-56.patch 2013-12-09 23:11:40.209547791 +0100 @@ -154,84 +154,6 @@ $build = array( '#theme' => 'item_list__user__new', '#items' => array(), -diff --git a/core/modules/user/lib/Drupal/user/Plugin/Block/UserOnlineBlock.php b/core/modules/user/lib/Drupal/user/Plugin/Block/UserOnlineBlock.php -index 9a647a5..7115f4d 100644 ---- a/core/modules/user/lib/Drupal/user/Plugin/Block/UserOnlineBlock.php -+++ b/core/modules/user/lib/Drupal/user/Plugin/Block/UserOnlineBlock.php -@@ -10,7 +10,10 @@ - use Drupal\block\BlockBase; - use Drupal\block\Annotation\Block; - use Drupal\Core\Annotation\Translation; -+use Drupal\Core\Entity\Query\QueryFactory; -+use Drupal\Core\Plugin\ContainerFactoryPluginInterface; - use Drupal\Core\Session\AccountInterface; -+use Symfony\Component\DependencyInjection\ContainerInterface; - - /** - * Provides a "Who's online" block. -@@ -24,7 +27,34 @@ - * category = @Translation("Lists (Views)") - * ) - */ --class UserOnlineBlock extends BlockBase { -+class UserOnlineBlock extends BlockBase implements ContainerFactoryPluginInterface { -+ -+ /** -+ * The entity query factory service. -+ * -+ * @var \Drupal\Core\Entity\Query\QueryFactory -+ */ -+ protected $entityQuery; -+ -+ /** -+ * {@inheritdoc} -+ */ -+ public static function create(ContainerInterface $container, array $configuration, $plugin_id, array $plugin_definition) { -+ return new static( -+ $configuration, -+ $plugin_id, -+ $plugin_definition, -+ $container->get('entity.query') -+ ); -+ } -+ -+ /** -+ * {@inheritdoc} -+ */ -+ public function __construct(array $configuration, $plugin_id, array $plugin_definition, QueryFactory $entity_query) { -+ parent::__construct($configuration, $plugin_id, $plugin_definition); -+ $this->entityQuery = $entity_query; -+ } - - /** - * {@inheritdoc} -@@ -84,7 +114,10 @@ public function build() { - $interval = REQUEST_TIME - $this->configuration['seconds_online']; - - // Perform database queries to gather online user lists. -- $authenticated_count = db_query("SELECT COUNT(uid) FROM {users} WHERE access >= :timestamp", array(':timestamp' => $interval))->fetchField(); -+ $authenticated_count = $this->entityQuery->get('user') -+ ->condition('access', $interval, '>=') -+ ->count() -+ ->execute(); - - $build = array( - '#theme' => 'item_list__user__online', -@@ -94,7 +127,13 @@ public function build() { - // Display a list of currently online users. - $max_users = $this->configuration['max_list_count']; - if ($authenticated_count && $max_users) { -- $uids = db_query_range('SELECT uid FROM {users} WHERE access >= :interval AND uid > 0 ORDER BY access DESC', 0, $max_users, array(':interval' => $interval))->fetchCol(); -+ $uids = $this->entityQuery->get('user') -+ ->condition('access', $interval, '>=') -+ ->condition('uid', 0, '>') -+ ->sort('access', 'DESC') -+ ->range(0, $max_users) -+ ->execute(); -+ - foreach (user_load_multiple($uids) as $account) { - $username = array( - '#theme' => 'username', diff --git a/core/modules/user/lib/Drupal/user/Plugin/Validation/Constraint/UserUniqueValidator.php b/core/modules/user/lib/Drupal/user/Plugin/Validation/Constraint/UserUniqueValidator.php index 945223f..f169cae 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/Validation/Constraint/UserUniqueValidator.php @@ -314,20 +236,19 @@ */ public function form(array $form, array &$form_state) { diff --git a/core/modules/user/lib/Drupal/user/UserAutocomplete.php b/core/modules/user/lib/Drupal/user/UserAutocomplete.php -index 4d36923..c0873db 100644 +index a7a20b2..16c31d6 100644 --- a/core/modules/user/lib/Drupal/user/UserAutocomplete.php +++ b/core/modules/user/lib/Drupal/user/UserAutocomplete.php -@@ -9,6 +9,9 @@ - +@@ -10,6 +10,8 @@ + use Drupal\Component\Utility\String; use Drupal\Core\Config\ConfigFactory; use Drupal\Core\Database\Connection; +use Drupal\Core\Entity\EntityManager; +use Drupal\Core\Entity\Query\QueryFactory; -+use Drupal\Component\Utility\String; /** * Defines a helper class to get user autocompletion results. -@@ -30,6 +33,20 @@ class UserAutocomplete { +@@ -31,6 +33,20 @@ class UserAutocomplete { protected $configFactory; /** @@ -348,7 +269,7 @@ * Constructs a UserAutocomplete object. * * @param \Drupal\Core\Database\Connection $connection -@@ -37,9 +54,11 @@ class UserAutocomplete { +@@ -38,9 +54,11 @@ class UserAutocomplete { * @param \Drupal\Core\Config\ConfigFactory $config_factory * The config factory. */ @@ -361,14 +282,13 @@ } /** -@@ -65,9 +84,15 @@ public function getMatches($string, $include_anonymous = FALSE) { - $matches[$anonymous_name] = check_plain($anonymous_name); +@@ -66,9 +84,14 @@ public function getMatches($string, $include_anonymous = FALSE) { + $matches[] = array('value' => $anonymous_name, 'label' => String::checkPlain($anonymous_name)); } } - $result = $this->connection->select('users')->fields('users', array('name'))->condition('name', db_like($string) . '%', 'LIKE')->range(0, 10)->execute(); - foreach ($result as $account) { -- $matches[$account->name] = check_plain($account->name); -+ +- $matches[] = array('value' => $account->name, 'label' => String::checkPlain($account->name)); + $uids = $this->entityQuery->get('user') + ->condition('name', $string, 'STARTS_WITH') + ->range(0, 10) @@ -376,7 +296,7 @@ + + $controller = $this->entityManager->getStorageController('user'); + foreach ($controller->loadMultiple($uids) as $account) { -+ $matches[$account->getUsername()] = String::checkPlain($account->getUsername()); ++ $matches[] = array('value' => $account->getUsername(), 'label' => String::checkPlain($account->getUsername())); } } @@ -478,7 +398,7 @@ // Anonymize old revisions. db_update('node_field_revision') diff --git a/core/modules/user/user.module b/core/modules/user/user.module -index 5751f02..4af3064 100644 +index b582725..ca190c6 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -464,16 +464,14 @@ function user_access($string, AccountInterface $account = NULL) { @@ -503,7 +423,7 @@ } /** -@@ -996,21 +994,20 @@ function user_authenticate($name, $password) { +@@ -990,21 +988,20 @@ function user_authenticate($name, $password) { function user_login_finalize(UserInterface $account) { global $user; $user = $account; @@ -530,7 +450,7 @@ } /** -@@ -1788,12 +1785,12 @@ function user_node_load($nodes, $types) { +@@ -1782,12 +1779,12 @@ function user_node_load($nodes, $types) { $uids[$nid] = $node->getAuthorId(); }