You are here

function gathercontent_update_8501 in GatherContent 8.5

Uninstall operation entity.

Convert previous version mapping type to the new one.

File

./gathercontent.install, line 199
Install and uninstall script for GatherContent module.

Code

function gathercontent_update_8501() {
  try {
    $entity_update_manager = \Drupal::entityDefinitionUpdateManager();
    $entity_type = $entity_update_manager
      ->getEntityType('gathercontent_operation');
    $entity_update_manager
      ->uninstallEntityType($entity_type);
    $entity_type = $entity_update_manager
      ->getEntityType('gathercontent_operation_item');
    $entity_update_manager
      ->uninstallEntityType($entity_type);
  } catch (\Exception $e) {

    // Do nothing, to prevent failure. The entities are removed, but Drupal
    // throws an exception, because the entities are no longer in the code.
  }

  // Convert mappings.
  $mapping_ids = \Drupal::entityQuery('gathercontent_mapping')
    ->execute();
  if (empty($mapping_ids)) {
    return;
  }
  $migrationDefinitionCreator = \Drupal::service('gathercontent.migration_creator');
  foreach ($mapping_ids as $mapping_id) {
    $mapping = Mapping::load($mapping_id);
    $mapping
      ->setMappedEntityType('node');
    $mapping
      ->setUpdatedDrupal(time());
    $mapping
      ->save();
    $mapping_data = unserialize($mapping
      ->getData());
    if (empty($mapping_data)) {
      continue;
    }
    $migrationDefinitionCreator
      ->setMapping($mapping)
      ->setMappingData($mapping_data)
      ->createMigrationDefinition();
  }
}