You are here

public function NewRelicConfigSubscriber::onImport in New Relic 8

Same name and namespace in other branches
  1. 2.x src/EventSubscriber/NewRelicConfigSubscriber.php \Drupal\new_relic_rpm\EventSubscriber\NewRelicConfigSubscriber::onImport()
  2. 2.0.x src/EventSubscriber/NewRelicConfigSubscriber.php \Drupal\new_relic_rpm\EventSubscriber\NewRelicConfigSubscriber::onImport()

Attempts to create a deployment on New Relic when a config import happens.

Parameters

\Drupal\Core\Config\ConfigImporterEvent $event: The current config event that we are responding to.

File

src/EventSubscriber/NewRelicConfigSubscriber.php, line 71

Class

NewRelicConfigSubscriber
Config event listener to mark deployments when a user imports configuration.

Namespace

Drupal\new_relic_rpm\EventSubscriber

Code

public function onImport(ConfigImporterEvent $event) {
  if (!$this->config
    ->get('config_import')) {
    return;
  }
  $changes = $event
    ->getChangelist();
  $name = $this->currentUser
    ->getAccountName();
  $description = $this
    ->t('A configuration import was run on the site.');
  $changelog = '';
  if (!empty($changes['create'])) {
    $changelog .= 'Configurations created:
';
    foreach ($changes['create'] as $config_key) {
      $changelog .= $config_key . '
';
    }
  }
  if (!empty($changes['update'])) {
    $changelog .= 'Configurations updated:
';
    foreach ($changes['update'] as $config_key) {
      $changelog .= $config_key . '
';
    }
  }
  if (!empty($changes['delete'])) {
    $changelog .= 'Configurations deleted:
';
    foreach ($changes['delete'] as $config_key) {
      $changelog .= $config_key . '
';
    }
  }
  if (!empty($changes['rename'])) {
    $changelog .= 'Configurations renamed:
';
    foreach ($changes['rename'] as $config_key) {
      $changelog .= $config_key . '
';
    }
  }

  /** @var \Drupal\new_relic_rpm\Client\NewRelicApiClient $client */
  $client = \Drupal::service('new_relic_rpm.client');
  $client
    ->createDeployment('config_import', $description, $name, $changelog);
}