diff --git a/core/lib/Drupal/Core/Config/Entity/Query/Query.php b/core/lib/Drupal/Core/Config/Entity/Query/Query.php index f79656c..b4e4b46 100644 --- a/core/lib/Drupal/Core/Config/Entity/Query/Query.php +++ b/core/lib/Drupal/Core/Config/Entity/Query/Query.php @@ -34,13 +34,6 @@ class Query extends QueryBase implements QueryInterface { protected $configFactory; /** - * The config key store. - * - * @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface - */ - protected $configKeyStore; - - /** * The key value factory. * * @var \Drupal\Core\KeyValueStore\KeyValueFactoryInterface @@ -139,7 +132,7 @@ protected function loadRecords() { if ($this->condition->getConjunction() == 'AND') { $lookup_keys = $this->entityType->getLookupKeys(); $conditions = $this->condition->conditions(); - foreach ($conditions as $condition_key =>$condition) { + foreach ($conditions as $condition_key => $condition) { $operator = $condition['operator'] ?: (is_array($condition['value']) ? 'IN' : '='); if (is_string($condition['field']) && ($operator == 'IN' || $operator == '=')) { // Special case ID lookups. @@ -193,10 +186,7 @@ protected function loadRecords() { * The key value store used to store fast lookups. */ protected function getConfigKeyStore() { - if (!isset($this->configKeyStore)) { - $this->configKeyStore = $this->keyValueFactory->get(QueryFactory::CONFIG_LOOKUP_PREFIX . $this->entityTypeId); - } - return $this->configKeyStore; + return $this->keyValueFactory->get(QueryFactory::CONFIG_LOOKUP_PREFIX . $this->entityTypeId); } } diff --git a/core/lib/Drupal/Core/Config/Entity/Query/QueryFactory.php b/core/lib/Drupal/Core/Config/Entity/Query/QueryFactory.php index f7d385d..222e870 100644 --- a/core/lib/Drupal/Core/Config/Entity/Query/QueryFactory.php +++ b/core/lib/Drupal/Core/Config/Entity/Query/QueryFactory.php @@ -74,16 +74,16 @@ public function getAggregate(EntityTypeInterface $entity_type, $conjunction) { } /** - * Gets the key value store where denormalized data is stored. + * Gets the key value store used to store fast lookups. * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type * The entity type. * * @return \Drupal\Core\KeyValueStore\KeyValueStoreInterface - * The key value store where denormalized data is stored. + * The key value store used to store fast lookups. */ - protected function getKeyValueStore(EntityTypeInterface $entity_type) { - return $this->keyValueFactory->get(static::CONFIG_LOOKUP_PREFIX . $entity_type->id()); + protected function getConfigKeyStore(EntityTypeInterface $entity_type) { + return $this->keyValueFactory->get(QueryFactory::CONFIG_LOOKUP_PREFIX . $entity_type->id()); } /** @@ -95,9 +95,9 @@ protected function getKeyValueStore(EntityTypeInterface $entity_type) { * The configuration object that is being saved. */ protected function updateConfigKeyStore(ConfigEntityTypeInterface $entity_type, Config $config) { - $config_key_store = $this->getKeyValueStore($entity_type); + $config_key_store = $this->getConfigKeyStore($entity_type); foreach ($entity_type->getLookupKeys() as $lookup_key) { - foreach($this->getKeys($lookup_key, $config) as $key) { + foreach($this->getKeys($config, $lookup_key) as $key) { $values = $config_key_store->get($key, []); if (!in_array($config->getName(), $values, TRUE)) { $values[] = $config->getName(); @@ -118,7 +118,7 @@ protected function updateConfigKeyStore(ConfigEntityTypeInterface $entity_type, protected function deleteConfigKeyStore(ConfigEntityTypeInterface $entity_type, Config $config) { $config_key_store = $this->getKeyValueStore($entity_type); foreach ($entity_type->getLookupKeys() as $lookup_key) { - foreach ($this->getKeys($lookup_key, $config, 'getOriginal') as $key) { + foreach ($this->getKeys($config, $lookup_key, 'getOriginal') as $key) { $values = $config_key_store->get($key, []); if ($pos = array_search($config->getName(), $values, TRUE)) { unset($values[$pos]); @@ -136,10 +136,10 @@ protected function deleteConfigKeyStore(ConfigEntityTypeInterface $entity_type, /** * Creates lookup keys for configuration data. * - * @param $key - * The configuration key to look for. * @param \Drupal\Core\Config\Config $config * The configuration object. + * @param string $key + * The configuration key to look for. * @param string $get_method * Which method on the config object to call to get the value. Defaults to * 'get'. @@ -148,10 +148,10 @@ protected function deleteConfigKeyStore(ConfigEntityTypeInterface $entity_type, * An array of lookup keys concatenated to the configuration values. * * @throws \LogicException - * Keys ending with a wildcard make no sense since you can not query against - * this. + * The provided $key cannot end with a wildcard. This makes no sense since + * you cannot do fast lookups against this. */ - protected function getKeys($key, Config $config, $get_method = 'get') { + protected function getKeys(Config $config, $key, $get_method = 'get') { if (substr($key, -1) == '*') { throw new \LogicException(strtr('%key ends with a wildcard this can not be used as a lookup', ['%key' => $key])); } @@ -161,7 +161,7 @@ protected function getKeys($key, Config $config, $get_method = 'get') { $value = trim($value, '.'); }); - $values = (array) $this->getValues($config, $parts, $parts[0], $get_method); + $values = (array) $this->getValues($config, $parts[0], $get_method, $parts); $output = array(); // Flatten the array to a single dimension and add the key to all the @@ -180,19 +180,18 @@ protected function getKeys($key, Config $config, $get_method = 'get') { * * @param \Drupal\Core\Config\Config $config * The configuration object. - * @param array $parts - * All the parts of a configuration key we are checking. * @param string $key * The current key being checked. * @param string $get_method - * Which method on the config object to call to get the value. Defaults to - * 'get'. + * Which method on the config object to call to get the value. + * @param array $parts + * All the parts of a configuration key we are checking. * @param int $start - * Which position of $parts we are pocessing. + * Which position of $parts we are processing. Defaults to 0. * * @return array */ - protected function getValues(Config $config, array $parts, $key, $get_method = 'get', $start = 0) { + protected function getValues(Config $config, $key, $get_method, array $parts, $start = 0) { $value = $config->$get_method($key); if (is_array($value)) { $new_value = []; @@ -206,7 +205,7 @@ protected function getValues(Config $config, array $parts, $key, $get_method = ' if (!empty($parts[$start])) { $new_key .= '.' . $parts[$start]; } - $new_value[] = $this->getValues($config, $parts, $new_key, $get_method, $start); + $new_value[] = $this->getValues($config, $new_key, $get_method, $parts, $start); } $value = $new_value; } diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/Query/QueryFactoryTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/Query/QueryFactoryTest.php index 593cab1..019ff6c 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/Query/QueryFactoryTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/Query/QueryFactoryTest.php @@ -31,7 +31,7 @@ public function testGetKeys(array $expected, $key, Config $config) { $method = new \ReflectionMethod($query_factory, 'getKeys'); $method->setAccessible(TRUE); - $actual = $method->invoke($query_factory, $key, $config); + $actual = $method->invoke($query_factory, $config, $key); $this->assertEquals($expected, $actual); } @@ -114,7 +114,7 @@ public function testGetKeysWildCardEnd() { $method = new \ReflectionMethod($query_factory, 'getKeys'); $method->setAccessible(TRUE); - $method->invoke($query_factory, 'test.*', $this->getConfigObject('test')); + $method->invoke($query_factory, $this->getConfigObject('test'), 'test.*'); } /**