You are here

function paragraphs_update_8016 in Paragraphs 8

Remove the uid and revision_uid fields.

File

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

Code

function paragraphs_update_8016() {
  $database = \Drupal::database();
  $spec = array(
    'type' => 'varchar',
    'description' => "Revision UID",
    'length' => 20,
    'not null' => FALSE,
  );
  $schema = $database
    ->schema();
  if (!$schema
    ->fieldExists('paragraphs_item_field_data', 'revision_uid')) {
    $schema
      ->addField('paragraphs_item_field_data', 'revision_uid', $spec);
  }
  if (!$schema
    ->fieldExists('paragraphs_item_revision_field_data', 'revision_uid')) {
    $schema
      ->addField('paragraphs_item_revision_field_data', 'revision_uid', $spec);
  }
  $tables_fields = [
    'paragraphs_item_revision' => 'revision_uid',
    'paragraphs_item_field_data' => 'uid',
    'paragraphs_item_revision_field_data' => 'uid',
  ];
  $entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
  foreach ($tables_fields as $table => $field) {
    if ($database
      ->schema()
      ->fieldExists($table, $field)) {
      $database
        ->update($table)
        ->fields([
        $field => NULL,
      ])
        ->execute();
    }
  }
  foreach (array_unique($tables_fields) as $table => $field) {
    $storage_definition = $entity_definition_update_manager
      ->getFieldStorageDefinition($field, 'paragraph');
    if ($storage_definition) {
      $entity_definition_update_manager
        ->uninstallFieldStorageDefinition($storage_definition);
    }
  }
}