From: skodak Date: Tue, 26 May 2009 09:52:38 +0000 (+0000) Subject: MDL-15249 refactoring towards cli install script X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=8580535b811987c480f1a72c5da56d5c544167e6;p=moodle.git MDL-15249 refactoring towards cli install script --- diff --git a/admin/index.php b/admin/index.php index 10f335b02a..f12c009505 100644 --- a/admin/index.php +++ b/admin/index.php @@ -1,4 +1,27 @@ -. + +/** + * Main administration script. + * + * @package moodlecore + * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com) + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ /// Check that config.php exists, if not then call the install script if (!file_exists('../config.php')) { @@ -157,31 +180,7 @@ } } - try { - print_upgrade_part_start('moodle', true); // does not store upgrade running flag - - $DB->get_manager()->install_from_xmldb_file("$CFG->libdir/db/install.xml"); - upgrade_started(); // we want the flag to be stored in config table ;-) - - /// set all core default records and default settings - require_once("$CFG->libdir/db/install.php"); - xmldb_main_install(); - - /// store version - upgrade_main_savepoint(true, $version, false); - - /// Continue with the instalation - events_update_definition('moodle'); - message_update_providers('moodle'); - message_update_providers('message'); - - /// Write default settings unconditionlly - admin_apply_default_settings(NULL, true); - - print_upgrade_part_end(null, true); - } catch (exception $ex) { - upgrade_handle_exception($ex); - } + install_core($version, true); } @@ -251,74 +250,20 @@ die(); } else { - - /// Launch main upgrade - try { - - // Upgrade current language pack if we can - if (empty($CFG->skiplangupgrade)) { - upgrade_language_pack(false); - } - - print_upgrade_part_start('moodle', false); - - $result = xmldb_main_upgrade($CFG->version); - if ($version > $CFG->version) { - // store version if not already there - upgrade_main_savepoint($result, $version, false); - } - - // perform all other component upgrade routines - update_capabilities('moodle'); - events_update_definition('moodle'); - message_update_providers('moodle'); - message_update_providers('message'); - - remove_dir($CFG->dataroot . '/cache', true); // flush cache - - print_upgrade_part_end('moodle', false); - } catch (Exception $ex) { - upgrade_handle_exception($ex); - } + // Launch main upgrade + upgrade_core($version, true); } } else if ($version < $CFG->version) { notify("WARNING!!! The code you are using is OLDER than the version that made these databases!"); } /// Updated human-readable release version if necessary - if ($release <> $CFG->release) { // Update the release version set_config("release", $release); } -/// upgrade all plugins types - try { - $plugintypes = get_plugin_types(); - foreach ($plugintypes as $type=>$location) { - upgrade_plugins($type, $location, 'print_upgrade_part_start', 'print_upgrade_part_end'); - } - } catch (Exception $ex) { - upgrade_handle_exception($ex); - } - -/// Check for changes to RPC functions - if ($CFG->mnet_dispatcher_mode != 'off') { - try { - // this needs a full rewrite, sorry to mention that :-( - require_once("$CFG->dirroot/$CFG->admin/mnet/adminlib.php"); - upgrade_RPC_functions(); // Return here afterwards - } catch (Exception $ex) { - upgrade_handle_exception($ex); - } - } - -/// Check for local database customisations - try { - require_once("$CFG->dirroot/lib/locallib.php"); - upgrade_local_db('print_upgrade_part_start', 'print_upgrade_part_end'); - } catch (Exception $ex) { - upgrade_handle_exception($ex); - } + // upgrade all plugins and other parts + upgrade_noncore(true); /// indicate that this site is fully configured except the admin password if (empty($CFG->rolesactive)) { @@ -463,4 +408,3 @@ admin_externalpage_print_footer(); -?> diff --git a/lib/upgradelib.php b/lib/upgradelib.php index 4d7a76bee0..1b712abd98 100644 --- a/lib/upgradelib.php +++ b/lib/upgradelib.php @@ -16,7 +16,7 @@ // along with Moodle. If not, see . /** - * Various upgrade related functions an classes. + * Various upgrade/install related functions and classes. * * @package moodlecore * @subpackage upgrade @@ -909,7 +909,7 @@ function print_upgrade_separator() { * @param string $plugin * @param bool $installation true if installation, false menas upgrade */ -function print_upgrade_part_start($plugin, $installation) { +function print_upgrade_part_start($plugin, $installation=false) { if (empty($plugin) or $plugin == 'moodle') { upgrade_started($installation); // does not store upgrade running flag yet print_heading(get_string('coresystem')); @@ -937,7 +937,7 @@ function print_upgrade_part_start($plugin, $installation) { * @param string $plugin * @param bool $installation true if installation, false menas upgrade */ -function print_upgrade_part_end($plugin, $installation) { +function print_upgrade_part_end($plugin, $installation=false) { upgrade_started(); if ($installation) { if (empty($plugin) or $plugin == 'moodle') { @@ -961,7 +961,7 @@ function print_upgrade_part_end($plugin, $installation) { * @param string $plugin * @param bool $installation true if installation, false menas upgrade */ -function silent_upgrade_part_start($plugin, $installation) { +function silent_upgrade_part_start($plugin, $installation=false) { if (empty($plugin) or $plugin == 'moodle') { upgrade_started($installation); // does not store upgrade running flag yet } else { @@ -987,7 +987,7 @@ function silent_upgrade_part_start($plugin, $installation) { * @param string $plugin * @param bool $installation true if installation, false menas upgrade */ -function silent_upgrade_part_end($plugin, $installation) { +function silent_upgrade_part_end($plugin, $installation=false) { upgrade_started(); if ($installation) { if (empty($plugin) or $plugin == 'moodle') { @@ -1052,3 +1052,140 @@ function upgrade_language_pack($lang='') { print_upgrade_separator(); } + +/** + * Install core moodle tables and initialize + * @param float $version target version + * @param bool $verbose + * @return void, may throw exception + */ +function install_core($version, $verbose) { + global $CFG, $DB; + + try { + if ($verbose) { + print_upgrade_part_start('moodle', true); // does not store upgrade running flag + } else { + silent_upgrade_part_start('moodle', true); // does not store upgrade running flag + } + + $DB->get_manager()->install_from_xmldb_file("$CFG->libdir/db/install.xml"); + upgrade_started(); // we want the flag to be stored in config table ;-) + + // set all core default records and default settings + require_once("$CFG->libdir/db/install.php"); + xmldb_main_install(); + + // store version + upgrade_main_savepoint(true, $version, false); + + // Continue with the instalation + events_update_definition('moodle'); + message_update_providers('moodle'); + message_update_providers('message'); + + // Write default settings unconditionlly + admin_apply_default_settings(NULL, true); + + if ($verbose) { + print_upgrade_part_end(null, true); + } else { + silent_upgrade_part_end(null, true); + } + } catch (exception $ex) { + upgrade_handle_exception($ex); + } +} + +/** + * Upgrade moodle core + * @param float $version target version + * @param bool $verbose + * @return void, may throw exception + */ +function upgrade_core($version, $verbose) { + global $CFG; + + try { + // Upgrade current language pack if we can + if (empty($CFG->skiplangupgrade)) { + upgrade_language_pack(false); + } + + if ($verbose) { + print_upgrade_part_start('moodle'); + } else { + silent_upgrade_part_start('moodle'); + } + + $result = xmldb_main_upgrade($CFG->version); + if ($version > $CFG->version) { + // store version if not already there + upgrade_main_savepoint($result, $version, false); + } + + // perform all other component upgrade routines + update_capabilities('moodle'); + events_update_definition('moodle'); + message_update_providers('moodle'); + message_update_providers('message'); + + remove_dir($CFG->dataroot . '/cache', true); // flush cache + + if ($verbose) { + print_upgrade_part_end('moodle'); + } else { + silent_upgrade_part_end('moodle'); + } + } catch (Exception $ex) { + upgrade_handle_exception($ex); + } +} + +/** + * Upgrade/install other parts of moodle + * @param bool $verbose + * @return void, may throw exception + */ +function upgrade_noncore($verbose) { + global $CFG; + + // setup callbacks + if ($verbose) { + $start = 'print_upgrade_part_start'; + $end = 'print_upgrade_part_end'; + } else { + $start = 'silent_upgrade_part_start'; + $end = 'silent_upgrade_part_end'; + } + + // upgrade all plugins types + try { + $plugintypes = get_plugin_types(); + foreach ($plugintypes as $type=>$location) { + upgrade_plugins($type, $location, $start, $end); + } + } catch (Exception $ex) { + upgrade_handle_exception($ex); + } + + // Check for changes to RPC functions + if ($CFG->mnet_dispatcher_mode != 'off') { + try { + // this needs a full rewrite, sorry to mention that :-( + // we have to make it part of standard WS framework + require_once("$CFG->dirroot/$CFG->admin/mnet/adminlib.php"); + upgrade_RPC_functions(); // Return here afterwards + } catch (Exception $ex) { + upgrade_handle_exception($ex); + } + } + + // Check for local database customisations + try { + require_once("$CFG->dirroot/lib/locallib.php"); + upgrade_local_db($start, $end); + } catch (Exception $ex) { + upgrade_handle_exception($ex); + } +}