You are here

function paragraphs_update_8004 in Paragraphs 8

Truncate the content_translation_status columns.

File

./paragraphs.install, line 72
Installation hooks for Paragraphs module.

Code

function paragraphs_update_8004() {
  $field_name = 'content_translation_status';
  $tables_to_update = [
    'paragraphs_item_field_data',
    'paragraphs_item_revision_field_data',
  ];
  $database = Drupal::database();
  $entity_definition_update_manager = Drupal::entityDefinitionUpdateManager();

  // Ensure that the data from the content translation status field is deleted
  // so that the field can safely be deleted.
  foreach ($tables_to_update as $table_to_update) {
    if ($database
      ->schema()
      ->fieldExists($table_to_update, $field_name)) {
      $database
        ->update($table_to_update)
        ->fields([
        $field_name => NULL,
      ])
        ->execute();
    }
  }

  // Delete the storage definition if it was defined before.
  $storage_definition = $entity_definition_update_manager
    ->getFieldStorageDefinition($field_name, 'paragraph');
  if ($storage_definition) {
    $entity_definition_update_manager
      ->uninstallFieldStorageDefinition($storage_definition);
  }
}