You are here

class CleanerSessionController in Cleaner 8

Class CleanerSessionController.

@package Drupal\cleaner\Controller

Hierarchy

Expanded class hierarchy of CleanerSessionController

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

File

src/Controller/CleanerSessionController.php, line 12

Namespace

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

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

  /**
   * {@inheritdoc}
   */
  public function execute() {
    if (\Drupal::config(CLEANER_SETTINGS)
      ->get(self::$configName)) {
      $count = \Drupal::database()
        ->delete('sessions')
        ->condition('timestamp', self::getExpirationTime(), '<')
        ->execute();
      if ($count) {
        \Drupal::service('cleaner_logger')
          ->log(LogLevel::INFO, 'Old sessions cleared.');
      }
    }
  }

  /**
   * Get the sessions expiration time.
   *
   * @return int
   *   Expiration timestamp.
   */
  private static function getExpirationTime() {
    return (int) (REQUEST_TIME - session_get_cookie_params()['lifetime']);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CleanerSessionController::$configName public static property Configuration name.
CleanerSessionController::execute public function Perform the operation. Overrides CleanerControllersInterface::execute
CleanerSessionController::getExpirationTime private static function Get the sessions expiration time.