mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-17846 moved blocks code from /blocks/db/* to core
This commit is contained in:
parent
27bd819be5
commit
ab2eb65c88
10 changed files with 73 additions and 253 deletions
109
lib/blocklib.php
109
lib/blocklib.php
|
@ -1069,115 +1069,6 @@ function blocks_repopulate_page($page) {
|
|||
return true;
|
||||
}
|
||||
|
||||
function upgrade_blocks_db($continueto) {
|
||||
/// This function upgrades the blocks tables, if necessary
|
||||
/// It's called from admin/index.php
|
||||
|
||||
global $CFG, $interactive, $DB;
|
||||
|
||||
require_once ($CFG->dirroot .'/blocks/version.php'); // Get code versions
|
||||
|
||||
if (empty($CFG->blocks_version)) { // Blocks have never been installed.
|
||||
$strdatabaseupgrades = get_string('databaseupgrades');
|
||||
if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
|
||||
print_header($strdatabaseupgrades, $strdatabaseupgrades,
|
||||
build_navigation(array(array('name' => $strdatabaseupgrades, 'link' => null, 'type' => 'misc'))), '',
|
||||
upgrade_get_javascript(), false, ' ', ' ');
|
||||
}
|
||||
upgrade_log_start();
|
||||
print_heading('blocks');
|
||||
if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
|
||||
$DB->set_debug(true);
|
||||
}
|
||||
/// Both old .sql files and new install.xml are supported
|
||||
/// but we priorize install.xml (XMLDB) if present
|
||||
$DB->get_manager()->install_from_xmldb_file($CFG->dirroot . '/blocks/db/install.xml'); //New method
|
||||
$status = true;
|
||||
if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
|
||||
$DB->set_debug(false);
|
||||
}
|
||||
if ($status) {
|
||||
if (set_config('blocks_version', $blocks_version)) {
|
||||
notify(get_string('databasesuccess'), 'notifysuccess');
|
||||
notify(get_string('databaseupgradeblocks', '', $blocks_version), 'notifysuccess');
|
||||
if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
|
||||
print_continue($continueto);
|
||||
print_footer('none');
|
||||
exit;
|
||||
} else if (CLI_UPGRADE && ($interactive > CLI_SEMI) ) {
|
||||
console_write('askcontinue');
|
||||
if (read_boolean()){
|
||||
return ;
|
||||
}else {
|
||||
console_write_error('','',false);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
print_error('cannotupgradeblock');
|
||||
}
|
||||
} else {
|
||||
print_error('cannotsetupblock');
|
||||
}
|
||||
}
|
||||
|
||||
/// Upgrading code starts here
|
||||
$newupgrade = false;
|
||||
if (is_readable($CFG->dirroot . '/blocks/db/upgrade.php')) {
|
||||
include_once($CFG->dirroot . '/blocks/db/upgrade.php'); // defines new upgrading function
|
||||
$newupgrade = true;
|
||||
}
|
||||
|
||||
if ($blocks_version > $CFG->blocks_version) { // Upgrade tables
|
||||
$strdatabaseupgrades = get_string('databaseupgrades');
|
||||
if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
|
||||
print_header($strdatabaseupgrades, $strdatabaseupgrades,
|
||||
build_navigation(array(array('name' => $strdatabaseupgrades, 'link' => null, 'type' => 'misc'))), '', upgrade_get_javascript());
|
||||
}
|
||||
upgrade_log_start();
|
||||
|
||||
print_heading('blocks');
|
||||
|
||||
/// Run de old and new upgrade functions for the module
|
||||
$newupgrade_function = 'xmldb_blocks_upgrade';
|
||||
|
||||
/// Then, the new function if exists and the old one was ok
|
||||
$newupgrade_status = true;
|
||||
if ($newupgrade && function_exists($newupgrade_function)) {
|
||||
if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
|
||||
$DB->set_debug(true);
|
||||
}
|
||||
$newupgrade_status = $newupgrade_function($CFG->blocks_version);
|
||||
} else if ($newupgrade) {
|
||||
notify ('Upgrade function ' . $newupgrade_function . ' was not available in ' .
|
||||
'/blocks/db/upgrade.php');
|
||||
}
|
||||
if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
|
||||
$DB->set_debug(false);
|
||||
}
|
||||
/// Now analyze upgrade results
|
||||
if ($newupgrade_status) { // No upgrading failed
|
||||
if (set_config('blocks_version', $blocks_version)) {
|
||||
notify(get_string('databasesuccess'), 'notifysuccess');
|
||||
notify(get_string('databaseupgradeblocks', '', $blocks_version), 'notifysuccess');
|
||||
if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
|
||||
print_continue($continueto);
|
||||
print_footer('none');
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
print_error('cannotupgradeblock');
|
||||
}
|
||||
} else {
|
||||
print_error('cannotupgradeblock');
|
||||
}
|
||||
|
||||
} else if ($blocks_version < $CFG->blocks_version) {
|
||||
upgrade_log_start();
|
||||
notify('WARNING!!! The Blocks version you are using is OLDER than the version that made these databases!');
|
||||
}
|
||||
upgrade_log_finish();
|
||||
}
|
||||
|
||||
//This function finds all available blocks and install them
|
||||
//into blocks table or do all the upgrade process if newer
|
||||
function upgrade_blocks_plugins($continueto) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue