You are here

protected function Requirements::checkDatabaseAliasConsistency in MongoDB 8.2

Apply database aliases consistency checks.

Parameters

array $state: The current state of requirements checks.

Return value

array

  • array: The current state of requirements checks.
  • bool: true if the checks added an error, false otherwise
1 call to Requirements::checkDatabaseAliasConsistency()
Requirements::check in modules/mongodb_watchdog/src/Install/Requirements.php
Implements hook_requirements().

File

modules/mongodb_watchdog/src/Install/Requirements.php, line 117

Class

Requirements
Class Requirements implements hook_requirements().

Namespace

Drupal\mongodb_watchdog\Install

Code

protected function checkDatabaseAliasConsistency(array $state) : array {
  $databases = $this->settings['databases'];
  if (!isset($databases[Logger::DB_LOGGER])) {
    $state[Logger::MODULE] += [
      'severity' => REQUIREMENT_ERROR,
      'value' => $this
        ->t('Missing `@alias` database alias in settings.', [
        '@alias' => Logger::DB_LOGGER,
      ]),
    ];
    return [
      $state,
      TRUE,
    ];
  }
  [
    $loggerClient,
    $loggerDb,
  ] = $databases[Logger::DB_LOGGER];
  unset($databases[Logger::DB_LOGGER]);
  $duplicates = [];
  foreach ($databases as $alias => $list) {
    [
      $client,
      $database,
    ] = $list;
    if ($loggerClient == $client && $loggerDb == $database) {
      $duplicates[] = "`{$alias}`";
    }
  }
  if (!empty($duplicates)) {
    $state[Logger::MODULE] += [
      'severity' => REQUIREMENT_ERROR,
      'value' => $this
        ->t('The `@alias` alias points to the same database as @others.', [
        '@alias' => Logger::DB_LOGGER,
        '@others' => implode(', ', $duplicates),
      ]),
      'description' => $this
        ->t('Those databases would also be dropped when uninstalling the watchdog module.'),
    ];
    return [
      $state,
      TRUE,
    ];
  }
  return [
    $state,
    FALSE,
  ];
}