|
|
@ -10,9 +10,10 @@ use Drupal\field\Entity\FieldStorageConfig; |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Updates Media file size field storage for larger files. |
|
|
|
* Updates Media file size field storage for larger files. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function islandora_core_feature_update_8001() { |
|
|
|
function islandora_core_feature_update_8001(&$sandbox) { |
|
|
|
|
|
|
|
|
|
|
|
$entity_type = 'media'; |
|
|
|
$entity_type = 'media'; |
|
|
|
|
|
|
|
|
|
|
|
$field_name = 'field_file_size'; |
|
|
|
$field_name = 'field_file_size'; |
|
|
|
|
|
|
|
|
|
|
|
$database = \Drupal::database(); |
|
|
|
$database = \Drupal::database(); |
|
|
@ -21,8 +22,18 @@ function islandora_core_feature_update_8001() { |
|
|
|
"{$entity_type}_revision__{$field_name}", |
|
|
|
"{$entity_type}_revision__{$field_name}", |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!isset($sandbox['progress'])) { |
|
|
|
|
|
|
|
$sandbox['upper_limit'] = 0; |
|
|
|
foreach ($tables as $table) { |
|
|
|
foreach ($tables as $table) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Record size of the table for future use. |
|
|
|
|
|
|
|
$sandbox[$table]['size'] = $database->select($table) |
|
|
|
|
|
|
|
->countQuery() |
|
|
|
|
|
|
|
->execute() |
|
|
|
|
|
|
|
->fetchField(); |
|
|
|
|
|
|
|
if ($sandbox[$table]['size'] > $sandbox['upper_limit']) { |
|
|
|
|
|
|
|
$sandbox['upper_limit'] = $sandbox[$table]['size']; |
|
|
|
|
|
|
|
} |
|
|
|
// Move the existing data out of the way. |
|
|
|
// Move the existing data out of the way. |
|
|
|
$database->schema()->renameTable($table, $table . '_o'); |
|
|
|
$database->schema()->renameTable($table, $table . '_o'); |
|
|
|
|
|
|
|
|
|
|
@ -76,6 +87,7 @@ function islandora_core_feature_update_8001() { |
|
|
|
'primary key' => ['entity_id', 'deleted', 'delta', 'langcode'], |
|
|
|
'primary key' => ['entity_id', 'deleted', 'delta', 'langcode'], |
|
|
|
'indexes' => ['bundle' => ['bundle'], 'revision_id' => ['revision_id']], |
|
|
|
'indexes' => ['bundle' => ['bundle'], 'revision_id' => ['revision_id']], |
|
|
|
]); |
|
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Update field storage configuration. |
|
|
|
// Update field storage configuration. |
|
|
@ -88,15 +100,35 @@ 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(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Track batch reload progress. |
|
|
|
|
|
|
|
$sandbox['progress'] = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Arbitrary, hopefully reasonable, batch size per table. |
|
|
|
|
|
|
|
$limit = 500; |
|
|
|
|
|
|
|
|
|
|
|
// Reload the data and clean up. |
|
|
|
// Reload the data and clean up. |
|
|
|
foreach ($tables as $table) { |
|
|
|
foreach ($tables as $table) { |
|
|
|
$query = $database->select($table . '_o', 'o')->fields('o'); |
|
|
|
if (!isset($sandbox[$table]['done'])) { |
|
|
|
|
|
|
|
$query = $database->select($table . '_o', 'o')->fields('o') |
|
|
|
|
|
|
|
->orderBy('o.entity_id', 'ASC') |
|
|
|
|
|
|
|
->orderBy('o.revision_id', 'ASC') |
|
|
|
|
|
|
|
->orderBy('o.delta', 'ASC') |
|
|
|
|
|
|
|
->range($sandbox['progress'], $sandbox['progress'] + $limit); |
|
|
|
$database->insert($table)->from($query)->execute(); |
|
|
|
$database->insert($table)->from($query)->execute(); |
|
|
|
$database->schema()->dropTable($table . '_o'); |
|
|
|
$database->schema()->dropTable($table . '_o'); |
|
|
|
|
|
|
|
if ($sandbox['progress'] + $limit >= $progress[$table]['size']) { |
|
|
|
|
|
|
|
$sandbox[$table]['done'] = TRUE; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$sandbox['progress'] = $sandbox['progress'] + $limit; |
|
|
|
|
|
|
|
$sandbox['#finished'] = $sandbox['progress'] >= $sandbox['upper_limit'] ? 1 : $sandbox['progress'] / $sandbox['upper_limit']; |
|
|
|
|
|
|
|
if ($sandbox['#finished'] == 1) { |
|
|
|
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', [ |
|
|
|
'@entity-type' => $entity_type, |
|
|
|
'@entity-type' => $entity_type, |
|
|
|
'@field-name' => $field_name, |
|
|
|
'@field-name' => $field_name, |
|
|
|
]); |
|
|
|
]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|