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
|
@ -159,6 +159,7 @@ function upgrade_db($version, $release) {
|
|||
'filter_multilang_converted' => 1,
|
||||
'backup_version' => 2008111700,
|
||||
'backup_release' => '2.0 dev',
|
||||
'blocks_version' => 2007081300, // might be removed soon
|
||||
));
|
||||
|
||||
// store main version
|
||||
|
@ -376,13 +377,9 @@ function upgrade_db($version, $release) {
|
|||
/// It is important that this is done AFTER the quiz module has been upgraded
|
||||
upgrade_plugins('qtype', 'question/type', $return_url); // Return here afterwards
|
||||
|
||||
/// Upgrade blocks system if necessary
|
||||
/// first old *.php update and then the new upgrade.php script
|
||||
require_once("$CFG->dirroot/lib/blocklib.php");
|
||||
upgrade_blocks_db($return_url); // Return here afterwards
|
||||
|
||||
/// Check all blocks and load (or upgrade them if necessary)
|
||||
/// first old *.php update and then the new upgrade.php script
|
||||
require_once("$CFG->dirroot/lib/blocklib.php");
|
||||
upgrade_blocks_plugins($return_url); // Return here afterwards
|
||||
|
||||
/// Check all enrolment plugins and upgrade if necessary
|
||||
|
@ -758,9 +755,6 @@ function get_db_directories() {
|
|||
}
|
||||
}
|
||||
|
||||
/// Now, block system stuff (blocks/db)
|
||||
$dbdirs[] = $CFG->dirroot.'/blocks/db';
|
||||
|
||||
/// Now, blocks (blocks/xxx/db)
|
||||
if ($plugins = get_list_of_plugins('blocks', 'db')) {
|
||||
foreach ($plugins as $plugin) {
|
||||
|
@ -4718,7 +4712,7 @@ class admin_page_manageblocks extends admin_externalpage {
|
|||
}
|
||||
|
||||
$found = false;
|
||||
if (!empty($CFG->blocks_version) and $blocks = $DB->get_records('block')) {
|
||||
if ($blocks = $DB->get_records('block')) {
|
||||
$textlib = textlib_get_instance();
|
||||
foreach ($blocks as $block) {
|
||||
if (strpos($block->name, $query) !== false) {
|
||||
|
|
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) {
|
||||
|
|
|
@ -2069,7 +2069,7 @@
|
|||
<KEY NAME="courseid" TYPE="unique" FIELDS="courseid" PREVIOUS="primary"/>
|
||||
</KEYS>
|
||||
</TABLE>
|
||||
<TABLE NAME="backup_log" COMMENT="To store every course backup log info" PREVIOUS="backup_courses">
|
||||
<TABLE NAME="backup_log" COMMENT="To store every course backup log info" PREVIOUS="backup_courses" NEXT="block">
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="courseid"/>
|
||||
<FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="time"/>
|
||||
|
@ -2082,6 +2082,58 @@
|
|||
<KEY NAME="courseid" TYPE="foreign" FIELDS="courseid" REFTABLE="backup_courses" REFFIELDS="courseid" PREVIOUS="primary"/>
|
||||
</KEYS>
|
||||
</TABLE>
|
||||
<TABLE NAME="block" COMMENT="contains all installed blocks" PREVIOUS="backup_log" NEXT="block_pinned">
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="name"/>
|
||||
<FIELD NAME="name" TYPE="char" LENGTH="40" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="version"/>
|
||||
<FIELD NAME="version" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="name" NEXT="cron"/>
|
||||
<FIELD NAME="cron" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="version" NEXT="lastcron"/>
|
||||
<FIELD NAME="lastcron" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="cron" NEXT="visible"/>
|
||||
<FIELD NAME="visible" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="false" DEFAULT="1" SEQUENCE="false" ENUM="false" PREVIOUS="lastcron" NEXT="multiple"/>
|
||||
<FIELD NAME="multiple" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="visible"/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||
</KEYS>
|
||||
</TABLE>
|
||||
<TABLE NAME="block_pinned" COMMENT="to pin blocks" PREVIOUS="block" NEXT="block_instance">
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="blockid"/>
|
||||
<FIELD NAME="blockid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="pagetype"/>
|
||||
<FIELD NAME="pagetype" TYPE="char" LENGTH="20" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="blockid" NEXT="position"/>
|
||||
<FIELD NAME="position" TYPE="char" LENGTH="10" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="pagetype" NEXT="weight"/>
|
||||
<FIELD NAME="weight" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="position" NEXT="visible"/>
|
||||
<FIELD NAME="visible" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="weight" NEXT="configdata"/>
|
||||
<FIELD NAME="configdata" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="visible"/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="blockid"/>
|
||||
<KEY NAME="blockid" TYPE="foreign" FIELDS="blockid" REFTABLE="block" REFFIELDS="id" PREVIOUS="primary"/>
|
||||
</KEYS>
|
||||
<INDEXES>
|
||||
<INDEX NAME="pagetype" UNIQUE="false" FIELDS="pagetype"/>
|
||||
</INDEXES>
|
||||
</TABLE>
|
||||
<TABLE NAME="block_instance" COMMENT="to store block instances in pages" PREVIOUS="block_pinned">
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="blockid"/>
|
||||
<FIELD NAME="blockid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="pageid"/>
|
||||
<FIELD NAME="pageid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="blockid" NEXT="pagetype"/>
|
||||
<FIELD NAME="pagetype" TYPE="char" LENGTH="20" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="pageid" NEXT="position"/>
|
||||
<FIELD NAME="position" TYPE="char" LENGTH="10" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="pagetype" NEXT="weight"/>
|
||||
<FIELD NAME="weight" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="position" NEXT="visible"/>
|
||||
<FIELD NAME="visible" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="weight" NEXT="configdata"/>
|
||||
<FIELD NAME="configdata" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" ENUM="false" PREVIOUS="visible"/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="blockid"/>
|
||||
<KEY NAME="blockid" TYPE="foreign" FIELDS="blockid" REFTABLE="block" REFFIELDS="id" PREVIOUS="primary"/>
|
||||
</KEYS>
|
||||
<INDEXES>
|
||||
<INDEX NAME="pageid" UNIQUE="false" FIELDS="pageid" NEXT="pagetype"/>
|
||||
<INDEX NAME="pagetype" UNIQUE="false" FIELDS="pagetype" PREVIOUS="pageid"/>
|
||||
</INDEXES>
|
||||
</TABLE>
|
||||
</TABLES>
|
||||
<STATEMENTS>
|
||||
<STATEMENT NAME="insert mnet_application" TYPE="insert" TABLE="mnet_application" COMMENT="Initial insert of records on table mnet_application" NEXT="insert log_display">
|
||||
|
|
|
@ -1318,6 +1318,20 @@ function xmldb_main_upgrade($oldversion) {
|
|||
upgrade_main_savepoint($result, 2009010801);
|
||||
}
|
||||
|
||||
if ($result && $oldversion < 2009011000) {
|
||||
|
||||
/// Changing nullability of field configdata on table block_instance to null
|
||||
$table = new xmldb_table('block_instance');
|
||||
$field = new xmldb_field('configdata');
|
||||
$field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, 'visible');
|
||||
|
||||
/// Launch change of nullability for field configdata
|
||||
$dbman->change_field_notnull($table, $field);
|
||||
|
||||
/// Main savepoint reached
|
||||
upgrade_main_savepoint($result, 2009011000);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue