diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php index 369e903..b3313dd 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php @@ -477,8 +477,20 @@ protected function postUpdateEntityTypeSchema(EntityTypeInterface $entity_type, // Rename the original tables so we can put them back in place in case // anything goes wrong. $backup_table_names = array_combine($original_table_mapping->getTableNames(), $backup_table_mapping->getTableNames()); - foreach ($backup_table_names as $original_table_name => $backup_table_name) { - $this->database->schema()->renameTable($original_table_name, $backup_table_name); + $renamed_tables = []; + try { + foreach ($backup_table_names as $original_table_name => $backup_table_name) { + $this->database->schema()->renameTable($original_table_name, $backup_table_name); + $renamed_tables[$original_table_name] = $backup_table_name; + } + } + catch (\Exception $e) { + foreach ($renamed_tables as $original_table_name => $backup_table_name) { + $this->database->schema()->renameTable($backup_table_name, $original_table_name); + } + + // Re-throw the original exception. + throw $e; } // Put the new tables in place and update the entity type and field storage diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlEntityTypeSchemaListenerTrait.php b/core/lib/Drupal/Core/Entity/Sql/SqlEntityTypeSchemaListenerTrait.php index d6f840b..b019670 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlEntityTypeSchemaListenerTrait.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlEntityTypeSchemaListenerTrait.php @@ -220,15 +220,15 @@ protected function copyData(EntityTypeInterface $entity_type, EntityTypeInterfac $sandbox['current_id'] = $identifier; } - // If we're not in maintenance mode, the number of entities could change at - // any time so make sure that we always use the latest record count. + // Get an updated count of entities that still need to migrated to the new + // storage. $missing = $this->database->select($table_name, 't') ->condition("t.$identifier_field", $sandbox['current_id'], '>') ->orderBy($identifier_field, 'ASC') ->countQuery() ->execute() ->fetchField(); - $sandbox['#finished'] = $sandbox['progress'] / ($sandbox['progress'] + (int) $missing); + $sandbox['#finished'] = $missing ? $sandbox['progress'] / ($sandbox['progress'] + (int) $missing) : 1; } /**