function is_staging_gte($b, $a) { if ($a === $b) { return true; } $a = normalize_version($a); $b = normalize_version($b); $split_a = explode('.', $a); $split_b = explode('.', $b); foreach ($split_a as $i => $part_a) { $cmp = strcmp($part_a, $split_b[$i]); if (0 === $cmp) { continue; } // Weird thing to do to handle numeric (0,1) considered higher version than alpha, beta, rc. if (is_numeric($part_a) && !is_numeric($split_b[$i])) { return true; } if (!is_numeric($part_a) && is_numeric($split_b[$i])) { return false; } if (0 < $cmp) { return true; } else { return false; } } return false; }
public function test_environment() { global $CFG; require_once $CFG->libdir . '/environmentlib.php'; list($envstatus, $environment_results) = check_moodle_environment(normalize_version($CFG->release), ENV_SELECT_RELEASE); $this->assertNotEmpty($envstatus); foreach ($environment_results as $environment_result) { $this->assertTrue($environment_result->getStatus(), "Problem detected in environment ({$environment_result->part}:{$environment_result->info}), fix all warnings and errors!"); } }
/** * Test the environment. */ public function test_environment() { global $CFG; require_once $CFG->libdir . '/environmentlib.php'; list($envstatus, $environment_results) = check_moodle_environment(normalize_version($CFG->release), ENV_SELECT_RELEASE); $this->assertNotEmpty($envstatus); foreach ($environment_results as $environment_result) { if ($environment_result->part === 'php_setting' and $environment_result->info === 'opcache.enable' and $environment_result->getLevel() === 'optional' and $environment_result->getStatus() === false) { $this->markTestSkipped('OPCache extension is not necessary for unit testing.'); continue; } $this->assertTrue($environment_result->getStatus(), "Problem detected in environment ({$environment_result->part}:{$environment_result->info}), fix all warnings and errors!"); } }
$strinstallation = get_string('installation', 'install'); // remove current session content completely session_get_instance()->terminate_current(); if (empty($agreelicense)) { $strlicense = get_string('license'); $PAGE->navbar->add($strlicense); $PAGE->set_title($strinstallation . ' - Moodle ' . $CFG->target_release); $PAGE->set_heading($strinstallation); $PAGE->set_cacheable(false); $output = $PAGE->get_renderer('core', 'admin'); echo $output->install_licence_page(); die; } if (empty($confirmrelease)) { require_once $CFG->libdir . '/environmentlib.php'; list($envstatus, $environment_results) = check_moodle_environment(normalize_version($release), ENV_SELECT_RELEASE); $strcurrentrelease = get_string('currentrelease'); $PAGE->navbar->add($strcurrentrelease); $PAGE->set_title($strinstallation); $PAGE->set_heading($strinstallation . ' - Moodle ' . $CFG->target_release); $PAGE->set_cacheable(false); $output = $PAGE->get_renderer('core', 'admin'); echo $output->install_environment_page($maturity, $envstatus, $environment_results, $release); die; } //TODO: add a page with list of non-standard plugins here $strdatabasesetup = get_string('databasesetup'); upgrade_init_javascript(); $PAGE->navbar->add($strdatabasesetup); $PAGE->set_title($strinstallation . ' - Moodle ' . $CFG->target_release); $PAGE->set_heading($strinstallation);
/** * Install Moodle DB, * config.php must exist, there must not be any tables in db yet. * * @param array $options adminpass is mandatory * @param bool $interactive * @return void */ function install_cli_database(array $options, $interactive) { global $CFG, $DB; require_once $CFG->libdir . '/environmentlib.php'; require_once $CFG->libdir . '/upgradelib.php'; // show as much debug as possible @error_reporting(E_ALL | E_STRICT); @ini_set('display_errors', '1'); $CFG->debug = E_ALL | E_STRICT; $CFG->debugdisplay = true; $CFG->version = ''; $CFG->release = ''; $CFG->branch = ''; $version = null; $release = null; $branch = null; // read $version and $release require $CFG->dirroot . '/version.php'; if ($DB->get_tables()) { cli_error(get_string('clitablesexist', 'install')); } if (empty($options['adminpass'])) { cli_error('Missing required admin password'); } // test environment first list($envstatus, $environment_results) = check_moodle_environment(normalize_version($release), ENV_SELECT_RELEASE); if (!$envstatus) { $errors = environment_get_errors($environment_results); cli_heading(get_string('environment', 'admin')); foreach ($errors as $error) { list($info, $report) = $error; echo "!! {$info} !!\n{$report}\n\n"; } exit(1); } if (!$DB->setup_is_unicodedb()) { if (!$DB->change_db_encoding()) { // If could not convert successfully, throw error, and prevent installation cli_error(get_string('unicoderequired', 'admin')); } } if ($interactive) { cli_separator(); cli_heading(get_string('databasesetup')); } // install core install_core($version, true); set_config('release', $release); set_config('branch', $branch); if (PHPUNIT_TEST) { // mark as test database as soon as possible set_config('phpunittest', 'na'); } // install all plugins types, local, etc. upgrade_noncore(true); // set up admin user password $DB->set_field('user', 'password', hash_internal_user_password($options['adminpass']), array('username' => 'admin')); // rename admin username if needed if (isset($options['adminuser']) and $options['adminuser'] !== 'admin' and $options['adminuser'] !== 'guest') { $DB->set_field('user', 'username', $options['adminuser'], array('username' => 'admin')); } // indicate that this site is fully configured set_config('rolesactive', 1); upgrade_finished(); // log in as admin - we need do anything when applying defaults $admins = get_admins(); $admin = reset($admins); session_set_user($admin); // apply all default settings, do it twice to fill all defaults - some settings depend on other setting admin_apply_default_settings(NULL, true); admin_apply_default_settings(NULL, true); set_config('registerauth', ''); // set the site name if (isset($options['shortname']) and $options['shortname'] !== '') { $DB->set_field('course', 'shortname', $options['shortname'], array('format' => 'site')); } if (isset($options['fullname']) and $options['fullname'] !== '') { $DB->set_field('course', 'fullname', $options['fullname'], array('format' => 'site')); } }
/** * This function will check if database requirements are satisfied * * @global object * @uses NO_VERSION_DATA_FOUND * @uses NO_DATABASE_SECTION_FOUND * @uses NO_DATABASE_VENDORS_FOUND * @uses NO_DATABASE_VENDOR_MYSQL_FOUND * @uses NO_DATABASE_VENDOR_POSTGRES_FOUND * @uses NO_DATABASE_VENDOR_VERSION_FOUND * @param string $version xml version we are going to use to test this server * @param int $env_select one of ENV_SELECT_NEWER | ENV_SELECT_DATAROOT | ENV_SELECT_RELEASE decide xml to use. * @return object results encapsulated in one environment_result object */ function environment_check_database($version, $env_select) { global $DB; $result = new environment_results('database'); $vendors = array(); //Array of vendors in version /// Get the enviroment version we need if (!($data = get_environment_for_version($version, $env_select))) { /// Error. No version data found $result->setStatus(false); $result->setErrorCode(NO_VERSION_DATA_FOUND); return $result; } /// Extract the database part if (!isset($data['#']['DATABASE'])) { /// Error. No DATABASE section found $result->setStatus(false); $result->setErrorCode(NO_DATABASE_SECTION_FOUND); return $result; } else { /// Extract level $level = get_level($data['#']['DATABASE']['0']); } /// Extract DB vendors. At least 2 are mandatory (mysql & postgres) if (!isset($data['#']['DATABASE']['0']['#']['VENDOR'])) { /// Error. No VENDORS found $result->setStatus(false); $result->setErrorCode(NO_DATABASE_VENDORS_FOUND); return $result; } else { /// Extract vendors foreach ($data['#']['DATABASE']['0']['#']['VENDOR'] as $vendor) { if (isset($vendor['@']['name']) && isset($vendor['@']['version'])) { $vendors[$vendor['@']['name']] = $vendor['@']['version']; $vendorsxml[$vendor['@']['name']] = $vendor; } } } /// Check we have the mysql vendor version if (empty($vendors['mysql'])) { $result->setStatus(false); $result->setErrorCode(NO_DATABASE_VENDOR_MYSQL_FOUND); return $result; } /// Check we have the postgres vendor version if (empty($vendors['postgres'])) { $result->setStatus(false); $result->setErrorCode(NO_DATABASE_VENDOR_POSTGRES_FOUND); return $result; } /// Now search the version we are using (depending of vendor) $current_vendor = $DB->get_dbfamily(); $dbinfo = $DB->get_server_info(); $current_version = normalize_version($dbinfo['version']); $needed_version = $vendors[$current_vendor]; /// Check we have a needed version if (!$needed_version) { $result->setStatus(false); $result->setErrorCode(NO_DATABASE_VENDOR_VERSION_FOUND); return $result; } /// And finally compare them, saving results if (version_compare($current_version, $needed_version, '>=')) { $result->setStatus(true); } else { $result->setStatus(false); } $result->setLevel($level); $result->setCurrentVersion($current_version); $result->setNeededVersion($needed_version); $result->setInfo($current_vendor); /// Do any actions defined in the XML file. process_environment_result($vendorsxml[$current_vendor], $result); return $result; }
$PAGE->set_cacheable(false); echo $OUTPUT->header(); echo $OUTPUT->heading("Moodle {$release}"); if (isset($maturity)) { // main version.php declares moodle code maturity if ($maturity < MATURITY_STABLE) { $maturitylevel = get_string('maturity' . $maturity, 'admin'); echo $OUTPUT->box($OUTPUT->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) . $OUTPUT->container($OUTPUT->doc_link('admin/versions', get_string('morehelp'))), 'generalbox maturitywarning'); } } $releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/en/Release_Notes'); $releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack echo $OUTPUT->box($releasenoteslink, 'generalbox releasenoteslink'); require_once $CFG->libdir . '/environmentlib.php'; if (!check_moodle_environment(normalize_version($release), $environment_results, true, ENV_SELECT_RELEASE)) { print_upgrade_reload("index.php?agreelicense=1&lang={$CFG->lang}"); } else { echo $OUTPUT->notification(get_string('environmentok', 'admin'), 'notifysuccess'); echo $OUTPUT->continue_button(new moodle_url('/admin/index.php', array('agreelicense' => 1, 'confirmrelease' => 1, 'lang' => $CFG->lang))); } echo $OUTPUT->footer(); die; } $strdatabasesetup = get_string('databasesetup'); upgrade_init_javascript(); $PAGE->navbar->add($strdatabasesetup); $PAGE->set_title($strinstallation . ' - Moodle ' . $CFG->target_release); $PAGE->set_heading($strinstallation); $PAGE->set_cacheable(false); echo $OUTPUT->header();
$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 $versions[$env_version] = $env_version . ' ' . $strupwards; } else { $versions = array('error' => $strerror); } } /// Print form and popup menu echo '<div style="text-align:center">' . $strmoodleversion . ' '; popup_form("{$CFG->wwwroot}/{$CFG->admin}/environment.php?version=", $versions, 'selectversion', $version, ''); echo '</div>'; /// End of main box print_simple_box_end();
/** * Gets a text-based site version description. * * @return string The site info */ public static function get_site_info() { global $CFG; $output = ''; // All developers have to understand English, do not localise! $env = self::get_environment(); $output .= "Moodle " . $env['moodleversion']; if ($hash = self::get_git_hash()) { $output .= ", {$hash}"; } $output .= "\n"; // Add php version. require_once $CFG->libdir . '/environmentlib.php'; $output .= "Php: " . normalize_version($env['phpversion']); // Add database type and version. $output .= ", " . $env['dbtype'] . ": " . $env['dbversion']; // OS details. $output .= ", OS: " . $env['os'] . "\n"; return $output; }
/** * Check if the current PHP version is greater than or equal to an * unsupported version. * * @param object $result an environment_results instance * @param string $version the version of PHP that can't be used * @return bool result of version check */ function restrict_php_version(&$result, $version) { // Get the current PHP version. $currentversion = normalize_version(phpversion()); // Confirm we're using a supported PHP version. if (version_compare($currentversion, $version, '<')) { // Everything is ok, the restriction doesn't apply. return false; } else { // We're using an unsupported PHP version, apply restriction. return true; } }
<legend>Script Repository</legend> <table id='fppScripts' cellspacing='5'> <tbody> <?php $indexCSV = file_get_contents("https://raw.githubusercontent.com/FalconChristmas/fpp-scripts/master/index.csv"); $lines = explode("\n", $indexCSV); $count = 0; foreach ($lines as $line) { if (preg_match("/^#/", $line)) { continue; } $parts = explode(',', $line); if (count($parts) < 4) { continue; } if (normalize_version($parts[3]) > $rfs_ver) { continue; } if ($count > 0) { ?> <tr><td colspan='3'><hr></td></tr> <?php } ?> <tr><td rowspan='3' valign='top'><input type='button' class='buttons' value='Install' onClick='InstallRemoteScript("<?php echo $parts[0]; ?> ", "<?php echo $parts[1]; ?> ");'><br />
function mnetadmin_rpc_upgrade($user, $json_response = true) { global $CFG, $USER; // Invoke local user and check his rights if ($auth_response = invoke_local_user((array) $user)) { if ($json_response) { return $auth_response; } else { return json_decode($auth_response); } } // Creating response $response = new stdclass(); $response->status = RPC_SUCCESS; require "{$CFG->dirroot}/version.php"; // defines $version, $release, $branch and $maturity $CFG->target_release = $release; // used during installation and upgrades if ($version < $CFG->version) { $response->status = RPC_FAILURE_RUN; $response->error = get_string('downgradedcore', 'error'); $response->errors[] = get_string('downgradedcore', 'error'); if ($json_response) { return json_encode($response); } else { return $response; } } $oldversion = "{$CFG->release} ({$CFG->version})"; $newversion = "{$release} ({$version})"; if (!moodle_needs_upgrading()) { $response->message = get_string('cliupgradenoneed', 'core_admin', $newversion); if ($json_response) { return json_encode($response); } else { return $response; } } // debug_trace('Remote Upgrade : Environment check'); list($envstatus, $environment_results) = check_moodle_environment(normalize_version($release), ENV_SELECT_NEWER); if (!$envstatus) { $response->status = RPC_FAILURE_RUN; $response->error = vmoodle_get_string('environmentissues', 'vmoodleadminset_upgrade'); $response->errors[] = vmoodle_get_string('environmentissues', 'vmoodleadminset_upgrade'); $response->detail = $environment_results; if ($json_response) { return json_encode($response); } else { return $response; } } // Test plugin dependencies. // debug_trace('Remote Upgrade : Plugins check'); $failed = array(); if (!plugin_manager::instance()->all_plugins_ok($version, $failed)) { $response->status = RPC_FAILURE_RUN; $response->error = get_string('pluginschecktodo', 'admin'); $response->errors[] = get_string('pluginschecktodo', 'admin'); if ($json_response) { return json_encode($response); } else { return $response; } } ob_start(); // debug_trace('Remote Upgrade : Upgrade core'); if ($version > $CFG->version) { upgrade_core($version, false); } set_config('release', $release); set_config('branch', $branch); // unconditionally upgrade // debug_trace('Remote Upgrade : Upgrade other'); upgrade_noncore(false); // log in as admin - we need doanything permission when applying defaults // debug_trace('Remote Upgrade : Turning ADMIN '); session_set_user(get_admin()); // apply all default settings, just in case do it twice to fill all defaults // debug_trace('Remote Upgrade : Applying settings '); admin_apply_default_settings(NULL, false); admin_apply_default_settings(NULL, false); ob_end_clean(); $response->message = vmoodle_get_string('upgradecomplete', 'vmoodleadminset_upgrade', $newversion); if ($json_response) { return json_encode($response); } else { return $response; } }
/** * Test the restrict_php_version() function returns false if the current * PHP version is less than the restricted version */ public function test_restrict_php_version_less_than_restricted_version() { global $CFG; require_once $CFG->libdir . '/environmentlib.php'; $result = new environment_results('php'); $delimiter = '.'; // Get the current PHP version. $currentversion = explode($delimiter, normalize_version(phpversion())); // Lets increase the major version to ensure don't trip the restriction. $currentversion[0]++; $restrictedversion = implode($delimiter, $currentversion); // Make sure the status is true before the test to see it flip to false. $result->setStatus(true); $this->assertFalse(restrict_php_version($result, $restrictedversion), 'restrict_php_version returns false if the current version is less than the restricted version'); }
/** * Returns environment info: php version, db vendor, db version, * moodle version and plugin version. * * @return array */ public static function get_environment_info() { global $DB, $CFG; require_once "{$CFG->libdir}/environmentlib.php"; require_once "{$CFG->libdir}/adminlib.php"; $envinfo = array('system' => php_uname('s'), 'server' => php_sapi_name(), 'phpversion' => normalize_version(phpversion()), 'dbvendor' => $DB->get_dbvendor(), 'dbversion' => '', 'moodleversion' => '', 'pluginversion' => ''); $dbinfo = $DB->get_server_info(); if (!empty($dbinfo['version'])) { $envinfo['dbversion'] = normalize_version($dbinfo['version']); } if ($version = get_component_version('moodle')) { $envinfo['moodleversion'] = normalize_version($version); } if ($version = get_component_version('block_mhaairs')) { $envinfo['pluginversion'] = normalize_version($version); } return (object) $envinfo; }