You are here

class SiteAuditCheckStatusSystem in Site Audit 7

Same name and namespace in other branches
  1. 8.2 Check/Status/System.php \SiteAuditCheckStatusSystem

Class SiteAuditCheckStatusSystem.

Hierarchy

Expanded class hierarchy of SiteAuditCheckStatusSystem

File

Check/Status/System.php, line 10
Contains \SiteAudit\Check\Status\System.

View source
class SiteAuditCheckStatusSystem extends SiteAuditCheckAbstract {

  /**
   * Implements \SiteAudit\Check\Abstract\getLabel().
   */
  public function getLabel() {
    return dt('System Status');
  }

  /**
   * Implements \SiteAudit\Check\Abstract\getDescription().
   */
  public function getDescription() {
    return dt("Drupal's status report.");
  }

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

  /**
   * Implements \SiteAudit\Check\Abstract\getResultInfo().
   */
  public function getResultInfo() {
  }

  /**
   * Implements \SiteAudit\Check\Abstract\getResultPass().
   */
  public function getResultPass() {
    $items = array();
    foreach ($this->registry['requirements'] as $requirement) {

      // Default to REQUIREMENT_INFO if no severity is set.
      if (!isset($requirement['severity'])) {
        $requirement['severity'] = REQUIREMENT_INFO;
      }

      // Reduce verbosity.
      if (!drush_get_option('detail') && $requirement['severity'] < REQUIREMENT_WARNING) {
        continue;
      }

      // Title: severity - value.
      if ($requirement['severity'] == REQUIREMENT_INFO) {
        $class = 'info';
        $severity = 'Info';
      }
      elseif ($requirement['severity'] == REQUIREMENT_OK) {
        $severity = 'Ok';
        $class = 'success';
      }
      elseif ($requirement['severity'] == REQUIREMENT_WARNING) {
        $severity = 'Warning';
        $class = 'warning';
      }
      elseif ($requirement['severity'] == REQUIREMENT_ERROR) {
        $severity = 'Error';
        $class = 'error';
      }
      if (drush_get_option('html') || drush_get_option('json')) {
        $value = isset($requirement['value']) && $requirement['value'] ? $requirement['value'] : '&nbsp;';
        $uri = drush_get_context('DRUSH_URI');

        // Unknown URI - strip all links, but leave formatting.
        if ($uri == 'http://default') {
          $value = strip_tags($value, '<em><i><b><strong><span>');
        }
        else {
          $value = preg_replace("#(<\\s*a\\s+[^>]*href\\s*=\\s*[\"'])(?!http)([^\"'>]+)([\"'>]+)#", '$1' . $uri . '$2$3', $value);
        }
        $item = array(
          'title' => $requirement['title'],
          'severity' => $severity,
          'value' => $value,
          'class' => $class,
        );
        if (drush_get_option('json')) {
          foreach ($item as $key => $value) {
            $item[$key] = strip_tags($value);
          }
        }
      }
      else {
        $item = strip_tags($requirement['title']) . ': ' . $severity;
        if (isset($requirement['value']) && $requirement['value']) {
          $item .= ' - ' . dt('@value', array(
            '@value' => strip_tags($requirement['value']),
          ));
        }
      }
      $items[] = $item;
    }
    if (drush_get_option('html')) {
      $ret_val = '<table class="table table-condensed">';
      $ret_val .= '<thead><tr><th>' . dt('Title') . '</th><th>' . dt('Severity') . '</th><th>' . dt('Value') . '</th></thead>';
      $ret_val .= '<tbody>';
      foreach ($items as $item) {
        $ret_val .= '<tr class="' . $item['class'] . '">';
        $ret_val .= '<td>' . $item['title'] . '</td>';
        $ret_val .= '<td>' . $item['severity'] . '</td>';
        $ret_val .= '<td>' . $item['value'] . '</td>';
        $ret_val .= '</tr>';
      }
      $ret_val .= '</tbody>';
      $ret_val .= '</table>';
    }
    elseif (drush_get_option('json')) {
      foreach ($items as $item) {
        unset($item['class']);
        $ret_val[] = $item;
      }
    }
    else {
      $separator = PHP_EOL;
      $separator .= str_repeat(' ', 4);
      $ret_val = implode($separator, $items);
    }
    return $ret_val;
  }

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

  /**
   * Implements \SiteAudit\Check\Abstract\getAction().
   */
  public function getAction() {
  }

