Browse Source

Rename, recreate, and reload tables instead of using temporary files.

pull/829/head
Seth Shaw 4 years ago
parent
commit
a52617e99d
  1. 72
      modules/islandora_core_feature/islandora_core_feature.install

72
modules/islandora_core_feature/islandora_core_feature.install

@ -23,23 +23,59 @@ function islandora_core_feature_update_8001() {
foreach ($tables as $table) { foreach ($tables as $table) {
// Squirrel away the data. // Move the existing data out of the way.
$table_file_path = "public://islandora_core_feature_update_8001_{$table}.json"; $database->schema()->renameTable($table, $table . '_o');
if (!file_exists($table_file_path)) {
$table_data = $database->select($table, 'n')->fields('n')->execute()->fetchAll();
\Drupal::service('file_system')->saveData(json_encode($table_data), $table_file_path);
}
// Clean it out for resizing. // Create replacement tables.
$database->truncate($table)->execute(); $database->schema()->createTable($table, [
'fields' => [
'bundle' => [
'type' => 'varchar',
'not null' => TRUE,
'length' => 128,
'default' => ' ',
],
'deleted' => [
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
],
'entity_id' => [
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'length' => 10,
$database->schema()->changeField($table, $field_name . '_value', $field_name . '_value', [ ],
'revision_id' => [
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'length' => 10,
],
'langcode' => [
'type' => 'varchar',
'not null' => TRUE,
'length' => 32,
'default' => ' ',
],
'delta' => [
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'length' => 10,
],
'field_file_size_value' => [
'type' => 'int', 'type' => 'int',
'size' => 'big', 'size' => 'big',
'unsigned' => TRUE, 'unsigned' => TRUE,
'not null' => TRUE, 'not null' => TRUE,
],
],
'primary key' => ['entity_id', 'deleted', 'delta', 'langcode'],
'indexes' => ['bundle' => ['bundle'], 'revision_id' => ['revision_id']],
]); ]);
} }
// Update field storage configuration. // Update field storage configuration.
@ -52,19 +88,11 @@ function islandora_core_feature_update_8001() {
// Make sure the new config persists. // Make sure the new config persists.
FieldStorageConfig::loadByName($entity_type, $field_name)->save(); FieldStorageConfig::loadByName($entity_type, $field_name)->save();
// Reload the data. // Reload the data and clean up.
foreach ($tables as $table) { foreach ($tables as $table) {
$table_file_path = "public://islandora_core_feature_update_8001_{$table}.json"; $query = $database->select($table . '_o', 'o')->fields('o');
if (file_exists($table_file_path)) { $database->insert($table)->from($query)->execute();
foreach (json_decode(file_get_contents($table_file_path), TRUE) as $row) { $database->schema()->dropTable($table . '_o');
$database->insert($table)
->fields((array) $row)
->execute();
}
// Clean up.
\Drupal::service('file_system')->delete($table_file_path);
}
} }
return t('Length of @entity-type.@field-name updated to an unsigned big int', [ return t('Length of @entity-type.@field-name updated to an unsigned big int', [

Loading…
Cancel
Save