diff --git a/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php b/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php index 52d01b7..0412a99 100644 --- a/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php +++ b/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php @@ -378,6 +378,7 @@ public function renameTable($table, $new_name) { } parent::renameTable($table, $new_name); + $info = $this->getPrefixInfo($new_name); return $this->connection->query('ALTER TABLE {' . $table . '} RENAME TO `' . $info['table'] . '`'); } diff --git a/core/lib/Drupal/Core/Database/Schema.php b/core/lib/Drupal/Core/Database/Schema.php index 67807c0..f2cd9e6 100644 --- a/core/lib/Drupal/Core/Database/Schema.php +++ b/core/lib/Drupal/Core/Database/Schema.php @@ -7,9 +7,10 @@ namespace Drupal\Core\Database; -use Drupal\Core\Database\SchemaObjectExistsException; use Drupal\Core\Database\Query\Condition; use Drupal\Core\Database\Query\PlaceholderInterface; +use Drupal\Core\DependencyInjection\ContainerNotInitializedException; +use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; /** * Provides a base implementation for Database Schema. @@ -44,7 +45,7 @@ * * @var \Drupal\Core\Cache\CacheBackendInterface */ - protected $cacheBin; + protected $cacheBin = NULL; /** * A unique identifier for this query object. @@ -54,7 +55,12 @@ public function __construct($connection) { $this->uniqueIdentifier = uniqid('', TRUE); $this->connection = $connection; - $this->cacheBin = \Drupal::cache(); + try { + $this->cacheBin = \Drupal::cache(); + } + // During the installation there's only a minimal container in place. + catch (InvalidArgumentException $e) { } + catch (ContainerNotInitializedException $e) { } } /** @@ -293,7 +299,7 @@ public function fieldExists($table, $column) { * If a table with the specified new name already exists. */ public function renameTable($table, $new_name) { - $this->cacheBin->delete("table_mapping:$table"); + $this->clearTableMappingCache($table); } /** @@ -307,7 +313,7 @@ public function renameTable($table, $new_name) { * by that name to begin with. */ public function dropTable($table) { - $this->cacheBin->delete("table_mapping:$table"); + $this->clearTableMappingCache($table); return TRUE; } @@ -338,7 +344,7 @@ public function dropTable($table) { * If the specified table already has a field by that name. */ public function addField($table, $field, $spec, $keys_new = array()) { - $this->cacheBin->delete("table_mapping:$table"); + $this->clearTableMappingCache($table); } /** @@ -354,7 +360,7 @@ public function addField($table, $field, $spec, $keys_new = array()) { * by that name to begin with. */ public function dropField($table, $field) { - $this->cacheBin->delete("table_mapping:$table"); + $this->clearTableMappingCache($table); return TRUE; } @@ -599,7 +605,7 @@ public function dropField($table, $field) { * If the specified destination field already exists. */ public function changeField($table, $field, $field_new, $spec, $keys_new = array()) { - $this->cacheBin->delete("table_mapping:$table"); + $this->clearTableMappingCache($table); } /** @@ -679,4 +685,17 @@ protected function escapeDefaultValue($value) { } return is_string($value) ? $this->connection->quote($value) : $value; } + + /** + * Clears the table mapping cache for a specific table. + * + * @param string $table + * The table for which the table mapping cache is cleared. + */ + protected function clearTableMappingCache($table) { + if ($this->cacheBin) { + $this->cacheBin->delete("table_mapping:$table"); + } + } + }