Skip to content
Browse files

Now results of check_moodle_environment() are

cached, saving us of some work when the script
is called more than once per request (install)

Merged from MOODLE_15_STABLE
  • Loading branch information...
1 parent 182dca1 commit 878d309c2b65dc54b09f2ab9f2f704394a576dcf stronk7 committed Jan 20, 2006
Showing with 33 additions and 19 deletions.
  1. +33 −19 lib/environmentlib.php
View
52 lib/environmentlib.php
@@ -61,35 +61,49 @@
function check_moodle_environment($version, &$environment_results, $print_table=true) {
$status = true;
- $result = true;
-/// Get the more recent version before the requested
- if (!$version = get_latest_version_available($version)) {
- $status = false;
- }
+/// This are cached per request
+ static $result = true;
+ static $env_results;
+ static $cache_exists = false;
-/// Perform all the checks
- if (!($environment_results = environment_check($version)) && $status) {
- $status = false;
- }
+/// if we have results cached, use them
+ if ($cache_exists) {
+ $environment_results = $env_results;
+/// No cache exists, calculate everything
+ } else {
+ /// Get the more recent version before the requested
+ if (!$version = get_latest_version_available($version)) {
+ $status = false;
+ }
+
+ /// Perform all the checks
+ if (!($environment_results = environment_check($version)) && $status) {
+ $status = false;
+ }
-/// Iterate over all the results looking for some error in required items
-/// or some error_code
- if ($status) {
- foreach ($environment_results as $environment_result) {
- if ((!$environment_result->getStatus() &&
- $environment_result->getLevel() == 'required') ||
- $environment_result->getErrorCode()) {
- $result = false;
+ /// Iterate over all the results looking for some error in required items
+ /// or some error_code
+ if ($status) {
+ foreach ($environment_results as $environment_result) {
+ if ((!$environment_result->getStatus() &&
+ $environment_result->getLevel() == 'required') ||
+ $environment_result->getErrorCode()) {
+ $result = false;
+ }
}
}
- }
+ /// Going to end, we store environment_results to cache
+ $env_results = $environment_results;
+ $cache_exists = true;
+ } ///End of cache block
/// If we have decided to print all the information, just do it
if ($print_table) {
print_moodle_environment($result && $status, $environment_results);
}
+
return ($result && $status);
}
@@ -129,7 +143,7 @@ function print_moodle_environment($result, $environment_results) {
$status = $environment_result->getStatus();
$error_code = $environment_result->getErrorCode();
/// Process Report field
- $rec = new object();
+ $rec = new stdClass();
/// Something has gone wrong at parsing time
if ($error_code) {
$stringtouse = 'environmentxmlerror';

0 comments on commit 878d309

Please sign in to comment.
Something went wrong with that request. Please try again.