Пример #1
0
    /**
     * Test the get_list_of_environment_versions() function.
     */
    public function test_get_list_of_environment_versions()
    {
        global $CFG;
        require_once $CFG->libdir . '/environmentlib.php';
        // Build a sample xmlised environment.xml.
        $xml = <<<END
<COMPATIBILITY_MATRIX>
    <MOODLE version="1.9">
        <PHP_EXTENSIONS>
            <PHP_EXTENSION name="xsl" level="required" />
        </PHP_EXTENSIONS>
    </MOODLE>
    <MOODLE version="2.5">
        <PHP_EXTENSIONS>
            <PHP_EXTENSION name="xsl" level="required" />
        </PHP_EXTENSIONS>
    </MOODLE>
    <MOODLE version="2.6">
        <PHP_EXTENSIONS>
            <PHP_EXTENSION name="xsl" level="required" />
        </PHP_EXTENSIONS>
    </MOODLE>
    <MOODLE version="2.7">
        <PHP_EXTENSIONS>
            <PHP_EXTENSION name="xsl" level="required" />
        </PHP_EXTENSIONS>
    </MOODLE>
    <PLUGIN name="block_test">
        <PHP_EXTENSIONS>
            <PHP_EXTENSION name="xsl" level="required" />
        </PHP_EXTENSIONS>
    </PLUGIN>
</COMPATIBILITY_MATRIX>
END;
        $environemt = xmlize($xml);
        $versions = get_list_of_environment_versions($environemt);
        $this->assertCount(5, $versions);
        $this->assertContains('1.9', $versions);
        $this->assertContains('2.5', $versions);
        $this->assertContains('2.6', $versions);
        $this->assertContains('2.7', $versions);
        $this->assertContains('all', $versions);
    }
/**
 * This function will return the xmlized data belonging to one Moodle version
 *
 * @param string $version top version from which we start to look backwards
 * @param int $env_select one of ENV_SELECT_NEWER | ENV_SELECT_DATAROOT | ENV_SELECT_RELEASE decide xml to use.
 * @return mixed the xmlized structure or false on error
 */
function get_environment_for_version($version, $env_select)
{
    /// Normalize the version requested
    $version = normalize_version($version);
    /// Load xml file
    if (!($contents = load_environment_xml($env_select))) {
        return false;
    }
    /// Detect available versions
    if (!($versions = get_list_of_environment_versions($contents))) {
        return false;
    }
    /// If the version requested is available
    if (!in_array($version, $versions)) {
        return false;
    }
    /// We now we have it. Extract from full contents.
    $fl_arr = array_flip($versions);
    return $contents['COMPATIBILITY_MATRIX']['#']['MOODLE'][$fl_arr[$version]];
}
Пример #3
0
                break;
            case INSTALLED:
                print_simple_box(get_string('componentinstalled', 'admin'), 'center');
                break;
        }
    }
}
/// Start of main box
print_simple_box_start('center');
echo "<div style=\"text-align:center\">" . $stradminhelpenvironment . "</div><br />";
/// Get current Moodle version
$current_version = $CFG->release;
/// Calculate list of versions
$versions = array();
if ($contents = load_environment_xml()) {
    if ($env_versions = get_list_of_environment_versions($contents)) {
        /// Set the current version at the beginning
        $env_version = normalize_version($current_version);
        //We need this later (for the upwards)
        $versions[$env_version] = $current_version;
        /// If no version has been previously selected, default to $current_version
        if (empty($version)) {
            $version = $env_version;
        }
        ///Iterate over each version, adding bigged than current
        foreach ($env_versions as $env_version) {
            if (version_compare(normalize_version($current_version), $env_version, '<')) {
                $versions[$env_version] = $env_version;
            }
        }
        /// Add 'upwards' to the last element
Пример #4
0
/**
 * This function will return the xmlized data belonging to one Moodle version
 *
 * @param string $version top version from which we start to look backwards
 * @param int|string $env_select one of ENV_SELECT_NEWER | ENV_SELECT_DATAROOT | ENV_SELECT_RELEASE decide xml to use. String means plugin name.
 * @return mixed the xmlized structure or false on error
 */
function get_environment_for_version($version, $env_select)
{
    /// Normalize the version requested
    $version = normalize_version($version);
    /// Load xml file
    if (!($contents = load_environment_xml($env_select))) {
        return false;
    }
    /// Detect available versions
    if (!($versions = get_list_of_environment_versions($contents))) {
        return false;
    }
    // If $env_select is not numeric then this is being called on a plugin, and not the core environment.xml
    // If a version of 'all' is in the arry is also means that the new <PLUGIN> tag was found, this should
    // be matched against any version of Moodle.
    if (!is_numeric($env_select) && in_array('all', $versions) && environment_verify_plugin($env_select, $contents['COMPATIBILITY_MATRIX']['#']['PLUGIN'][0])) {
        return $contents['COMPATIBILITY_MATRIX']['#']['PLUGIN'][0];
    }
    /// If the version requested is available
    if (!in_array($version, $versions)) {
        return false;
    }
    /// We now we have it. Extract from full contents.
    $fl_arr = array_flip($versions);
    return $contents['COMPATIBILITY_MATRIX']['#']['MOODLE'][$fl_arr[$version]];
}