diff --git a/core/lib/Drupal/Core/Config/DatabaseStorage.php b/core/lib/Drupal/Core/Config/DatabaseStorage.php index 162fd46..1dd8507 100644 --- a/core/lib/Drupal/Core/Config/DatabaseStorage.php +++ b/core/lib/Drupal/Core/Config/DatabaseStorage.php @@ -18,7 +18,8 @@ class DatabaseStorage implements StorageInterface { /** * Database connection options for this storage controller. * - * - target: The connection to use for storage operations. + * - connection: The connection key to use. + * - target: The target on the connection to use. * * @var array */ @@ -29,6 +30,7 @@ class DatabaseStorage implements StorageInterface { */ public function __construct(array $options = array()) { $options += array( + 'connection' => 'default', 'target' => 'default', ); $this->options = $options; @@ -38,7 +40,7 @@ class DatabaseStorage implements StorageInterface { * Returns the database connection to use. */ protected function getConnection() { - return Database::getConnection($this->options['target']); + return Database::getConnection($this->options['target'], $this->options['connection']); } /** @@ -71,6 +73,8 @@ class DatabaseStorage implements StorageInterface { * Implements Drupal\Core\Config\StorageInterface::write(). * * @throws PDOException + * + * @todo Ignore slave targets for data manipulation operations. */ public function write($name, array $data) { $data = $this->encode($data); @@ -85,6 +89,8 @@ class DatabaseStorage implements StorageInterface { * Implements Drupal\Core\Config\StorageInterface::delete(). * * @throws PDOException + * + * @todo Ignore slave targets for data manipulation operations. */ public function delete($name) { $options = array('return' => Database::RETURN_AFFECTED) + $this->options; diff --git a/core/lib/Drupal/Core/Config/FileStorage.php b/core/lib/Drupal/Core/Config/FileStorage.php index cee29ae..7827dc0 100644 --- a/core/lib/Drupal/Core/Config/FileStorage.php +++ b/core/lib/Drupal/Core/Config/FileStorage.php @@ -94,7 +94,7 @@ class FileStorage implements StorageInterface { */ public function write($name, array $data) { $data = $this->encode($data); - $status = file_put_contents($this->getFilePath($name), $data); + $status = @file_put_contents($this->getFilePath($name), $data); if ($status === FALSE) { throw new StorageException('Failed to write configuration file: ' . $this->getFilePath($name)); } @@ -106,6 +106,9 @@ class FileStorage implements StorageInterface { */ public function delete($name) { if (!$this->exists($name)) { + if (!file_exists($this->options['directory'])) { + throw new StorageException($this->options['directory'] . '/ not found.'); + } return FALSE; } return drupal_unlink($this->getFilePath($name)); @@ -138,11 +141,13 @@ class FileStorage implements StorageInterface { * Implements Drupal\Core\Config\StorageInterface::listAll(). */ public function listAll($prefix = '') { + // glob() silently ignores the error of a non-existing search directory, + // even with the GLOB_ERR flag. + if (!file_exists($this->options['directory'])) { + throw new StorageException($this->options['directory'] . '/ not found.'); + } $extension = '.' . self::getFileExtension(); $files = glob($this->options['directory'] . '/' . $prefix . '*' . $extension); - if ($files === FALSE) { - return array(); - } $clean_name = function ($value) use ($extension) { return basename($value, $extension); }; diff --git a/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php b/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php index 98a9bd3..b811199 100644 --- a/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php +++ b/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php @@ -33,6 +33,7 @@ class ContainerBuilder extends BaseContainerBuilder { // Register configuration storage dispatcher. $this->setParameter('config.storage.info', array( 'Drupal\Core\Config\DatabaseStorage' => array( + 'connection' => 'default', 'target' => 'default', 'read' => TRUE, 'write' => TRUE, diff --git a/core/modules/config/lib/Drupal/config/Tests/Storage/ConfigStorageTestBase.php b/core/modules/config/lib/Drupal/config/Tests/Storage/ConfigStorageTestBase.php index 15ccb90..3e6b254 100644 --- a/core/modules/config/lib/Drupal/config/Tests/Storage/ConfigStorageTestBase.php +++ b/core/modules/config/lib/Drupal/config/Tests/Storage/ConfigStorageTestBase.php @@ -86,7 +86,8 @@ abstract class ConfigStorageTestBase extends WebTestBase { $this->fail('Exception not thrown upon writing to a non-existing storage bin.'); } catch (\Exception $e) { - $this->pass('Exception thrown upon writing to a non-existing storage bin.'); + $class = get_class($e); + $this->pass($class . ' thrown upon writing to a non-existing storage bin.'); } // Deleting from a non-existing storage bin throws an exception. @@ -95,7 +96,8 @@ abstract class ConfigStorageTestBase extends WebTestBase { $this->fail('Exception not thrown upon deleting from a non-existing storage bin.'); } catch (\Exception $e) { - $this->pass('Exception thrown upon deleting from a non-existing storage bin.'); + $class = get_class($e); + $this->pass($class . ' thrown upon deleting from a non-existing storage bin.'); } // Listing on a non-existing storage bin throws an exception. @@ -104,7 +106,8 @@ abstract class ConfigStorageTestBase extends WebTestBase { $this->fail('Exception not thrown upon listing from a non-existing storage bin.'); } catch (\Exception $e) { - $this->pass('Exception thrown upon listing from a non-existing storage bin.'); + $class = get_class($e); + $this->pass($class . ' thrown upon listing from a non-existing storage bin.'); } } diff --git a/core/modules/config/lib/Drupal/config/Tests/Storage/DatabaseStorageTest.php b/core/modules/config/lib/Drupal/config/Tests/Storage/DatabaseStorageTest.php index 6fa1094..2e1599f 100644 --- a/core/modules/config/lib/Drupal/config/Tests/Storage/DatabaseStorageTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/Storage/DatabaseStorageTest.php @@ -24,7 +24,7 @@ class DatabaseStorageTest extends ConfigStorageTestBase { function setUp() { parent::setUp(); $this->storage = new DatabaseStorage(); - $this->invalidStorage = new DatabaseStorage(array('target' => 'invalid')); + $this->invalidStorage = new DatabaseStorage(array('connection' => 'invalid')); } protected function read($name) {