You are here

function gathercontent_update_8504 in GatherContent 8.5

Add langcode field to tracking table.

File

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

Code

function gathercontent_update_8504() {
  $spec = _gathercontent_entity_mapping_spec();
  $schema = Database::getConnection()
    ->schema();
  if (!$schema
    ->fieldExists('gathercontent_entity_mapping', 'langcode')) {
    $schema
      ->addField('gathercontent_entity_mapping', 'langcode', $spec['fields']['langcode']);
    $schema
      ->dropPrimaryKey('gathercontent_entity_mapping');
    $schema
      ->addPrimaryKey('gathercontent_entity_mapping', $spec['primary key']);
  }

  /** @var \Drupal\Core\Database\Connection $connection */
  $connection = \Drupal::service('database');

  /** @var \Drupal\Core\Language\LanguageInterface $language */
  $language = \Drupal::service('language.default')
    ->get();
  $langcode = $language
    ->getId();

  // Update the langcode field to contain the default language.
  // Later imports will store the correct language for the given entity.
  $connection
    ->update('gathercontent_entity_mapping')
    ->fields([
    'langcode' => $langcode,
  ])
    ->execute();
}