From: skodak Date: Thu, 6 Aug 2009 19:59:16 +0000 (+0000) Subject: MDL-20015 a way to recover from problems in db/install.php X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=9b683d130ab5b363c91f4a56d4efc706e40741cb;p=moodle.git MDL-20015 a way to recover from problems in db/install.php --- diff --git a/lib/upgradelib.php b/lib/upgradelib.php index ba0a0e7f8b..3952d62ce0 100644 --- a/lib/upgradelib.php +++ b/lib/upgradelib.php @@ -322,8 +322,24 @@ function upgrade_plugins($type, $startcallback, $endcallback, $verbose) { } } - $installedversion = get_config($plugin->fullname, 'version'); + // try to recover from interrupted install.php if needed + if (file_exists($fullplug.'/db/install.php')) { + if (get_config($plugin->fullname, 'installrunning')) { + require_once($fullplug.'/db/install.php'); + $recover_install_function = 'xmldb_'.$plugin->fullname.'_install_recovery'; + if (function_exists($recover_install_function)) { + $startcallback($component, true, $verbose); + $recover_install_function(); + unset_config('installrunning', 'block_'.$plugin->fullname); + update_capabilities($component); + events_update_definition($component); + message_update_providers($component); + $endcallback($component, true, $verbose); + } + } + } + $installedversion = get_config($plugin->fullname, 'version'); if (empty($installedversion)) { // new installation $startcallback($component, true, $verbose); @@ -331,16 +347,19 @@ function upgrade_plugins($type, $startcallback, $endcallback, $verbose) { if (file_exists($fullplug.'/db/install.xml')) { $DB->get_manager()->install_from_xmldb_file($fullplug.'/db/install.xml'); } + + /// store version + upgrade_plugin_savepoint(true, $plugin->version, $type, $plug, false); + /// execute post install file if (file_exists($fullplug.'/db/install.php')) { require_once($fullplug.'/db/install.php'); + set_config('installrunning', 1, 'block_'.$plugin->fullname); $post_install_function = 'xmldb_'.$plugin->fullname.'_install';; $post_install_function(); + unset_config('installrunning', 'block_'.$plugin->fullname); } - /// store version - upgrade_plugin_savepoint(true, $plugin->version, $type, $plug, false); - /// Install various components update_capabilities($component); events_update_definition($component); @@ -425,6 +444,23 @@ function upgrade_plugins_modules($startcallback, $endcallback, $verbose) { $currmodule = $DB->get_record('modules', array('name'=>$module->name)); + if (file_exists($fullmod.'/db/install.php')) { + if (get_config($module->name, 'installrunning')) { + require_once($fullmod.'/db/install.php'); + $recover_install_function = 'xmldb_'.$module->name.'_install_recovery'; + if (function_exists($recover_install_function)) { + $startcallback($component, true, $verbose); + $recover_install_function(); + unset_config('installrunning', $module->name); + // Install various components too + update_capabilities($component); + events_update_definition($component); + message_update_providers($component); + $endcallback($component, true, $verbose); + } + } + } + if (empty($currmodule->version)) { $startcallback($component, true, $verbose); @@ -437,8 +473,11 @@ function upgrade_plugins_modules($startcallback, $endcallback, $verbose) { /// Post installation hook - optional if (file_exists("$fullmod/db/install.php")) { require_once("$fullmod/db/install.php"); + // Set installation running flag, we need to recover after exception or error + set_config('installrunning', 1, $module->name); $post_install_function = 'xmldb_'.$module->name.'_install';; $post_install_function(); + unset_config('installrunning', $module->name); } /// Install various components @@ -544,6 +583,23 @@ function upgrade_plugins_blocks($startcallback, $endcallback, $verbose) { $currblock = $DB->get_record('block', array('name'=>$block->name)); + if (file_exists($fullblock.'/db/install.php')) { + if (get_config('block_'.$blockname, 'installrunning')) { + require_once($fullblock.'/db/install.php'); + $recover_install_function = 'xmldb_block_'.$blockname.'_install_recovery'; + if (function_exists($recover_install_function)) { + $startcallback($component, true, $verbose); + $recover_install_function(); + unset_config('installrunning', 'block_'.$blockname); + // Install various components + update_capabilities($component); + events_update_definition($component); + message_update_providers($component); + $endcallback($component, true, $verbose); + } + } + } + if (empty($currblock->version)) { // block not installed yet, so install it // If it allows multiples, start with it enabled @@ -562,8 +618,11 @@ function upgrade_plugins_blocks($startcallback, $endcallback, $verbose) { if (file_exists($fullblock.'/db/install.php')) { require_once($fullblock.'/db/install.php'); + // Set installation running flag, we need to recover after exception or error + set_config('installrunning', 1, 'block_'.$blockname); $post_install_function = 'xmldb_block_'.$blockname.'_install';; $post_install_function(); + unset_config('installrunning', 'block_'.$blockname); } $blocktitles[$block->name] = $blocktitle; @@ -1044,7 +1103,7 @@ function core_tables_exist() { if (!$tables = $DB->get_tables() ) { // No tables yet at all. return false; - + } else { // Check for missing main tables $mtables = array('config', 'course', 'groupings'); // some tables used in 1.9 and 2.0, preferable something from the start and end of install.xml foreach ($mtables as $mtable) { @@ -1053,5 +1112,5 @@ function core_tables_exist() { } } return true; - } + } }