MDL-10168 improvements to display of results from environment checks
This commit is contained in:
+76
-44
@@ -55,8 +55,9 @@
|
||||
* The function looks for the best version to compare and
|
||||
* everything. This is the only function that should be called
|
||||
* ever from the rest of Moodle.
|
||||
* @param string version version to check.
|
||||
* @param string version version to check.
|
||||
* @param array results array of results checked.
|
||||
* @param boolean true/false, whether to print the table or just return results array
|
||||
* @return boolean true/false, depending of results
|
||||
*/
|
||||
function check_moodle_environment($version, &$environment_results, $print_table=true) {
|
||||
@@ -111,7 +112,7 @@ function check_moodle_environment($version, &$environment_results, $print_table=
|
||||
return ($result && $status);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* This function will print one beautiful table with all the environmental
|
||||
* configuration and how it suits Moodle needs.
|
||||
* @param boolean final result of the check (true/false)
|
||||
@@ -131,16 +132,28 @@ function print_moodle_environment($result, $environment_results) {
|
||||
$strrestricted = get_string('restricted');
|
||||
$strenvironmenterrortodo = get_string('environmenterrortodo', 'admin');
|
||||
|
||||
/// Here we'll store all the feedback found
|
||||
$feedbacktext = '';
|
||||
|
||||
/// Table header
|
||||
$table->head = array ($strname, $strinfo, $strreport, $strstatus);
|
||||
$table->align = array ('center', 'center', 'left', 'center');
|
||||
$table->wrap = array ('nowrap', '', '', 'nowrap');
|
||||
$table->size = array ('10', 10, '100%', '10');
|
||||
$table->width = '90%';
|
||||
$table->class = 'environmenttable generaltable';
|
||||
/// Table headers
|
||||
$servertable = new stdClass;//table for server checks
|
||||
$servertable->head = array ($strname, $strinfo, $strreport, $strstatus);
|
||||
$servertable->align = array ('center', 'center', 'left', 'center');
|
||||
$servertable->wrap = array ('nowrap', '', '', 'nowrap');
|
||||
$servertable->size = array ('10', 10, '100%', '10');
|
||||
$servertable->width = '90%';
|
||||
$servertable->class = 'environmenttable generaltable';
|
||||
|
||||
$serverdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
|
||||
|
||||
$othertable = new stdClass;//table for custom checks
|
||||
$othertable->head = array ($strinfo, $strreport, $strstatus);
|
||||
$othertable->align = array ('center', 'left', 'center');
|
||||
$othertable->wrap = array ('', '', 'nowrap');
|
||||
$othertable->size = array (10, '100%', '10');
|
||||
$othertable->width = '90%';
|
||||
$othertable->class = 'environmenttable generaltable';
|
||||
|
||||
$otherdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
|
||||
|
||||
|
||||
/// Iterate over each environment_result
|
||||
$continue = true;
|
||||
@@ -195,48 +208,67 @@ function print_moodle_environment($result, $environment_results) {
|
||||
$status = $strcheck;
|
||||
$warningline = true;
|
||||
} else { //Handle error result (error)
|
||||
$status = $strcheck;
|
||||
$status = $strcheck;
|
||||
$errorline = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Build the text
|
||||
$report = get_string($stringtouse, 'admin', $rec);
|
||||
$linkparts = array();
|
||||
$linkparts[] = 'admin/environment';
|
||||
$linkparts[] = $type;
|
||||
if (!empty($info)){
|
||||
$linkparts[] = $info;
|
||||
}
|
||||
$report = doc_link(join($linkparts, '/'), get_string($stringtouse, 'admin', $rec));
|
||||
|
||||
/// Format error or warning line
|
||||
if ($errorline || $warningline) {
|
||||
$styletoapply = $errorline? 'error':'warn';
|
||||
$type = '<span class="'.$styletoapply.'">'.$type.'</span>';
|
||||
$info = '<span class="'.$styletoapply.'">'.$info.'</span>';
|
||||
$report = '<span class="'.$styletoapply.'">'.$report.'</span>';
|
||||
$status = '<span class="'.$styletoapply.'">'.$status.'</span>';
|
||||
$messagetype = $errorline? 'error':'warn';
|
||||
} else {
|
||||
$messagetype = 'ok';
|
||||
}
|
||||
/// Add the row to the table
|
||||
$table->data[] = array ($type, $info, $report, $status);
|
||||
///Process the feedback if necessary
|
||||
$status = '<span class="'.$messagetype.'">'.$status.'</span>';
|
||||
/// Here we'll store all the feedback found
|
||||
$feedbacktext = '';
|
||||
///Process the feedback if necessary
|
||||
if ($feedbackstr = $environment_result->getFeedbackStr()) {
|
||||
$feedbacktext .= '<li class="environmenttable">'.get_string($feedbackstr, 'admin').'</li>';
|
||||
$feedbacktext .= '<p class="'.$messagetype.'">'.get_string($feedbackstr, 'admin').'</p>';
|
||||
}
|
||||
///Process the bypass if necessary
|
||||
if ($bypassstr = $environment_result->getBypassStr()) {
|
||||
$feedbacktext .= '<li class="environmenttable">'.get_string($bypassstr, 'admin').'</li>';
|
||||
$feedbacktext .= '<p class="warn">'.get_string($bypassstr, 'admin').'</p>';
|
||||
}
|
||||
///Process the restrict if necessary
|
||||
if ($restrictstr = $environment_result->getRestrictStr()) {
|
||||
$feedbacktext .= '<li class="environmenttable">'.get_string($restrictstr, 'admin').'</li>';
|
||||
$feedbacktext .= '<p class="error">'.get_string($restrictstr, 'admin').'</p>';
|
||||
}
|
||||
if ($feedbacktext) {
|
||||
$report = $report .$feedbacktext;
|
||||
}
|
||||
/// Add the row to the table
|
||||
|
||||
if ($environment_result->getPart() == 'custom_check'){
|
||||
$otherdata[$messagetype][] = array ($info, $report, $status);
|
||||
|
||||
} else {
|
||||
$serverdata[$messagetype][] = array ($type, $info, $report, $status);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//put errors first in
|
||||
$servertable->data = array_merge($serverdata['error'], $serverdata['warn'], $serverdata['ok']);
|
||||
$othertable->data = array_merge($otherdata['error'], $otherdata['warn'], $otherdata['ok']);
|
||||
|
||||
/// Print table
|
||||
print_table($table);
|
||||
|
||||
/// And feedback accumulated text
|
||||
if ($feedbacktext) {
|
||||
print_simple_box('<ul>'.$feedbacktext.'</ul>', 'center', '90%', '', '', 'environmentbox generalbox');
|
||||
print_heading(get_string('serverchecks', 'admin'));
|
||||
print_table($servertable);
|
||||
if (count($othertable->data)){
|
||||
print_heading(get_string('customcheck', 'admin'));
|
||||
print_table($othertable);
|
||||
}
|
||||
|
||||
/// Finally, if any error has happened, print the summary box
|
||||
if (!$result) {
|
||||
print_simple_box($strenvironmenterrortodo, 'center', '', '', '', 'environmentbox errorbox');
|
||||
@@ -267,7 +299,7 @@ function normalize_version($version) {
|
||||
* @return mixed the xmlized structure or false on error
|
||||
*/
|
||||
function load_environment_xml() {
|
||||
|
||||
|
||||
global $CFG;
|
||||
|
||||
static $data; //Only load and xmlize once by request
|
||||
@@ -279,7 +311,7 @@ function load_environment_xml() {
|
||||
/// First of all, take a look inside $CFG->dataroot/environment/environment.xml
|
||||
$file = $CFG->dataroot.'/environment/environment.xml';
|
||||
$internalfile = $CFG->dirroot.'/'.$CFG->admin.'/environment.xml';
|
||||
if (!is_file($file) || !is_readable($file) || filemtime($file) < filemtime($internalfile) ||
|
||||
if (!is_file($file) || !is_readable($file) || filemtime($file) < filemtime($internalfile) ||
|
||||
!$contents = file_get_contents($file)) {
|
||||
/// Fallback to fixed $CFG->admin/environment.xml
|
||||
if (!is_file($internalfile) || !is_readable($internalfile) || !$contents = file_get_contents($internalfile)) {
|
||||
@@ -353,12 +385,12 @@ function get_latest_version_available ($version) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* This function will return the xmlized data belonging to one Moodle version
|
||||
* @return mixed the xmlized structure or false on error
|
||||
*/
|
||||
function get_environment_for_version($version) {
|
||||
|
||||
|
||||
/// Normalize the version requested
|
||||
$version = normalize_version($version);
|
||||
|
||||
@@ -379,12 +411,12 @@ function get_environment_for_version($version) {
|
||||
|
||||
/// We now we have it. Extract from full contents.
|
||||
$fl_arr = array_flip($versions);
|
||||
|
||||
|
||||
return $contents['COMPATIBILITY_MATRIX']['#']['MOODLE'][$fl_arr[$version]];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* This function will check for everything (DB, PHP and PHP extensions for now)
|
||||
* returning an array of environment_result objects.
|
||||
* @param string $version xml version we are going to use to test this server
|
||||
@@ -525,7 +557,7 @@ function environment_check_php($version) {
|
||||
} else {
|
||||
$result->setStatus(false);
|
||||
}
|
||||
$result->setLevel($level);
|
||||
$result->setLevel($level);
|
||||
$result->setCurrentVersion($current_version);
|
||||
$result->setNeededVersion($needed_version);
|
||||
/// Process messages, modifying the $result if needed.
|
||||
@@ -677,7 +709,7 @@ function environment_check_database($version) {
|
||||
} else {
|
||||
$result->setStatus(false);
|
||||
}
|
||||
$result->setLevel($level);
|
||||
$result->setLevel($level);
|
||||
$result->setCurrentVersion($current_version);
|
||||
$result->setNeededVersion($needed_version);
|
||||
$result->setInfo($current_vendor);
|
||||
@@ -796,7 +828,7 @@ function process_environment_messages($xml, &$result) {
|
||||
//--- Helper Class to return results to caller ---//
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* This class is used to return the results of the environment
|
||||
* main functions (environment_check_xxxx)
|
||||
*/
|
||||
@@ -879,7 +911,7 @@ class environment_results {
|
||||
function setInfo($info) {
|
||||
$this->info=$info;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the feedback string
|
||||
* @param string the feedback string
|
||||
@@ -929,7 +961,7 @@ class environment_results {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current version
|
||||
* Get the current version
|
||||
* @return string current version
|
||||
*/
|
||||
function getCurrentVersion() {
|
||||
@@ -1009,7 +1041,7 @@ function bypass_mysql416_reqs ($result) {
|
||||
/// checker. All those functions will receive the result object and will
|
||||
/// return it modified as needed (status and bypass string)
|
||||
|
||||
/**
|
||||
/**
|
||||
* This function will restrict PHP reqs if:
|
||||
* - We are using PHP 5.0.x, informing about the buggy version
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user