diff --git a/core/modules/shortcut/shortcut.install b/core/modules/shortcut/shortcut.install index c5ddf81..68d834c 100644 --- a/core/modules/shortcut/shortcut.install +++ b/core/modules/shortcut/shortcut.install @@ -73,8 +73,8 @@ function shortcut_uninstall() { */ function shortcut_update_8001() { $entity_type = \Drupal::entityTypeManager()->getStorage('shortcut')->getEntityType(); + \Drupal::service('system.entity_schema_updater')->updateEntityType($entity_type); \Drupal::service('system.entity_schema_updater')->createTables($entity_type); \Drupal::service('system.entity_schema_updater')->installFields($entity_type); - \Drupal::service('system.entity_schema_updater')->updateEntityType($entity_type); \Drupal::service('system.entity_schema_updater')->copyData($entity_type); } diff --git a/core/modules/shortcut/src/Entity/Shortcut.php b/core/modules/shortcut/src/Entity/Shortcut.php index 704e160..9f60fe0 100644 --- a/core/modules/shortcut/src/Entity/Shortcut.php +++ b/core/modules/shortcut/src/Entity/Shortcut.php @@ -30,6 +30,8 @@ * }, * base_table = "shortcut", * data_table = "shortcut_field_data", + * revision_table = "shortcut_revision", + * revision_data_table = "shortcut_field_revision", * translatable = TRUE, * entity_keys = { * "id" = "id", diff --git a/core/modules/system/src/EntitySchemaUpdater.php b/core/modules/system/src/EntitySchemaUpdater.php index 524c6a3..292edac 100644 --- a/core/modules/system/src/EntitySchemaUpdater.php +++ b/core/modules/system/src/EntitySchemaUpdater.php @@ -31,6 +31,7 @@ public function installFields(EntityTypeInterface $entity_type) { ->setSetting('unsigned', TRUE); \Drupal::entityDefinitionUpdateManager() ->installFieldStorageDefinition($entity_type->getKey('revision'), $entity_type->id(), $entity_type->id(), $revision_id); + } $revision_created = BaseFieldDefinition::create('created') @@ -68,6 +69,11 @@ public function installFields(EntityTypeInterface $entity_type) { foreach ($field_definitions as $field_definition) { \Drupal::entityDefinitionUpdateManager()->updateFieldStorageDefinition($field_definition); } + + $revision_data_table = $entity_type->getRevisionDataTable(); + $schema = \Drupal::database()->schema(); + $schema->dropPrimaryKey($revision_data_table); + $schema->addPrimaryKey($revision_data_table, [$entity_type->getKey('revision'), $entity_type->getKey('langcode')]); } public function updateEntityType(EntityTypeInterface $entity_type) { @@ -77,14 +83,9 @@ public function updateEntityType(EntityTypeInterface $entity_type) { $keys = $last_entity_type->getKeys(); $keys['revision'] = 'revision_id'; $last_entity_type->set('entity_keys', $keys); + $last_entity_type->set('revision_table', $entity_type->getRevisionTable()); + $last_entity_type->set('revision_data_table', $entity_type->getRevisionDataTable()); $last_installed_schema_repository->setLastInstalledDefinition($last_entity_type); - - $storage = \Drupal::entityTypeManager()->getStorage($entity_type->id()); - $result = \Drupal::entityQuery($entity_type->id())->execute(); - $entities = $storage->loadMultiple(); - foreach ($entities as $entity) { - $entity->save(); - } } public function copyData(EntityTypeInterface $entity_type) { @@ -120,7 +121,7 @@ public function copyData(EntityTypeInterface $entity_type) { } $query = \Drupal::database()->select($table_name)->fields($table_name, [$id])->condition($id, $record[$id]); $exists = $query->execute()->fetchAll(); - if (isset($exists) && ($exists[0]->{$id} == $record[$id])) { + if (isset($exists) && isset($exists[0]) && ($exists[0]->{$id} == $record[$id])) { \Drupal::database() ->update($table_name) ->fields($values)