[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/report/performance/ -> locallib.php (source)

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * This file contains classes for report_performance
  19   *
  20   * @package   report_performance
  21   * @copyright 2013 Rajesh Taneja
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die;
  26  
  27  /**
  28   * Class defining issue result.
  29   *
  30   * @package   report_performance
  31   * @copyright 2013 Rajesh Taneja
  32   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  33   */
  34  class report_performance_issue {
  35      /** @var string issue identifier */
  36      public $issue;
  37      /** @var string issue name */
  38      public $name;
  39      /** @var string shown as status */
  40      public $statusstr;
  41      /** @var string string defines issue status */
  42      public $status;
  43      /** @var string shown as comment */
  44      public $comment;
  45      /** @var string details aboout issue*/
  46      public $details;
  47      /** @var string link pointing to configuration */
  48      public $configlink;
  49  }
  50  
  51  /**
  52   * This contains functions to get list of issues and there results.
  53   *
  54   * @package   report_performance
  55   * @copyright 2013 Rajesh Taneja
  56   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  57   */
  58  class report_performance {
  59      /**
  60       * This is used when issue is ok and there is no impact on performance.
  61       */
  62      const REPORT_PERFORMANCE_OK = 'ok';
  63  
  64      /**
  65       * This is used to notify that issue might impact performance.
  66       */
  67      const REPORT_PERFORMANCE_WARNING = 'warning';
  68  
  69      /**
  70       * This is used to notify if issue is serious and will impact performance.
  71       */
  72      const REPORT_PERFORMANCE_SERIOUS = 'serious';
  73  
  74      /**
  75       * This is used to notify if issue is critical and will significantly impact performance.
  76       */
  77      const REPORT_PERFORMANCE_CRITICAL = 'critical';
  78  
  79      /**
  80       * Return list of performance check function list.
  81       *
  82       * @return array list of performance issues.
  83       */
  84      public function get_issue_list() {
  85          return array(
  86              'report_performance_check_themedesignermode',
  87              'report_performance_check_cachejs',
  88              'report_performance_check_debugmsg',
  89              'report_performance_check_automatic_backup',
  90              'report_performance_check_enablestats'
  91          );
  92      }
  93  
  94      /**
  95       * Returns document link for performance issue
  96       *
  97       * @param string $issue string describing issue
  98       * @param string $name name of issue
  99       * @return string issue link pointing to docs page.
 100       */
 101      public function doc_link($issue, $name) {
 102          global $CFG, $OUTPUT;
 103  
 104          if (empty($CFG->docroot)) {
 105              return $name;
 106          }
 107  
 108          return $OUTPUT->doc_link('report/performance/'.$issue, $name);
 109      }
 110  
 111      /**
 112       * Helper function to add issue details to table.
 113       *
 114       * @param html_table $table table in which issue details should be added
 115       * @param report_performance_issues $issueresult issue result to be added
 116       * @param bool $detail true if issue if displayed in detail.
 117       */
 118      public function add_issue_to_table(&$table, $issueresult, $detailed = false) {
 119          global $OUTPUT;
 120          $statusarr = array(self::REPORT_PERFORMANCE_OK => 'statusok',
 121                          self::REPORT_PERFORMANCE_WARNING => 'statuswarning',
 122                          self::REPORT_PERFORMANCE_SERIOUS => 'statusserious',
 123                          self::REPORT_PERFORMANCE_CRITICAL => 'statuscritical');
 124  
 125          $row = array();
 126          if ($detailed) {
 127              $row[0] = $this->doc_link($issueresult->issue, $issueresult->name);
 128          } else {
 129              $url = new moodle_url('/report/performance/index.php', array('issue' => $issueresult->issue));
 130              $row[0] = html_writer::link($url, $issueresult->name);
 131          }
 132          $row[1] = html_writer::tag('span', $issueresult->statusstr, array('class' => $statusarr[$issueresult->status]));
 133          $row[2] = $issueresult->comment;
 134          if (!empty($issueresult->configlink)) {
 135              $editicon = html_writer::empty_tag('img', array('alt' => $issueresult->issue, 'class' => 'icon',
 136                  'src' => $OUTPUT->pix_url('i/settings')));
 137              $row[3] = $OUTPUT->action_link($issueresult->configlink, $editicon);
 138          } else {
 139              $row[3] = '';
 140          }
 141  
 142          $table->data[] = $row;
 143      }
 144  
 145      /**
 146       * Verifies if theme designer mode is enabled.
 147       *
 148       * @return report_performance_issue result of themedesigner issue.
 149       */
 150      public static function report_performance_check_themedesignermode() {
 151          global $CFG;
 152          $issueresult = new report_performance_issue();
 153          $issueresult->issue = 'report_performance_check_themedesignermode';
 154          $issueresult->name = get_string('themedesignermode', 'admin');
 155  
 156          if (empty($CFG->themedesignermode)) {
 157              $issueresult->statusstr = get_string('disabled', 'report_performance');
 158              $issueresult->status = self::REPORT_PERFORMANCE_OK;
 159              $issueresult->comment = get_string('check_themedesignermode_comment_disable', 'report_performance');
 160          } else {
 161              $issueresult->statusstr = get_string('enabled', 'report_performance');
 162              $issueresult->status = self::REPORT_PERFORMANCE_CRITICAL;
 163              $issueresult->comment = get_string('check_themedesignermode_comment_enable', 'report_performance');
 164          }
 165  
 166          $issueresult->details = get_string('check_themedesignermode_details', 'report_performance');
 167          $issueresult->configlink = new moodle_url('/admin/search.php', array('query' => 'themedesignermode'));
 168          return $issueresult;
 169      }
 170  
 171      /**
 172       * Checks if javascript is cached.
 173       *
 174       * @return report_performance_issue result of cachejs issue.
 175       */
 176      public static function report_performance_check_cachejs() {
 177          global $CFG;
 178          $issueresult = new report_performance_issue();
 179          $issueresult->issue = 'report_performance_check_cachejs';
 180          $issueresult->name = get_string('cachejs', 'admin');
 181  
 182          if (empty($CFG->cachejs)) {
 183              $issueresult->statusstr = get_string('disabled', 'report_performance');
 184              $issueresult->status = self::REPORT_PERFORMANCE_CRITICAL;
 185              $issueresult->comment = get_string('check_cachejs_comment_disable', 'report_performance');
 186          } else {
 187              $issueresult->statusstr = get_string('enabled', 'report_performance');
 188              $issueresult->status = self::REPORT_PERFORMANCE_OK;
 189              $issueresult->comment = get_string('check_cachejs_comment_enable', 'report_performance');
 190          }
 191  
 192          $issueresult->details = get_string('check_cachejs_details', 'report_performance');
 193          $issueresult->configlink = new moodle_url('/admin/search.php', array('query' => 'cachejs'));
 194          return $issueresult;
 195      }
 196  
 197      /**
 198       * Checks debug config.
 199       *
 200       * @return report_performance_issue result of debugmsg issue.
 201       */
 202      public static function report_performance_check_debugmsg() {
 203          global $CFG;
 204          $issueresult = new report_performance_issue();
 205          $issueresult->issue = 'report_performance_check_debugmsg';
 206          $issueresult->name = get_string('debug', 'admin');
 207          $debugchoices = array(DEBUG_NONE  => 'debugnone',
 208                              DEBUG_MINIMAL => 'debugminimal',
 209                              DEBUG_NORMAL => 'debugnormal',
 210                              DEBUG_ALL => 'debugall',
 211                              DEBUG_DEVELOPER => 'debugdeveloper');
 212  
 213          $issueresult->statusstr = get_string($debugchoices[$CFG->debug], 'admin');
 214          if (!$CFG->debugdeveloper) {
 215              $issueresult->status = self::REPORT_PERFORMANCE_OK;
 216              $issueresult->comment = get_string('check_debugmsg_comment_nodeveloper', 'report_performance');
 217          } else {
 218              $issueresult->status = self::REPORT_PERFORMANCE_WARNING;
 219              $issueresult->comment = get_string('check_debugmsg_comment_developer', 'report_performance');
 220          }
 221  
 222          $issueresult->details = get_string('check_debugmsg_details', 'report_performance');
 223  
 224          $issueresult->configlink = new moodle_url('/admin/settings.php', array('section' => 'debugging'));
 225          return $issueresult;
 226      }
 227  
 228      /**
 229       * Checks automatic backup config.
 230       *
 231       * @return report_performance_issue result of automatic backup issue.
 232       */
 233      public static function report_performance_check_automatic_backup() {
 234          global $CFG;
 235          require_once($CFG->dirroot . '/backup/util/helper/backup_cron_helper.class.php');
 236  
 237          $issueresult = new report_performance_issue();
 238          $issueresult->issue = 'report_performance_check_automatic_backup';
 239          $issueresult->name = get_string('check_backup', 'report_performance');
 240  
 241          $automatedbackupsenabled = get_config('backup', 'backup_auto_active');
 242          if ($automatedbackupsenabled == backup_cron_automated_helper::AUTO_BACKUP_ENABLED) {
 243              $issueresult->statusstr = get_string('autoactiveenabled', 'backup');
 244              $issueresult->status = self::REPORT_PERFORMANCE_WARNING;
 245              $issueresult->comment = get_string('check_backup_comment_enable', 'report_performance');
 246          } else {
 247              if ($automatedbackupsenabled == backup_cron_automated_helper::AUTO_BACKUP_DISABLED) {
 248                  $issueresult->statusstr = get_string('autoactivedisabled', 'backup');
 249              } else {
 250                  $issueresult->statusstr = get_string('autoactivemanual', 'backup');
 251              }
 252              $issueresult->status = self::REPORT_PERFORMANCE_OK;
 253              $issueresult->comment = get_string('check_backup_comment_disable', 'report_performance');
 254          }
 255  
 256          $issueresult->details = get_string('check_backup_details', 'report_performance');
 257          $issueresult->configlink = new moodle_url('/admin/search.php', array('query' => 'backup_auto_active'));
 258          return $issueresult;
 259      }
 260  
 261      /**
 262       * Checks if stats are enabled.
 263       */
 264      public static function report_performance_check_enablestats() {
 265          global $CFG;
 266          $issueresult = new report_performance_issue();
 267          $issueresult->issue = 'report_performance_check_enablestats';
 268          $issueresult->name = get_string('enablestats', 'admin');
 269  
 270          if (!empty($CFG->enablestats)) {
 271              $issueresult->statusstr = get_string('enabled', 'report_performance');
 272              $issueresult->status = self::REPORT_PERFORMANCE_WARNING;
 273              $issueresult->comment = get_string('check_enablestats_comment_enable', 'report_performance');
 274          } else {
 275              $issueresult->statusstr = get_string('disabled', 'report_performance');
 276              $issueresult->status = self::REPORT_PERFORMANCE_OK;
 277              $issueresult->comment = get_string('check_enablestats_comment_disable', 'report_performance');
 278          }
 279  
 280          $issueresult->details = get_string('check_enablestats_details', 'report_performance');
 281          $issueresult->configlink = new moodle_url('/admin/search.php', array('query' => 'enablestats'));
 282          return $issueresult;
 283      }
 284  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1