You are here

public function DebugCommands::debugDisable in Purge 8.3

Disable debugging for all of Purge's log channels.

@usage drush p:debug-disable Disables the log channels.

@command p:debug-dis @aliases pddis,p-debug-dis

Parameters

array $options: Associative array of options whose values come from Drush.

File

modules/purge_drush/src/Commands/DebugCommands.php, line 45

Class

DebugCommands
Commands to help debugging caching and Purge.

Namespace

Drupal\purge_drush\Commands

Code

public function debugDisable(array $options = [
  'format' => 'string',
]) {
  $enabled_channels = function () {
    $ids = [];
    foreach ($this->purgeLogger
      ->getChannels() as $channel) {
      if (in_array(RfcLogLevel::DEBUG, $channel['grants'])) {
        $ids[] = $channel['id'];
      }
    }
    return $ids;
  };

  // Abort when debugging is already disabled everywhere.
  if (empty($enabled_channels())) {
    throw new \Exception(dt("Debugging already disabled for all channels."));
  }

  // Prepend some output when we're operating interactively.
  if ($options['format'] == 'string') {
    $this
      ->io()
      ->writeln(dt("Disabled debug logging for the following log channels:"));
    $this
      ->io()
      ->listing($enabled_channels());
  }

  // Disable debugging for all channels.
  foreach ($this->purgeLogger
    ->getChannels() as $channel) {
    if (in_array(RfcLogLevel::DEBUG, $channel['grants'])) {
      $key = array_search(RfcLogLevel::DEBUG, $channel['grants']);
      unset($channel['grants'][$key]);
      $this->purgeLogger
        ->setChannel($channel['id'], $channel['grants']);
    }
  }
}