You are here

class CleanerWatchdogController in Cleaner 8

Class CleanerWatchdogController.

@package Drupal\cleaner\Controller

Hierarchy

Expanded class hierarchy of CleanerWatchdogController

1 string reference to 'CleanerWatchdogController'
cleaner.services.yml in ./cleaner.services.yml
cleaner.services.yml
1 service uses CleanerWatchdogController
cleaner_watchdog in ./cleaner.services.yml
Drupal\cleaner\Controller\CleanerWatchdogController

File

src/Controller/CleanerWatchdogController.php, line 12

Namespace

Drupal\cleaner\Controller
View source
class CleanerWatchdogController implements CleanerControllersInterface {

  /**
   * Configuration name.
   *
   * @var string
   */
  public static $configName = 'cleaner_empty_watchdog';

  /**
   * Watchdog log level.
   *
   * @type string
   */
  protected static $logLevel;

  /**
   * Watchdog log message.
   *
   * @type string
   */
  protected static $logMessage;

  /**
   * {@inheritdoc}
   */
  public function execute() {
    if (\Drupal::config(CLEANER_SETTINGS)
      ->get(self::$configName)) {
      if (self::cleanWatchdog()) {
        static::$logLevel = LogLevel::INFO;
        static::$logMessage = 'Watchdog logs has been successfully cleared.';
      }
      else {
        static::$logLevel = LogLevel::ERROR;
        static::$logMessage = 'Something going wrong - watchdog logs can\'t be cleared.';
      }
      \Drupal::service('cleaner_logger')
        ->log(static::$logLevel, static::$logMessage);
    }
  }

  /**
   * Perform clearing database table - "watchdog".
   *
   * @return bool
   *   TRUE on success, FALSE otherwise.
   */
  private static function cleanWatchdog() {
    if (!\Drupal::database()
      ->schema()
      ->tableExists('watchdog')) {
      return FALSE;
    }
    return (bool) \Drupal::database()
      ->query('TRUNCATE {watchdog}')
      ->execute();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CleanerWatchdogController::$configName public static property Configuration name.
CleanerWatchdogController::$logLevel protected static property Watchdog log level.
CleanerWatchdogController::$logMessage protected static property Watchdog log message.
CleanerWatchdogController::cleanWatchdog private static function Perform clearing database table - "watchdog".
CleanerWatchdogController::execute public function Perform the operation. Overrides CleanerControllersInterface::execute