You are here

function simplenews_update_8205 in Simplenews 8.2

Same name and namespace in other branches
  1. 3.x simplenews.install \simplenews_update_8205()

Add simplenews_issue error_count property.

File

./simplenews.install, line 229
Install, update and uninstall functions for the simplenews module.

Code

function simplenews_update_8205() {
  $manager = \Drupal::entityDefinitionUpdateManager();
  $storage_definition = $manager
    ->getFieldStorageDefinition('simplenews_issue', 'node');
  $table_mapping = \Drupal::service('entity_type.manager')
    ->getStorage('node')
    ->getTableMapping();
  $table_names[] = $table_mapping
    ->getDedicatedDataTableName($storage_definition);
  $table_names[] = $table_mapping
    ->getDedicatedRevisionTableName($storage_definition);
  $column_name = $table_mapping
    ->getFieldColumnName($storage_definition, 'error_count');
  $schema = Database::getConnection()
    ->schema();
  $new_property = [
    'description' => 'Counter of already sent newsletters.',
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => FALSE,
  ];
  foreach ($table_names as $table_name) {
    if (!$schema
      ->fieldExists($table_name, $column_name)) {
      $schema
        ->addField($table_name, $column_name, $new_property);
    }
  }
  $manager
    ->updateFieldStorageDefinition($storage_definition);
}