/**
 * This function will perform the whole check, returning
 * true or false as final result. Also, he full array of
 * environment_result will be returned in the parameter list.
 * 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 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)
{
    $status = true;
    /// This are cached per request
    static $result = true;
    static $env_results;
    static $cache_exists = 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->getBypassStr()) {
                    $result = false;
                    // required item that is not bypased
                } else {
                    if ($environment_result->getStatus() && $environment_result->getLevel() == 'required' && $environment_result->getRestrictStr()) {
                        $result = false;
                        // required item that is restricted
                    } else {
                        if ($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;
}
Beispiel #2
0
/**
 * This function checks all the requirements defined in environment.xml.
 *
 * @param string $version version to check.
 * @param int $env_select one of ENV_SELECT_NEWER | ENV_SELECT_DATAROOT | ENV_SELECT_RELEASE decide xml to use. Default ENV_SELECT_NEWER (BC)
 * @return array with two elements. The first element true/false, depending on
 *      on whether the check passed. The second element is an array of environment_results
 *      objects that has detailed information about the checks and which ones passed.
 */
function check_moodle_environment($version, $env_select = ENV_SELECT_NEWER)
{
    if ($env_select != ENV_SELECT_NEWER and $env_select != ENV_SELECT_DATAROOT and $env_select != ENV_SELECT_RELEASE) {
        throw new coding_exception('Incorrect value of $env_select parameter');
    }
    /// Get the more recent version before the requested
    if (!($version = get_latest_version_available($version, $env_select))) {
        return array(false, array());
    }
    /// Perform all the checks
    if (!($environment_results = environment_check($version, $env_select))) {
        return array(false, array());
    }
    /// Iterate over all the results looking for some error in required items
    /// or some error_code
    $result = true;
    foreach ($environment_results as $environment_result) {
        if (!$environment_result->getStatus() && $environment_result->getLevel() == 'required' && !$environment_result->getBypassStr()) {
            $result = false;
            // required item that is not bypased
        } else {
            if ($environment_result->getStatus() && $environment_result->getLevel() == 'required' && $environment_result->getRestrictStr()) {
                $result = false;
                // required item that is restricted
            } else {
                if ($environment_result->getErrorCode()) {
                    $result = false;
                }
            }
        }
    }
    return array($result, $environment_results);
}