Issue #3099986 by alexpott, amateescu: Move part of workspaces_post_update_move_association_data() to a hook_update_N
parent
258c4eac9c
commit
73dc06a6c4
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Entity\ContentEntityNullStorage;
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
use Drupal\workspaces\Entity\Workspace;
|
||||
|
||||
|
@ -174,3 +175,23 @@ function workspaces_update_8802() {
|
|||
|
||||
$entity_definition_update_manager->installFieldStorageDefinition('parent', 'workspace', 'workspaces', $storage_definition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the Workspace Association entity storage if necessary.
|
||||
*/
|
||||
function workspaces_update_8803() {
|
||||
$entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
|
||||
$entity_type = $entity_definition_update_manager->getEntityType('workspace_association');
|
||||
|
||||
// We can't migrate the workspace association data if the entity type is not
|
||||
// using its default storage.
|
||||
// @see workspaces_post_update_move_association_data()
|
||||
if ($entity_type && $entity_type->getHandlerClasses()['storage'] === 'Drupal\workspaces\WorkspaceAssociationStorage') {
|
||||
\Drupal::state()->set('workspaces_update_8803.tables', [
|
||||
'base_table' => $entity_type->getBaseTable(),
|
||||
'revision_table' => $entity_type->getRevisionTable(),
|
||||
]);
|
||||
$entity_type->setStorageClass(ContentEntityNullStorage::class);
|
||||
$entity_definition_update_manager->uninstallEntityType($entity_type);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,10 +5,8 @@
|
|||
* Post update functions for the Workspaces module.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityNullStorage;
|
||||
use Drupal\Core\Entity\Entity\EntityFormDisplay;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
|
||||
use Drupal\Core\Site\Settings;
|
||||
|
||||
/**
|
||||
|
@ -31,20 +29,14 @@ function workspaces_post_update_remove_default_workspace() {
|
|||
*/
|
||||
function workspaces_post_update_move_association_data(&$sandbox) {
|
||||
$database = \Drupal::database();
|
||||
$entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
|
||||
$entity_type_manager = \Drupal::entityTypeManager();
|
||||
$entity_type = $entity_definition_update_manager->getEntityType('workspace_association');
|
||||
|
||||
// We can't migrate the workspace association data if the entity type is not
|
||||
// using its default storage.
|
||||
if ($entity_type->getHandlerClasses()['storage'] !== 'Drupal\workspaces\WorkspaceAssociationStorage') {
|
||||
// @see workspaces_update_8803()
|
||||
$tables = \Drupal::state()->get('workspaces_update_8803.tables');
|
||||
if (!$tables) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Since the custom storage class doesn't exist anymore, we have to use core's
|
||||
// default storage.
|
||||
$entity_type->setStorageClass(SqlContentEntityStorage::class);
|
||||
|
||||
// If 'progress' is not set, this will be the first run of the batch.
|
||||
if (!isset($sandbox['progress'])) {
|
||||
$sandbox['progress'] = 0;
|
||||
|
@ -93,12 +85,12 @@ function workspaces_post_update_move_association_data(&$sandbox) {
|
|||
|
||||
// Copy all the data from the base table of the 'workspace_association'
|
||||
// entity type to the temporary association table.
|
||||
$select = $database->select($entity_type->getBaseTable())
|
||||
->fields($entity_type->getBaseTable(), ['workspace', 'target_entity_type_id', 'target_entity_id', 'target_entity_revision_id']);
|
||||
$select = $database->select($tables['base_table'])
|
||||
->fields($tables['base_table'], ['workspace', 'target_entity_type_id', 'target_entity_id', 'target_entity_revision_id']);
|
||||
$database->insert('tmp_workspace_association')->from($select)->execute();
|
||||
}
|
||||
|
||||
$table_name = $entity_type->getRevisionTable();
|
||||
$table_name = $tables['revision_table'];
|
||||
$revision_field_name = 'revision_id';
|
||||
|
||||
// Get the next entity association revision records to migrate.
|
||||
|
@ -136,12 +128,10 @@ function workspaces_post_update_move_association_data(&$sandbox) {
|
|||
// Uninstall the 'workspace_association' entity type and rename the temporary
|
||||
// table.
|
||||
if ($sandbox['#finished'] == 1) {
|
||||
$entity_type->setStorageClass(ContentEntityNullStorage::class);
|
||||
$entity_definition_update_manager->uninstallEntityType($entity_type);
|
||||
$database->schema()->dropTable('workspace_association');
|
||||
$database->schema()->dropTable('workspace_association_revision');
|
||||
|
||||
$database->schema()->dropTable($tables['base_table']);
|
||||
$database->schema()->dropTable($tables['revision_table']);
|
||||
$database->schema()->renameTable('tmp_workspace_association', 'workspace_association');
|
||||
\Drupal::state()->delete('workspaces_update_8803.tables');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue