/** * Load global $CFG; * @internal * @static * @return void */ public static function initialise_cfg() { global $DB; $dbhash = false; try { $dbhash = $DB->get_field('config', 'value', array('name'=>'phpunittest')); } catch (Exception $e) { // not installed yet initialise_cfg(); return; } if ($dbhash !== core_component::get_all_versions_hash()) { // do not set CFG - the only way forward is to drop and reinstall return; } // standard CFG init initialise_cfg(); }
/** * Determine if moodle installation requires update. * * Checks version numbers of main code and all plugins to see * if there are any mismatches. * * @return bool */ function moodle_needs_upgrading() { global $CFG; if (empty($CFG->version)) { return true; } // There is no need to purge plugininfo caches here because // these caches are not used during upgrade and they are purged after // every upgrade. if (empty($CFG->allversionshash)) { return true; } $hash = core_component::get_all_versions_hash(); return $hash !== $CFG->allversionshash; }
/** * Upgrade/install other parts of moodle * @param bool $verbose * @return void, may throw exception */ function upgrade_noncore($verbose) { global $CFG; raise_memory_limit(MEMORY_EXTRA); // upgrade all plugins types try { // Reset caches before any output. cache_helper::purge_all(true); purge_all_caches(); $plugintypes = core_component::get_plugin_types(); foreach ($plugintypes as $type=>$location) { upgrade_plugins($type, 'print_upgrade_part_start', 'print_upgrade_part_end', $verbose); } // Update cache definitions. Involves scanning each plugin for any changes. cache_helper::update_definitions(); // Mark the site as upgraded. set_config('allversionshash', core_component::get_all_versions_hash()); // Purge caches again, just to be sure we arn't holding onto old stuff now. cache_helper::purge_all(true); purge_all_caches(); } catch (Exception $ex) { upgrade_handle_exception($ex); } }
/** * Stores the version hash in both database and dataroot */ protected static function store_versions_hash() { global $CFG; $framework = self::get_framework(); $hash = core_component::get_all_versions_hash(); // add test db flag set_config($framework . 'test', $hash); // hash all plugin versions - helps with very fast detection of db structure changes $hashfile = self::get_dataroot() . '/' . $framework . '/versionshash.txt'; file_put_contents($hashfile, $hash); testing_fix_file_permissions($hashfile); }
/** * Upgrade/install other parts of moodle * @param bool $verbose * @return void, may throw exception */ function upgrade_noncore($verbose) { global $CFG; raise_memory_limit(MEMORY_EXTRA); // upgrade all plugins types try { // Reset caches before any output. cache_helper::purge_all(true); purge_all_caches(); $plugintypes = core_component::get_plugin_types(); foreach ($plugintypes as $type => $location) { upgrade_plugins($type, 'print_upgrade_part_start', 'print_upgrade_part_end', $verbose); } // Upgrade services. // This function gives plugins and subsystems a chance to add functions to existing built-in services. external_update_services(); // Update cache definitions. Involves scanning each plugin for any changes. cache_helper::update_definitions(); // Mark the site as upgraded. set_config('allversionshash', core_component::get_all_versions_hash()); // Purge caches again, just to be sure we arn't holding onto old stuff now. cache_helper::purge_all(true); purge_all_caches(); } catch (Exception $ex) { upgrade_handle_exception($ex); } catch (Throwable $ex) { // Engine errors in PHP7 throw exceptions of type Throwable (this "catch" will be ignored in PHP5). upgrade_handle_exception($ex); } }
/** * Returns whether test database and dataroot were created using the current version codebase * * @return bool */ public static function is_site_data_updated() { $datarootpath = util::get_performance_dir(); if (!is_dir($datarootpath)) { return 1; } if (!file_exists($datarootpath . '/versionshash.txt')) { return 1; } $hash = \core_component::get_all_versions_hash(); $oldhash = file_get_contents($datarootpath . '/versionshash.txt'); if ($hash !== $oldhash) { return false; } $dbhash = get_config('core', 'perfromancesitehash'); if ($hash !== $dbhash) { return false; } return true; }