  /**
   * Implements \SiteAudit\Check\Abstract\calculateScore().
   */
  public function calculateScore() {

    // See system/system.admin.inc function system_status().
    // Load .install files.
    include_once DRUPAL_ROOT . '/includes/install.inc';
    drupal_load_updates();

    // Check run-time requirements and status information.
    $this->registry['requirements'] = module_invoke_all('requirements', 'runtime');
    usort($this->registry['requirements'], '_system_sort_requirements');
    $this->percentOverride = 0;
    $requirements_with_severity = array();
    foreach ($this->registry['requirements'] as $key => $value) {
      if (isset($value['severity'])) {
        $requirements_with_severity[$key] = $value;
      }
    }
    $score_each = 100 / count($requirements_with_severity);
    $worst_severity = REQUIREMENT_INFO;
    foreach ($this->registry['requirements'] as $requirement) {
      if (isset($requirement['severity'])) {
        if ($requirement['severity'] > $worst_severity) {
          $worst_severity = $requirement['severity'];
        }
        if ($requirement['severity'] == REQUIREMENT_WARNING) {
          $this->percentOverride += $score_each / 2;
        }
        elseif ($requirement['severity'] != REQUIREMENT_ERROR) {
          $this->percentOverride += $score_each;
        }
      }
    }
    $this->percentOverride = round($this->percentOverride);
    if ($this->percentOverride > 80) {
      return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_PASS;
    }
    elseif ($this->percentOverride > 60) {
      return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_WARN;
    }
    return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_FAIL;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SiteAuditCheckAbstract::$abort protected property Indicate that no other checks should be run after this check.
SiteAuditCheckAbstract::$optOut protected property User has opted out of this check in configuration.
SiteAuditCheckAbstract::$percentOverride protected property If set, will override the Report's percentage.
SiteAuditCheckAbstract::$registry protected property Use for passing data between checks within a report.
SiteAuditCheckAbstract::$score protected property Quantifiable number associated with result on a scale of 0 to 2.
SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_FAIL constant
SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_INFO constant
SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_PASS constant
SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_WARN constant
SiteAuditCheckAbstract::getPercentOverride public function Get the report percent override, if any.
SiteAuditCheckAbstract::getRegistry public function Get the check registry.
SiteAuditCheckAbstract::getRelativePath public function Gives path relative to DRUPAL_ROOT of the path is inside Drupal.
SiteAuditCheckAbstract::getResult public function Determine the result message based on the score.
SiteAuditCheckAbstract::getScore public function Get a quantifiable number representing a check result; lazy initialization.
SiteAuditCheckAbstract::getScoreCssClass public function Get the CSS class associated with a score.
SiteAuditCheckAbstract::getScoreDrushLevel public function Get the Drush message level associated with a score.
SiteAuditCheckAbstract::getScoreLabel public function Get a human readable label for a score.
SiteAuditCheckAbstract::renderAction public function Display action items for a user to perform.
SiteAuditCheckAbstract::shouldAbort public function Determine whether the check failed so badly that the report must stop.
SiteAuditCheckAbstract::__construct public function Constructor.
SiteAuditCheckStatusSystem::calculateScore public function Implements \SiteAudit\Check\Abstract\calculateScore(). Overrides SiteAuditCheckAbstract::calculateScore
SiteAuditCheckStatusSystem::getAction public function Implements \SiteAudit\Check\Abstract\getAction(). Overrides SiteAuditCheckAbstract::getAction
SiteAuditCheckStatusSystem::getDescription public function Implements \SiteAudit\Check\Abstract\getDescription(). Overrides SiteAuditCheckAbstract::getDescription
SiteAuditCheckStatusSystem::getLabel public function Implements \SiteAudit\Check\Abstract\getLabel(). Overrides SiteAuditCheckAbstract::getLabel
SiteAuditCheckStatusSystem::getResultFail public function Implements \SiteAudit\Check\Abstract\getResultFail(). Overrides SiteAuditCheckAbstract::getResultFail
SiteAuditCheckStatusSystem::getResultInfo public function Implements \SiteAudit\Check\Abstract\getResultInfo(). Overrides SiteAuditCheckAbstract::getResultInfo
SiteAuditCheckStatusSystem::getResultPass public function Implements \SiteAudit\Check\Abstract\getResultPass(). Overrides SiteAuditCheckAbstract::getResultPass
SiteAuditCheckStatusSystem::getResultWarn public function Implements \SiteAudit\Check\Abstract\getResultWarn(). Overrides SiteAuditCheckAbstract::getResultWarn