amazon_ses-2.0.x-dev/amazon_ses.install

amazon_ses.install
<?php

/**
 * @file
 * The install file for the amazon_ses module.
 */

/**
 * Implements hook_requirements().
 */
function amazon_ses_requirements($phase) {
  $requirements = [];

  if ($phase == 'runtime') {
    $config = \Drupal::config('amazon_ses.settings');
    $from_address = $config->get('from_address');

    if (!$from_address) {
      $requirements['amazon_ses_from_address'] = [
        'title' => t('Amazon SES'),
        'value' => t('From email address not set.'),
        'severity' => REQUIREMENT_ERROR,
      ];
    }
  }

  return $requirements;
}

/**
 * Enable Amazon Web Services module.
 */
function amazon_ses_update_30001() {
  \Drupal::service('module_installer')->install(['aws'], FALSE);
}

/**
 * Migrate credentials from AWS Secrets Manager.
 */
function amazon_ses_update_30002() {
  /** @var \Drupal\aws\AwsInterface $aws */
  $aws = \Drupal::service('aws');
  $config = $aws->getServiceConfig('sesv2');

  if (!$config) {
    $config_factory = \Drupal::configFactory();
    $profile_storage = \Drupal::entityTypeManager()->getStorage('aws_profile');
    $secrets_manager_config = $config_factory->get('aws_secrets_manager.settings');

    $profile = $profile_storage->load('amazon_ses');

    if (!$profile) {
      $profile = $profile_storage->create([
        'id' => 'amazon_ses',
        'name' => 'Amazon SES',
        'default' => 0,
        'aws_access_key_id' => $secrets_manager_config->get('aws_key'),
        'aws_secret_access_key' => $secrets_manager_config->get('aws_secret'),
        'region' => $secrets_manager_config->get('aws_region'),
      ]);
      $profile->save();
    }

    $aws->setServiceConfig('sesv2', [
      'profile' => $profile->id(),
      'version' => 'latest',
    ]);
  }

  $config_factory->getEditable('amazon_ses.settings')
    ->clear('credentials')
    ->save(TRUE);
}

/**
 * Set throttling multiplier to 1.
 */
function amazon_ses_update_30003() {
  $config_factory = \Drupal::configFactory();
  $config_factory->getEditable('amazon_ses.settings')
    ->set('multiplier', 1)
    ->save(TRUE);
}

/**
 * Add default values for new configuration.
 */
function amazon_ses_update_30004() {
  $config_factory = \Drupal::configFactory();
  $config_factory->getEditable('amazon_ses.settings')
    ->set('from_name', $config_factory->get('system.site')->get('name'))
    ->set('override_from', FALSE)
    ->save(TRUE);
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc