Skip to content
Snippets Groups Projects
Commit d8b92d57 authored by catch's avatar catch
Browse files

Issue #3181013 by Driskell, alexpott, ericgsmith, Pan Lee, smustgrave, Kristen...

Issue #3181013 by Driskell, alexpott, ericgsmith, Pan Lee, smustgrave, Kristen Pol, mxr576: Faulty permanent config cache has been set to the cache backend on failed sql server connection

(cherry picked from commit 201fd312)
parent 3f1801bf
No related branches found
Tags 5.x-1.0-rc2
4 merge requests!7564Revert "Issue #3364773 by roshnichordiya, Chris Matthews, thakurnishant_06,...,!5752Issue #3275828 by joachim, quietone, bradjones1, Berdir: document the reason...,!5627Issue #3261805: Field not saved when change of 0 on string start,!3106Issue #3017548: "Filtered HTML" text format does not support manual teaser break (<!--break-->)
Pipeline #55586 passed
......@@ -72,8 +72,11 @@ public function exists($name) {
], $this->options)->fetchField();
}
catch (\Exception $e) {
// If we attempt a read without actually having the database or the table
// available, just return FALSE so the caller can handle it.
if ($this->connection->schema()->tableExists($this->table)) {
throw $e;
}
// If we attempt a read without actually having the table available,
// return false so the caller can handle it.
return FALSE;
}
}
......@@ -90,8 +93,11 @@ public function read($name) {
}
}
catch (\Exception $e) {
// If we attempt a read without actually having the database or the table
// available, just return FALSE so the caller can handle it.
if ($this->connection->schema()->tableExists($this->table)) {
throw $e;
}
// If we attempt a read without actually having the table available,
// return false so the caller can handle it.
}
return $data;
}
......@@ -108,8 +114,11 @@ public function readMultiple(array $names) {
}
}
catch (\Exception $e) {
// If we attempt a read without actually having the database or the table
// available, just return an empty array so the caller can handle it.
if ($this->connection->schema()->tableExists($this->table)) {
throw $e;
}
// If we attempt a read without actually having the table available,
// return an empty array so the caller can handle it.
}
return $list;
}
......@@ -277,6 +286,11 @@ public function listAll($prefix = '') {
return $query->execute()->fetchCol();
}
catch (\Exception $e) {
if ($this->connection->schema()->tableExists($this->table)) {
throw $e;
}
// If we attempt a read without actually having the table available,
// return an empty array so the caller can handle it.
return [];
}
}
......@@ -295,6 +309,11 @@ public function deleteAll($prefix = '') {
->execute();
}
catch (\Exception $e) {
if ($this->connection->schema()->tableExists($this->table)) {
throw $e;
}
// If we attempt a delete without actually having the table available,
// return false so the caller can handle it.
return FALSE;
}
}
......@@ -328,6 +347,11 @@ public function getAllCollectionNames() {
])->fetchCol();
}
catch (\Exception $e) {
if ($this->connection->schema()->tableExists($this->table)) {
throw $e;
}
// If we attempt a read without actually having the table available,
// return an empty array so the caller can handle it.
return [];
}
}
......
......@@ -4,6 +4,7 @@
use Drupal\Core\Config\DatabaseStorage;
use Drupal\Core\Database\Database;
use Drupal\Core\Database\DatabaseExceptionWrapper;
/**
* Tests DatabaseStorage operations.
......@@ -39,4 +40,87 @@ protected function delete($name) {
Database::getConnection()->delete('config')->condition('name', $name)->execute();
}
/**
* Tests that operations throw exceptions if the query fails.
*/
public function testExceptionIsThrownIfQueryFails() {
$connection = Database::getConnection();
if ($connection->databaseType() === 'sqlite') {
// See: https://www.drupal.org/project/drupal/issues/3349286
$this->markTestSkipped('SQLite cannot allow detection of exceptions due to double quoting.');
return;
}
Database::getConnection()->schema()->dropTable('config');
// In order to simulate database issue create a table with an incorrect
// specification.
$table_specification = [
'fields' => [
'id' => [
'type' => 'int',
'default' => NULL,
],
],
];
Database::getConnection()->schema()->createTable('config', $table_specification);
try {
$this->storage->exists('config.settings');
$this->fail('Expected exception not thrown from exists()');
}
catch (DatabaseExceptionWrapper $e) {
// Exception was expected
}
try {
$this->storage->read('config.settings');
$this->fail('Expected exception not thrown from read()');
}
catch (DatabaseExceptionWrapper $e) {
// Exception was expected
}
try {
$this->storage->readMultiple(['config.settings', 'config.settings2']);
$this->fail('Expected exception not thrown from readMultiple()');
}
catch (DatabaseExceptionWrapper $e) {
// Exception was expected
}
try {
$this->storage->write('config.settings', ['data' => '']);
$this->fail('Expected exception not thrown from deleteAll()');
}
catch (DatabaseExceptionWrapper $e) {
// Exception was expected
}
try {
$this->storage->listAll();
$this->fail('Expected exception not thrown from listAll()');
}
catch (DatabaseExceptionWrapper $e) {
// Exception was expected
}
try {
$this->storage->deleteAll();
$this->fail('Expected exception not thrown from deleteAll()');
}
catch (DatabaseExceptionWrapper $e) {
// Exception was expected
}
try {
$this->storage->getAllCollectionNames();
$this->fail('Expected exception not thrown from getAllCollectionNames()');
}
catch (DatabaseExceptionWrapper $e) {
// Exception was expected
}
$this->assertTrue(TRUE);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment