Merge branch 'MDL-67822-schema-check' of https://github.com/brendanheywood/moodle

This commit is contained in:
Andrew Nicols 2021-06-10 11:03:52 +08:00
commit 8c8eac9df5
3 changed files with 89 additions and 0 deletions

View File

@ -69,6 +69,7 @@ class manager {
new performance\debugging(),
new performance\backups(),
new performance\stats(),
new performance\dbschema(),
];
// Any plugin can add status checks to this report by implementing a callback

View File

@ -0,0 +1,85 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* DB schema performance check
*
* @package core
* @category check
* @copyright 2021 Brendan Heywood <brendan@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\check\performance;
defined('MOODLE_INTERNAL') || die();
use core\check\check;
use core\check\result;
/**
* DB schema performance check
*
* @copyright 2021 Brendan Heywood <brendan@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class dbschema extends check {
/**
* Get the short check name
*
* @return string
*/
public function get_name(): string {
return get_string('check_dbschema_name', 'report_performance');
}
/**
* A link to a place to action this
*
* @return action_link|null
*/
public function get_action_link(): ?\action_link {
return new \action_link(
new \moodle_url(\get_docs_url('Verify_Database_Schema')),
get_string('moodledocs'));
}
/**
* Return result
* @return result
*/
public function get_result(): result {
global $DB;
$dbmanager = $DB->get_manager();
$schema = $dbmanager->get_install_xml_schema();
if (!$errors = $dbmanager->check_database_schema($schema)) {
return new result(result::OK, get_string('check_dbschema_ok', 'report_performance'), '');
}
$details = '';
foreach ($errors as $tablename => $items) {
$details .= \html_writer::tag('h4', $tablename);
foreach ($items as $item) {
$details .= \html_writer::tag('pre', $item);
}
}
return new result(result::ERROR, get_string('check_dbschema_errors', 'report_performance'), $details);
}
}

View File

@ -29,6 +29,9 @@ $string['check_backup_details'] = 'Enabling automated backup will automatically
$string['check_cachejs_comment_disable'] = 'If enabled, page loading performance is improved.';
$string['check_cachejs_comment_enable'] = 'If disabled, page might load slow.';
$string['check_cachejs_details'] = 'Javascript caching and compression greatly improves page loading performance. It is strongly recommended for production sites.';
$string['check_dbschema_name'] = 'Database schema check';
$string['check_dbschema_ok'] = 'Database schema is correct.';
$string['check_dbschema_errors'] = 'Database schema is not aligned.';
$string['check_debugmsg_comment_nodeveloper'] = 'If set to DEVELOPER, performance may be affected slightly.';
$string['check_debugmsg_comment_developer'] = 'If set to a value other than DEVELOPER, performance may be improved slightly.';
$string['check_debugmsg_details'] = 'There is rarely any advantage in going to Developer level, unless requested by a developer.<p>Once you have obtained the error message, and copied and pasted it somewhere, it is HIGHLY RECOMMENDED to turn Debug back to NONE. Debug messages can give clues to a hacker as to the setup of your site and may affect performance.</p>';