You are here

PageExpire.php in Site Audit 8.2

Same filename and directory in other branches
  1. 7 Check/Cache/PageExpire.php

Contains \SiteAudit\Check\Cache\PageExpire.

File

Check/Cache/PageExpire.php
View source
<?php

/**
 * @file
 * Contains \SiteAudit\Check\Cache\PageExpire.
 */

/**
 * Class SiteAuditCheckCachePageExpire.
 */
class SiteAuditCheckCachePageExpire extends SiteAuditCheckAbstract {

  /**
   * Implements \SiteAudit\Check\Abstract\getLabel().
   */
  public function getLabel() {
    return dt('Expiration of cached pages');
  }

  /**
   * Implements \SiteAudit\Check\Abstract\getDescription().
   */
  public function getDescription() {
    return dt('Verify that Drupal\'s cached pages last for at least 15 minutes.');
  }

  /**
   * Implements \SiteAudit\Check\Abstract\getResultFail().
   */
  public function getResultFail() {
    return dt('Expiration of cached pages not set!');
  }

  /**
   * Implements \SiteAudit\Check\Abstract\getResultInfo().
   */
  public function getResultInfo() {
    return $this
      ->getResultFail();
  }

  /**
   * Implements \SiteAudit\Check\Abstract\getResultPass().
   */
  public function getResultPass() {
    global $conf;
    return dt('Expiration of cached pages is set to @minutes min.', array(
      '@minutes' => round(\Drupal::config('system.performance')
        ->get('cache.page.max_age') / 60),
    ));
  }

  /**
   * Implements \SiteAudit\Check\Abstract\getResultWarn().
   */
  public function getResultWarn() {
    global $conf;
    return dt('Expiration of cached pages only set to @minutes min.', array(
      '@minutes' => round(\Drupal::config('system.performance')
        ->get('cache.page.max_age') / 60),
    ));
  }

  /**
   * Implements \SiteAudit\Check\Abstract\getAction().
   */
  public function getAction() {
    if (!in_array($this->score, array(
      SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_PASS,
    ))) {
      return dt('Go to /admin/config/development/performance and set "Expiration of cached pages" to 15 min or above.');
    }
  }

  /**
   * Implements \SiteAudit\Check\Abstract\calculateScore().
   */
  public function calculateScore() {
    $config = \Drupal::config('system.performance')
      ->get('cache.page.max_age');
    if ($config == 0) {
      if (site_audit_env_is_dev()) {
        return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_INFO;
      }
      return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_FAIL;
    }
    elseif ($config >= 900) {
      return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_PASS;
    }
    return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_WARN;
  }

}

Classes

Namesort descending Description
SiteAuditCheckCachePageExpire Class SiteAuditCheckCachePageExpire.