diff --git a/core/includes/cache.inc b/core/includes/cache.inc index 89506a0..06b0ab1 100644 --- a/core/includes/cache.inc +++ b/core/includes/cache.inc @@ -53,17 +53,7 @@ function cache($bin = 'cache') { * The list of tags to invalidate cache items for. */ function cache_invalidate(array $tags) { - foreach (cache_get_backends() as $bin => $class) { + foreach (CacheFactory::getBackends() as $bin => $class) { cache($bin)->invalidateTags($tags); } } - -/** - * Returns a list of cache backends for this site. - * - * @return - * An associative array with cache bins as keys, and backend classes as value. - */ -function cache_get_backends() { - return variable_get('cache_classes', array('cache' => 'Drupal\Core\Cache\DatabaseBackend')); -} diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index 09b3e86..94b1c4a 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -280,9 +280,13 @@ function install_begin_request(&$install_state) { // If it is not, replace the configuration storage with the InstallStorage // implementation, for the following reasons: // - The first call into drupal_container() will try to set up the regular - // runtime configuration storage, using the CachedStorage. The storage - // controller requires to pass in the active config directory name, but that - // directory does not exist yet. + // runtime configuration storage, using the CachedStorage by default. It + // calls config_get_config_directory() to retrieve the config directory to + // use, but that throws an exception, since $config_directories is not + // defined since there is no settings.php yet. If there is a prepared + // settings.php already, then the returned directory still cannot be used, + // because it does not necessarily exist. The installer ensures that it + // exists and is writeable in a later step. // - The installer outputs maintenance theme pages and performs many other // operations, which try to load configuration. Since there is no active // configuration yet, and because the configuration system does not have a diff --git a/core/lib/Drupal/Core/Cache/CacheFactory.php b/core/lib/Drupal/Core/Cache/CacheFactory.php index fdbaeb7..da42a26 100644 --- a/core/lib/Drupal/Core/Cache/CacheFactory.php +++ b/core/lib/Drupal/Core/Cache/CacheFactory.php @@ -27,22 +27,30 @@ class CacheFactory { * @return Drupal\Core\Cache\CacheBackendInterface * The cache backend object associated with the specified bin. */ - static function get($bin) { + public static function get($bin) { + // Check whether there is a custom class defined for the requested bin or + // use the default 'cache' definition otherwise. + $cache_backends = self::getBackends(); + $class = isset($cache_backends[$bin]) ? $cache_backends[$bin] : $cache_backends['cache']; + return new $class($bin); + } + + /** + * Returns a list of cache backends for this site. + * + * @return array + * An associative array with cache bins as keys, and backend class names as + * value. + */ + public static function getBackends() { // @todo Improve how cache backend classes are defined. Cannot be // configuration, since e.g. the CachedStorage config storage controller // requires the definition in its constructor already. global $conf; $cache_backends = isset($conf['cache_classes']) ? $conf['cache_classes'] : array(); - - // Check whether there is a custom class defined for the requested bin and - // default to the DatabaseBackend otherwise. - if (isset($cache_backends[$bin])) { - $class = $cache_backends[$bin]; - } - else { - $class = 'Drupal\Core\Cache\DatabaseBackend'; - } - return new $class($bin); + // Ensure there is a default 'cache' bin definition. + $cache_backends += array('cache' => 'Drupal\Core\Cache\DatabaseBackend'); + return $cache_backends; } } diff --git a/core/lib/Drupal/Core/Config/CachedStorage.php b/core/lib/Drupal/Core/Config/CachedStorage.php index e17f56f..2278bf9 100644 --- a/core/lib/Drupal/Core/Config/CachedStorage.php +++ b/core/lib/Drupal/Core/Config/CachedStorage.php @@ -49,8 +49,9 @@ public function __construct(StorageInterface $storage, CacheBackendInterface $ca * Implements Drupal\Core\Config\StorageInterface::exists(). */ public function exists($name) { - // A single storage lookup is faster than a cache lookup and possibly - // subsequent storage lookup. + // The cache would read in the entire data (instead of only checking whether + // any data exists), and on a potential cache miss, an additional storage + // lookup would have to happen, so check the storage directly. return $this->storage->exists($name); } @@ -70,6 +71,11 @@ public function read($name) { if ($data !== FALSE) { $this->cache->set($name, $data, CacheBackendInterface::CACHE_PERMANENT, array('config' => array($name))); } + // If the cache contained bogus data and there is no data in the storage, + // wipe the cache entry. + elseif ($cache) { + $this->cache->delete($name); + } return $data; } @@ -77,6 +83,8 @@ public function read($name) { * Implements Drupal\Core\Config\StorageInterface::write(). */ public function write($name, array $data) { + // Not all data that is written is necessarily read; just invalidate the + // cache. $this->cache->delete($name); return $this->storage->write($name, $data); } @@ -101,14 +109,14 @@ public function rename($name, $new_name) { /** * Implements Drupal\Core\Config\StorageInterface::encode(). */ - public static function encode($data) { + public function encode($data) { return $this->storage->encode($data); } /** * Implements Drupal\Core\Config\StorageInterface::decode(). */ - public static function decode($raw) { + public function decode($raw) { return $this->storage->decode($raw); } diff --git a/core/lib/Drupal/Core/Config/DatabaseStorage.php b/core/lib/Drupal/Core/Config/DatabaseStorage.php index 43c8168..1fb87b0 100644 --- a/core/lib/Drupal/Core/Config/DatabaseStorage.php +++ b/core/lib/Drupal/Core/Config/DatabaseStorage.php @@ -57,7 +57,7 @@ public function __construct(Connection $connection, $table, array $options = arr * Implements Drupal\Core\Config\StorageInterface::exists(). */ public function exists($name) { - return (bool) $this->connection->queryRange('SELECT 1 FROM {' . $this->table . '} WHERE name = :name', 0, 1, array( + return (bool) $this->connection->queryRange('SELECT 1 FROM {' . $this->connection->escapeTable($this->table) . '} WHERE name = :name', 0, 1, array( ':name' => $name, ), $this->options)->fetchField(); } @@ -76,7 +76,7 @@ public function read($name) { // catch the exception and just return an empty array so the caller can // handle it if need be. try { - $raw = $this->connection->query('SELECT data FROM {' . $this->table . '} WHERE name = :name', array(':name' => $name), $this->options)->fetchField(); + $raw = $this->connection->query('SELECT data FROM {' . $this->connection->escapeTable($this->table) . '} WHERE name = :name', array(':name' => $name), $this->options)->fetchField(); if ($raw !== FALSE) { $data = $this->decode($raw); } @@ -156,7 +156,7 @@ public function decode($raw) { * Only thrown in case $this->options['throw_exception'] is TRUE. */ public function listAll($prefix = '') { - return $this->connection->query('SELECT name FROM {' . $this->table . '} WHERE name LIKE :name', array( + return $this->connection->query('SELECT name FROM {' . $this->connection->escapeTable($this->table) . '} WHERE name LIKE :name', array( ':name' => db_like($prefix) . '%', ), $this->options)->fetchCol(); } diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchExcerptTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchExcerptTest.php index 99fd422..d97975b 100644 --- a/core/modules/search/lib/Drupal/search/Tests/SearchExcerptTest.php +++ b/core/modules/search/lib/Drupal/search/Tests/SearchExcerptTest.php @@ -13,6 +13,12 @@ * Tests the search_excerpt() function. */ class SearchExcerptTest extends WebTestBase { + + /** + * Modules to enable. + * + * @var array + */ public static $modules = array('search'); public static function getInfo() {