From: tjhunt Date: Wed, 6 May 2009 09:12:03 +0000 (+0000) Subject: blocklib: MDL-19010 upgrade database tables ready for now blocks system X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=66b10689e215e9888956dd4172a107c5395f3d94;p=moodle.git blocklib: MDL-19010 upgrade database tables ready for now blocks system --- diff --git a/admin/blocks.php b/admin/blocks.php index 99216f8249..eccd748a5c 100644 --- a/admin/blocks.php +++ b/admin/blocks.php @@ -83,7 +83,7 @@ } // First delete instances and then block - $instances = $DB->get_records('block_instance', array('blockid'=>$block->id)); + $instances = $DB->get_records('block_instance_old', array('blockid'=>$block->id)); if(!empty($instances)) { foreach($instances as $instance) { blocks_delete_instance($instance); @@ -169,8 +169,8 @@ // MDL-11167, blocks can be placed on mymoodle, or the blogs page // and it should not show up on course search page - $totalcount = $DB->count_records('block_instance', array('blockid'=>$blockid)); - $count = $DB->count_records('block_instance', array('blockid'=>$blockid, 'pagetype'=>'course-view')); + $totalcount = $DB->count_records('block_instance_old', array('blockid'=>$blockid)); + $count = $DB->count_records('block_instance_old', array('blockid'=>$blockid, 'pagetype'=>'course-view')); if ($count>0) { $blocklist = "wwwroot}/course/search.php?blocklist=$blockid&sesskey=".sesskey()."\" "; diff --git a/admin/replace.php b/admin/replace.php index bf54affd65..2ee8f6f6e9 100644 --- a/admin/replace.php +++ b/admin/replace.php @@ -43,7 +43,7 @@ print_simple_box_end(); /// Try to replace some well-known serialised contents (html blocks) notify('Replacing in html blocks...'); $sql = "SELECT bi.* - FROM {block_instance} bi + FROM {block_instance_old} bi JOIN {block} b ON b.id = bi.blockid WHERE b.name = 'html'"; if ($instances = $DB->get_records_sql($sql)) { diff --git a/admin/roles/tabs.php b/admin/roles/tabs.php index e292131190..bedf540101 100755 --- a/admin/roles/tabs.php +++ b/admin/roles/tabs.php @@ -118,7 +118,7 @@ if ($currenttab != 'update') { break; case CONTEXT_BLOCK: - if ($blockinstance = $DB->get_record('block_instance', array('id'=>$context->instanceid))) { + if ($blockinstance = $DB->get_record('block_instance_old', array('oldid'=>$context->instanceid))) { if ($block = $DB->get_record('block', array('id'=>$blockinstance->blockid))) { $blockname = print_context_name($context); diff --git a/admin/settings.php b/admin/settings.php index da6ca837c3..ae239ed427 100644 --- a/admin/settings.php +++ b/admin/settings.php @@ -3,7 +3,6 @@ require_once('../config.php'); require_once($CFG->libdir.'/adminlib.php'); require_once($CFG->libdir.'/blocklib.php'); -require_once($CFG->dirroot.'/'.$CFG->admin.'/pagelib.php'); $section = required_param('section', PARAM_SAFEDIR); $return = optional_param('return','', PARAM_ALPHA); diff --git a/backup/backuplib.php b/backup/backuplib.php index d11e509600..349d894c4d 100644 --- a/backup/backuplib.php +++ b/backup/backuplib.php @@ -2826,13 +2826,13 @@ // add all roles assigned at block context if ($courseblocks = $DB->get_records_sql("SELECT * - FROM {block_instance} + FROM {block_instance_old} WHERE pagetype = '".PAGE_COURSE_VIEW."' AND pageid = ?", array($preferences->backup_course))) { foreach ($courseblocks as $courseblock) { - $context = get_context_instance(CONTEXT_BLOCK, $courseblock->id); + $context = get_context_instance(CONTEXT_BLOCK, $courseblock->oldid); $contexts[$context->id] = $context; } } diff --git a/blocks/moodleblock.class.php b/blocks/moodleblock.class.php index cecf71fdc0..906496103d 100644 --- a/blocks/moodleblock.class.php +++ b/blocks/moodleblock.class.php @@ -728,11 +728,13 @@ class block_base { $data = $data; $this->config = $data; - $table = 'block_instance'; + $table = 'block_instance_old'; + $field = 'oldid'; if (!empty($pinned)) { - $table = 'block_pinned'; + $table = 'block_pinned_old'; + $field = 'id'; } - return $DB->set_field($table, 'configdata', base64_encode(serialize($data)), array('id'=>$this->instance->id)); + return $DB->set_field($table, 'configdata', base64_encode(serialize($data)), array($field => $this->instance->id)); } /** @@ -743,11 +745,13 @@ class block_base { function instance_config_commit($pinned=false) { global $DB; - $table = 'block_instance'; + $table = 'block_instance_old'; + $field = 'oldid'; if (!empty($pinned)) { - $table = 'block_pinned'; + $table = 'block_pinned_old'; + $field = 'id'; } - return $DB->set_field($table, 'configdata', base64_encode(serialize($this->config)), array('id'=>$this->instance->id)); + return $DB->set_field($table, 'configdata', base64_encode(serialize($this->config)), array($field => $this->instance->id)); } /** diff --git a/blocks/section_links/block_section_links.php b/blocks/section_links/block_section_links.php index 7201d946c5..7117ad925f 100644 --- a/blocks/section_links/block_section_links.php +++ b/blocks/section_links/block_section_links.php @@ -24,7 +24,7 @@ class block_section_links extends block_base { } function applicable_formats() { - return (array('course-view-weeks' => true, 'course-view-topics' => true, 'course-edit-weeks' => true, 'course-edit-topics' => true)); + return (array('course-view-weeks' => true, 'course-view-topics' => true)); } function get_content() { diff --git a/blog/lib.php b/blog/lib.php index 8f0fbc1c5e..d23cd343cf 100755 --- a/blog/lib.php +++ b/blog/lib.php @@ -39,12 +39,12 @@ $newblock->position = 'r'; $newblock->weight = 0; $newblock->visible = 1; - $DB->insert_record('block_instance', $newblock); + $DB->insert_record('block_instance_old', $newblock); // add blog_tags menu $newblock -> blockid = $tagsblock->id; $newblock -> weight = 1; - $DB->insert_record('block_instance', $newblock); + $DB->insert_record('block_instance_old', $newblock); // finally we set the page size pref set_user_preference('blogpagesize', 10); diff --git a/course/search.php b/course/search.php index a15762c6a6..99e149a890 100644 --- a/course/search.php +++ b/course/search.php @@ -117,7 +117,7 @@ // get list of courses containing blocks if required if (!empty($blocklist) and confirm_sesskey()) { $blockid = $blocklist; - if (!$blocks = $DB->get_records('block_instance', array('blockid'=>$blockid))) { + if (!$blocks = $DB->get_records('block_instance_old', array('blockid'=>$blockid))) { print_error('blockcannotread', '', '', $blockid); } diff --git a/course/view.php b/course/view.php index d68aff4508..274a6eecc1 100644 --- a/course/view.php +++ b/course/view.php @@ -93,6 +93,7 @@ $PAGE = page_create_object(PAGE_COURSE_VIEW, $course->id); $PAGE->set_url('course/view.php', array('id' => $course->id)); + $PAGE->set_pagetype('course-view-' . $course->format); $PAGE->set_other_editing_capability('moodle/course:manageactivities'); $pageblocks = blocks_setup($PAGE, BLOCKS_PINNED_BOTH); diff --git a/lib/accesslib.php b/lib/accesslib.php index 2ded5fb2b6..0e5393f630 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -2094,14 +2094,14 @@ function create_context($contextlevel, $instanceid) { // Only non-pinned & course-page based $sql = "SELECT ctx.path, ctx.depth FROM {context} ctx - JOIN {block_instance} bi + JOIN {block_instance_old} bi ON (bi.pageid=ctx.instanceid AND ctx.contextlevel=".CONTEXT_COURSE.") - WHERE bi.id=? AND bi.pagetype='course-view'"; + WHERE bi.oldid=? AND bi.pagetype='course-view'"; $params = array($instanceid); if ($p = $DB->get_record_sql($sql, $params)) { $basepath = $p->path; $basedepth = $p->depth; - } else if ($bi = $DB->get_record('block_instance', array('id'=>$instanceid))) { + } else if ($bi = $DB->get_record('block_instance_old', array('oldid'=>$instanceid))) { if ($bi->pagetype != 'course-view') { // ok - not a course block } else if ($parent = get_context_instance(CONTEXT_COURSE, $bi->pageid)) { @@ -2295,8 +2295,8 @@ function create_contexts($contextlevel=null, $buildpaths=true) { if (empty($contextlevel) or $contextlevel == CONTEXT_BLOCK) { $sql = "INSERT INTO {context} (contextlevel, instanceid) - SELECT ".CONTEXT_BLOCK.", bi.id - FROM {block_instance} bi + SELECT ".CONTEXT_BLOCK.", bi.oldid + FROM {block_instance_old} bi WHERE NOT EXISTS (SELECT 'x' FROM {context} cx WHERE bi.id = cx.instanceid AND cx.contextlevel=".CONTEXT_BLOCK.")"; @@ -2359,8 +2359,8 @@ function cleanup_contexts() { SELECT c.contextlevel, c.instanceid FROM {context} c - LEFT OUTER JOIN {block_instance} t - ON c.instanceid = t.id + LEFT OUTER JOIN {block_instance_old} t + ON c.instanceid = t.oldid WHERE t.id IS NULL AND c.contextlevel = ".CONTEXT_BLOCK." "; if ($rs = $DB->get_recordset_sql($sql)) { @@ -2408,8 +2408,8 @@ function preload_course_contexts($courseid) { UNION ALL SELECT x.instanceid, x.id, x.contextlevel, x.path, x.depth - FROM {block_instance} bi - JOIN {context} x ON x.instanceid=bi.id + FROM {block_instance_old} bi + JOIN {context} x ON x.instanceid=bi.oldid WHERE bi.pageid=? AND bi.pagetype='course-view' AND x.contextlevel=".CONTEXT_BLOCK." @@ -3427,7 +3427,7 @@ function print_context_name($context, $withprefix = true, $short = false) { break; case CONTEXT_BLOCK: // not necessarily 1 to 1 to course - if ($blockinstance = $DB->get_record('block_instance', array('id'=>$context->instanceid))) { + if ($blockinstance = $DB->get_record('block_instance_old', array('oldid'=>$context->instanceid))) { if ($block = $DB->get_record('block', array('id'=>$blockinstance->blockid))) { global $CFG; require_once("$CFG->dirroot/blocks/moodleblock.class.php"); @@ -3608,7 +3608,7 @@ function fetch_context_capabilities($context) { break; case CONTEXT_BLOCK: // block caps - $cb = $DB->get_record('block_instance', array('id'=>$context->instanceid)); + $cb = $DB->get_record('block_instance_old', array('oldid'=>$context->instanceid)); $block = $DB->get_record('block', array('id'=>$cb->blockid)); $extra = ""; @@ -3755,7 +3755,7 @@ function get_sorted_contexts($select, $params = array()) { LEFT JOIN {course_categories} cat ON ctx.contextlevel = 40 AND cat.id = ctx.instanceid LEFT JOIN {course} c ON ctx.contextlevel = 50 AND c.id = ctx.instanceid LEFT JOIN {course_modules} cm ON ctx.contextlevel = 70 AND cm.id = ctx.instanceid - LEFT JOIN {block_instance} bi ON ctx.contextlevel = 80 AND bi.id = ctx.instanceid + LEFT JOIN {block_instance_old} bi ON ctx.contextlevel = 80 AND bi.oldid = ctx.instanceid $select ORDER BY ctx.contextlevel, bi.position, COALESCE(cat.sortorder, c.sortorder, cm.section, bi.weight), u.lastname, u.firstname, cm.id ", $params); @@ -5825,7 +5825,7 @@ function build_context_path($force=false) { $sql = "INSERT INTO {context_temp} (id, path, depth) SELECT ctx.id, ".$DB->sql_concat('pctx.path', "'/'", 'ctx.id').", pctx.depth+1 FROM {context} ctx - JOIN {block_instance} bi ON ctx.instanceid = bi.id + JOIN {block_instance_old} bi ON ctx.instanceid = bi.oldid JOIN {context} pctx ON bi.pageid=pctx.instanceid WHERE ctx.contextlevel=".CONTEXT_BLOCK." AND pctx.contextlevel=".CONTEXT_COURSE." @@ -5844,8 +5844,8 @@ function build_context_path($force=false) { SET depth=2, path=".$DB->sql_concat("'$base/'", 'id')." WHERE contextlevel=".CONTEXT_BLOCK." AND EXISTS (SELECT 'x' - FROM {block_instance} bi - WHERE bi.id = {context}.instanceid + FROM {block_instance_old} bi + WHERE bi.oldid = {context}.instanceid AND bi.pagetype!='course-view') $emptyclause "; $DB->execute($sql); diff --git a/lib/blocklib.php b/lib/blocklib.php index 282e67092c..78234b953e 100644 --- a/lib/blocklib.php +++ b/lib/blocklib.php @@ -164,19 +164,19 @@ function blocks_delete_instance($instance,$pinned=false) { } if (!empty($pinned)) { - $DB->delete_records('block_pinned', array('id'=>$instance->id)); + $DB->delete_records('block_pinned_old', array('id'=>$instance->id)); // And now, decrement the weight of all blocks after this one - $sql = "UPDATE {block_pinned} + $sql = "UPDATE {block_pinned_old} SET weight = weight - 1 WHERE pagetype = ? AND position = ? AND weight > ?"; $params = array($instance->pagetype, $instance->position, $instance->weight); $DB->execute($sql, $params); } else { // Now kill the db record; - $DB->delete_records('block_instance', array('id'=>$instance->id)); + $DB->delete_records('block_instance_old', array('oldid'=>$instance->id)); delete_context(CONTEXT_BLOCK, $instance->id); // And now, decrement the weight of all blocks after this one - $sql = "UPDATE {block_instance} + $sql = "UPDATE {block_instance_old} SET weight = weight - 1 WHERE pagetype = ? AND pageid = ? AND position = ? AND weight > ?"; @@ -514,9 +514,9 @@ function blocks_execute_action($page, &$pageblocks, $blockaction, $instanceorid, } $instance->visible = ($instance->visible) ? 0 : 1; if (!empty($pinned)) { - $DB->update_record('block_pinned', $instance); + $DB->update_record('block_pinned_old', $instance); } else { - $DB->update_record('block_instance', $instance); + $DB->update_record('block_instance_old', $instance); } break; case 'delete': @@ -549,16 +549,16 @@ function blocks_execute_action($page, &$pageblocks, $blockaction, $instanceorid, if(!empty($other)) { ++$other->weight; if (!empty($pinned)) { - $DB->update_record('block_pinned', $other); + $DB->update_record('block_pinned_old', $other); } else { - $DB->update_record('block_instance', $other); + $DB->update_record('block_instance_old', $other); } } --$instance->weight; if (!empty($pinned)) { - $DB->update_record('block_pinned', $instance); + $DB->update_record('block_pinned_old', $instance); } else { - $DB->update_record('block_instance', $instance); + $DB->update_record('block_instance_old', $instance); } } break; @@ -586,16 +586,16 @@ function blocks_execute_action($page, &$pageblocks, $blockaction, $instanceorid, if(!empty($other)) { --$other->weight; if (!empty($pinned)) { - $DB->update_record('block_pinned', $other); + $DB->update_record('block_pinned_old', $other); } else { - $DB->update_record('block_instance', $other); + $DB->update_record('block_instance_old', $other); } } ++$instance->weight; if (!empty($pinned)) { - $DB->update_record('block_pinned', $instance); + $DB->update_record('block_pinned_old', $instance); } else { - $DB->update_record('block_instance', $instance); + $DB->update_record('block_instance_old', $instance); } } break; @@ -643,13 +643,13 @@ function blocks_execute_action($page, &$pageblocks, $blockaction, $instanceorid, $newpos = $page->blocks->get_default_position(); if (!empty($pinned)) { $sql = "SELECT 1, MAX(weight) + 1 AS nextfree - FROM {block_pinned} + FROM {block_pinned_old} WHERE pagetype = ? AND position = ?"; $params = array($page->pagetype, $newpos); } else { $sql = "SELECT 1, MAX(weight) + 1 AS nextfree - FROM {block_instance} + FROM {block_instance_old} WHERE pageid = ? AND pagetype = ? AND position = ?"; $params = array($page->get_id(), $page->pagetype, $newpos); } @@ -666,9 +666,9 @@ function blocks_execute_action($page, &$pageblocks, $blockaction, $instanceorid, $newinstance->visible = 1; $newinstance->configdata = ''; if (!empty($pinned)) { - $newinstance->id = $DB->insert_record('block_pinned', $newinstance); + $newinstance->id = $DB->insert_record('block_pinned_old', $newinstance); } else { - $newinstance->id = $DB->insert_record('block_instance', $newinstance); + $newinstance->id = $DB->insert_record('block_instance_old', $newinstance); } // If the new instance was created, allow it to do additional setup @@ -719,13 +719,13 @@ function blocks_execute_repositioning(&$instance, $newpos, $newweight, $pinned=f // Close the weight gap we 'll leave behind if (!empty($pinned)) { - $sql = "UPDATE {block_instance} + $sql = "UPDATE {block_instance_old} SET weight = weight - 1 WHERE pagetype = ? AND position = ? AND weight > ?"; $params = array($instance->pagetype, $instance->position, $instance->weight); } else { - $sql = "UPDATE {block_instance} + $sql = "UPDATE {block_instance_old} SET weight = weight - 1 WHERE pagetype = ? AND pageid = ? AND position = ? AND weight > ?"; @@ -737,9 +737,9 @@ function blocks_execute_repositioning(&$instance, $newpos, $newweight, $pinned=f $instance->weight = $newweight; if (!empty($pinned)) { - $DB->update_record('block_pinned', $instance); + $DB->update_record('block_pinned_old', $instance); } else { - $DB->update_record('block_instance', $instance); + $DB->update_record('block_instance_old', $instance); } } @@ -773,12 +773,12 @@ function blocks_move_block($page, &$instance, $destpos, $destweight=NULL, $pinne // First we close the gap that will be left behind when we take out the // block from it's current column. if ($pinned) { - $closegapsql = "UPDATE {block_instance} + $closegapsql = "UPDATE {block_instance_old} SET weight = weight - 1 WHERE weight > ? AND position = ? AND pagetype = ?"; $params = array($instance->weight, $instance->position, $instance->pagetype); } else { - $closegapsql = "UPDATE {block_instance} + $closegapsql = "UPDATE {block_instance_old} SET weight = weight - 1 WHERE weight > ? AND position = ? AND pagetype = ? AND pageid = ?"; @@ -790,12 +790,12 @@ function blocks_move_block($page, &$instance, $destpos, $destweight=NULL, $pinne // Now let's make space for the block being moved. if ($pinned) { - $opengapsql = "UPDATE {block_instance} + $opengapsql = "UPDATE {block_instance_old} SET weight = weight + 1 WHERE weight >= ? AND position = ? AND pagetype = ?"; $params = array($destweight, $destpos, $instance->pagetype); } else { - $opengapsql = "UPDATE {block_instance} + $opengapsql = "UPDATE {block_instance_old} SET weight = weight + 1 WHERE weight >= ? AND position = ? AND pagetype = ? AND pageid = ?"; @@ -810,9 +810,9 @@ function blocks_move_block($page, &$instance, $destpos, $destweight=NULL, $pinne $instance->weight = $destweight; if ($pinned) { - $table = 'block_pinned'; + $table = 'block_pinned_old'; } else { - $table = 'block_instance'; + $table = 'block_instance_old'; } return $DB->update_record($table, $instance); } @@ -834,7 +834,7 @@ function blocks_get_pinned($page) { $select .= " AND visible = 1"; } - $blocks = $DB->get_records_select('block_pinned', $select, $params, 'position, weight'); + $blocks = $DB->get_records_select('block_pinned_old', $select, $params, 'position, weight'); $positions = $page->blocks->get_positions(); $arr = array(); @@ -895,7 +895,7 @@ function blocks_get_by_page_pinned($page) { function blocks_get_by_page($page) { global $DB; - $blocks = $DB->get_records_select('block_instance', "pageid = ? AND ? LIKE (" . $DB->sql_concat('pagetype', "'%'") . ")", + $blocks = $DB->get_records_select('block_instance_old', "pageid = ? AND ? LIKE (" . $DB->sql_concat('pagetype', "'%'") . ")", array($page->get_id(), $page->pagetype), 'position, weight'); $positions = $page->blocks->get_positions(); @@ -954,12 +954,12 @@ function blocks_print_adminblock(&$page, &$pageblocks) { */ function blocks_delete_all_on_page($pagetype, $pageid) { global $DB; - if ($instances = $DB->get_records('block_instance', array('pageid' => $pageid, 'pagetype' => $pagetype))) { + if ($instances = $DB->get_records('block_instance_old', array('pageid' => $pageid, 'pagetype' => $pagetype))) { foreach ($instances as $instance) { delete_context(CONTEXT_BLOCK, $instance->id); // Ingore any failures here. } } - return $DB->delete_records('block_instance', array('pageid' => $pageid, 'pagetype' => $pagetype)); + return $DB->delete_records('block_instance_old', array('pageid' => $pageid, 'pagetype' => $pagetype)); } // Dispite what this function is called, it seems to be mostly used to populate @@ -1017,7 +1017,7 @@ function blocks_repopulate_page($page) { if(!empty($newinstance->blockid)) { // Only add block if it was recognized - $DB->insert_record('block_instance', $newinstance); + $DB->insert_record('block_instance_old', $newinstance); ++$weight; } } diff --git a/lib/db/install.xml b/lib/db/install.xml index ad4ea3567a..0c12ced41c 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -1,5 +1,5 @@ - @@ -2156,7 +2156,7 @@ - +
@@ -2169,44 +2169,49 @@ + + +
- +
- - - - - - - + + + + + + + + + - - + + - +
- +
- - - - - - - - + + + + + + + + - - + + + - - +
-
+ \ No newline at end of file diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index f091be8ef9..a6cb922122 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -1710,6 +1710,396 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL"); upgrade_main_savepoint($result, 2009042800); } + if ($result && $oldversion < 2009042801) { + + /// Define table block_instance to be renamed to block_instance_old + $table = new xmldb_table('block_instance'); + + /// Launch rename table for block_instance + $dbman->rename_table($table, 'block_instances'); + + /// Main savepoint reached + upgrade_main_savepoint($result, 2009042801); + } + + if ($result && $oldversion < 2009042802) { + + /// Define table block_instance to be renamed to block_instance_old + $table = new xmldb_table('block_pinned'); + + /// Launch rename table for block_instance + $dbman->rename_table($table, 'block_pinned_old'); + + /// Main savepoint reached + upgrade_main_savepoint($result, 2009042802); + } + + if ($result && $oldversion < 2009042803) { + + /// Define table block_instance_old to be created + $table = new xmldb_table('block_instance_old'); + + /// Adding fields to table block_instance_old + $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); + $table->add_field('oldid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); + $table->add_field('blockid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); + $table->add_field('pageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); + $table->add_field('pagetype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, null); + $table->add_field('region', XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null, null, null); + $table->add_field('weight', XMLDB_TYPE_INTEGER, '3', null, XMLDB_NOTNULL, null, null, null, '0'); + $table->add_field('visible', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, null, '0'); + $table->add_field('configdata', XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null); + + /// Adding keys to table block_instance_old + $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); + $table->add_key('blockid', XMLDB_KEY_FOREIGN, array('blockid'), 'block', array('id')); + + /// Adding indexes to table block_instance_old + $table->add_index('pageid', XMLDB_INDEX_NOTUNIQUE, array('pageid')); + $table->add_index('pagetype', XMLDB_INDEX_NOTUNIQUE, array('pagetype')); + + /// Conditionally launch create table for block_instance_old + if (!$dbman->table_exists($table)) { + $dbman->create_table($table); + } + + /// Main savepoint reached + upgrade_main_savepoint($result, 2009042803); + } + + if ($result && $oldversion < 2009042804) { + /// Copy current blocks data from block_instances to block_instance_old + $DB->execute('INSERT INTO {block_instance_old} (oldid, blockid, pageid, pagetype, position, weight, visible, configdata) + SELECT id, blockid, pageid, pagetype, position, weight, visible, configdata FROM {block_instances} ORDER BY id'); + + upgrade_main_savepoint($result, 2009042804); + } + + if ($result && $oldversion < 2009042805) { + + /// Define field multiple to be dropped from block + $table = new xmldb_table('block'); + $field = new xmldb_field('multiple'); + + /// Conditionally launch drop field multiple + if ($dbman->field_exists($table, $field)) { + $dbman->drop_field($table, $field); + } + + /// Main savepoint reached + upgrade_main_savepoint($result, 2009042805); + } + + if ($result && $oldversion < 2009042806) { + $table = new xmldb_table('block_instances'); + + /// Rename field weight on table block_instances to defaultweight + $field = new xmldb_field('weight', XMLDB_TYPE_INTEGER, '3', null, XMLDB_NOTNULL, null, null, null, '0', 'position'); + $dbman->rename_field($table, $field, 'defaultweight'); + + /// Rename field position on table block_instances to defaultregion + $field = new xmldb_field('position', XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null, null, null, 'pagetype'); + $dbman->rename_field($table, $field, 'defaultregion'); + + /// Main savepoint reached + upgrade_main_savepoint($result, 2009042806); + } + + if ($result && $oldversion < 2009042807) { + + /// Changing precision of field defaultregion on table block_instances to (16) + $table = new xmldb_table('block_instances'); + $field = new xmldb_field('defaultregion', XMLDB_TYPE_CHAR, '16', null, XMLDB_NOTNULL, null, null, null, null, 'subpagepattern'); + + /// Launch change of precision for field defaultregion + $dbman->change_field_precision($table, $field); + + /// Main savepoint reached + upgrade_main_savepoint($result, 2009042807); + } + + if ($result && $oldversion < 2009042808) { + /// Change regions to the new notation + $DB->set_field('block_instances', 'defaultregion', 'side-pre', array('defaultregion' => 'l')); + $DB->set_field('block_instances', 'defaultregion', 'side-post', array('defaultregion' => 'r')); + $DB->set_field('block_instances', 'defaultregion', 'course-view-top', array('defaultregion' => 'c')); + // This third one is a custom value from contrib/patches/center_blocks_position_patch and the + // flex page course format. Hopefully this new value is an adequate alternative. + + /// Main savepoint reached + upgrade_main_savepoint($result, 2009042808); + } + + if ($result && $oldversion < 2009042809) { + + /// Define key blockname (unique) to be added to block + $table = new xmldb_table('block'); + $key = new xmldb_key('blockname', XMLDB_KEY_UNIQUE, array('name')); + + /// Launch add key blockname + $dbman->add_key($table, $key); + + /// Main savepoint reached + upgrade_main_savepoint($result, 2009042809); + } + + if ($result && $oldversion < 2009042810) { + $table = new xmldb_table('block_instances'); + + /// Define field blockname to be added to block_instances + $field = new xmldb_field('blockname', XMLDB_TYPE_CHAR, '40', null, null, null, null, null, null, 'blockid'); + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + /// Define field contextid to be added to block_instances + $field = new xmldb_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'blockname'); + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + /// Define field showinsubcontexts to be added to block_instances + $field = new xmldb_field('showinsubcontexts', XMLDB_TYPE_INTEGER, '4', null, null, null, null, null, null, 'contextid'); + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + /// Define field subpagepattern to be added to block_instances + $field = new xmldb_field('subpagepattern', XMLDB_TYPE_CHAR, '16', null, null, null, null, null, null, 'pagetype'); + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + /// Main savepoint reached + upgrade_main_savepoint($result, 2009042810); + } + + if ($result && $oldversion < 2009042811) { + $table = new xmldb_table('block_instances'); + + /// Fill in blockname from blockid + $DB->execute("UPDATE {block_instances} SET blockname = (SELECT name FROM {block} WHERE id = blockid)"); + + /// Set showinsubcontexts = 0 for all rows. + $DB->execute("UPDATE {block_instances} SET showinsubcontexts = 0"); + + /// Main savepoint reached + upgrade_main_savepoint($result, 2009042811); + } + + if ($result && $oldversion < 2009042812) { + + /// Rename field pagetype on table block_instances to pagetypepattern + $table = new xmldb_table('block_instances'); + $field = new xmldb_field('pagetype', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, null, null, 'pageid'); + + /// Launch rename field pagetype + $dbman->rename_field($table, $field, 'pagetypepattern'); + + /// Main savepoint reached + upgrade_main_savepoint($result, 2009042812); + } + + if ($result && $oldversion < 2009042813) { + /// fill in contextid and subpage, and update pagetypepattern from pagetype and pageid + + /// site-index + $frontpagecontext = get_context_instance(CONTEXT_COURSE, SITEID); + $DB->execute("UPDATE {block_instances} SET (contextid, pagetypepattern, subpagepattern) = + (" . $frontpagecontext->id . ", 'site-index', NULL) WHERE pagetypepattern = 'site-index'"); + + /// course-view + $DB->execute("UPDATE {block_instances} SET (contextid, pagetypepattern, subpagepattern) = + (( + SELECT {context}.id + FROM {context} + JOIN {course} ON instanceid = {course}.id AND contextlevel = " . CONTEXT_COURSE . " + WHERE {course}.id = pageid + ), 'course-view-*', NULL) WHERE pagetypepattern = 'course-view'"); + + /// admin + $syscontext = get_context_instance(CONTEXT_SYSTEM); + $DB->execute("UPDATE {block_instances} SET (contextid, pagetypepattern, subpagepattern) = + (" . $syscontext->id . ", 'admin-*', NULL) WHERE pagetypepattern = 'admin'"); + + /// my-index + $DB->execute("UPDATE {block_instances} SET (contextid, pagetypepattern, subpagepattern) = + (( + SELECT {context}.id + FROM {context} + JOIN {user} ON instanceid = {user}.id AND contextlevel = " . CONTEXT_USER . " + WHERE {user}.id = pageid + ), 'my-index', NULL) WHERE pagetypepattern = 'my-index'"); + + /// tag-index + $DB->execute("UPDATE {block_instances} SET (contextid, pagetypepattern, subpagepattern) = + (" . $syscontext->id . ", 'tag-index', pageid) WHERE pagetypepattern = 'tag-index'"); + + /// blog-view + $DB->execute("UPDATE {block_instances} SET (contextid, pagetypepattern, subpagepattern) = + (( + SELECT {context}.id + FROM {context} + JOIN {user} ON instanceid = {user}.id AND contextlevel = " . CONTEXT_USER . " + WHERE {user}.id = pageid + ), 'blog-index', NULL) WHERE pagetypepattern = 'blog-view'"); + + /// mod-xxx-view + $moduleswithblocks = array('chat', 'data', 'lesson', 'quiz', 'dimdim', 'game', 'wiki', 'oublog'); + foreach ($moduleswithblocks as $modname) { + if (!$dbman->table_exists($modname)) { + continue; + } + $DB->execute("UPDATE {block_instances} SET (contextid, pagetypepattern, subpagepattern) = + (( + SELECT {context}.id + FROM {context} + JOIN {course_modules} ON instanceid = {course_modules}.id AND contextlevel = " . CONTEXT_MODULE . " + JOIN {modules} ON {modules}.id = {course_modules}.module AND {modules}.name = '$modname' + JOIN {{$modname}} ON {course_modules}.instance = {{$modname}}.id + WHERE {{$modname}}.id = pageid + ), 'blog-index', NULL) WHERE pagetypepattern = 'blog-view'"); + } + + /// Main savepoint reached + upgrade_main_savepoint($result, 2009042813); + } + + if ($result && $oldversion < 2009042814) { + /// fill in any missing contextids with a dummy value, so we can add the not-null constraint. + $DB->execute("UPDATE {block_instances} SET contextid = -1 WHERE contextid IS NULL"); + + /// Main savepoint reached + upgrade_main_savepoint($result, 2009042814); + } + + if ($result && $oldversion < 2009042815) { + $table = new xmldb_table('block_instances'); + + /// Changing nullability of field blockname on table block_instances to not null + $field = new xmldb_field('blockname', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null, null, null, 'id'); + $dbman->change_field_notnull($table, $field); + + /// Changing nullability of field contextid on table block_instances to not null + $field = new xmldb_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null, 'blockname'); + $dbman->change_field_notnull($table, $field); + + /// Changing nullability of field showinsubcontexts on table block_instances to not null + $field = new xmldb_field('showinsubcontexts', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null, null, null, 'contextid'); + $dbman->change_field_notnull($table, $field); + + /// Main savepoint reached + upgrade_main_savepoint($result, 2009042815); + } + + if ($result && $oldversion < 2009042816) { + /// Add exiting sticky blocks. + $blocks = $DB->get_records('block'); + $syscontext = get_context_instance(CONTEXT_SYSTEM); + $newregions = array( + 'l' => 'side-pre', + 'r' => 'side-post', + 'c' => 'course-view-top', + ); + $stickyblocks = $DB->get_recordset('block_pinned_old'); + foreach ($stickyblocks as $stickyblock) { + $newblock = stdClass; + $newblock->blockname = $blocks[$stickyblock]->name; + $newblock->contextid = $syscontext->id; + $newblock->showinsubcontexts = 1; + switch ($stickyblock->pagetype) { + case 'course-view': + $newblock->pagetypepattern = 'course-view-*'; + break; + default: + $newblock->pagetypepattern = $stickyblock->pagetype; + } + $newblock->defaultregion = $newregions[$stickyblock->position]; + $newblock->defaultweight = $stickyblock->weight; + $newblock->configdata = $stickyblock->configdata; + $DB->insert_record('block_instances', $newblock); + } + + /// Main savepoint reached + upgrade_main_savepoint($result, 2009042816); + } + + if ($result && $oldversion < 2009042817) { + + /// Define table block_positions to be created + $table = new xmldb_table('block_positions'); + + /// Adding fields to table block_positions + $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); + $table->add_field('blockinstanceid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, null); + $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null); + $table->add_field('pagetype', XMLDB_TYPE_CHAR, '64', null, XMLDB_NOTNULL, null, null, null, null); + $table->add_field('subpage', XMLDB_TYPE_CHAR, '16', null, XMLDB_NOTNULL, null, null, null, null); + $table->add_field('visible', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null, null, '1'); + $table->add_field('region', XMLDB_TYPE_CHAR, '16', null, XMLDB_NOTNULL, null, null, null, null); + $table->add_field('weight', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, null); + + /// Adding keys to table block_positions + $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); + $table->add_key('blockinstanceid', XMLDB_KEY_FOREIGN, array('blockinstanceid'), 'block_instances', array('id')); + $table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id')); + + /// Adding indexes to table block_positions + $table->add_index('blockinstanceid-contextid-pagetype-subpage', XMLDB_INDEX_UNIQUE, array('blockinstanceid', 'contextid', 'pagetype', 'subpage')); + + /// Conditionally launch create table for block_positions + if (!$dbman->table_exists($table)) { + $dbman->create_table($table); + } + + /// Main savepoint reached + upgrade_main_savepoint($result, 2009042817); + } + + if ($result && $oldversion < 2009042818) { + /// And block instances with visible = 0, copy that information to block_positions + $DB->execute("INSERT INTO {block_positions} (blockinstanceid, contextid, pagetype, subpage, visible, region, weight) + SELECT id, contextid, + CASE WHEN pagetypepattern = 'course-view-*' THEN + (SELECT " . $DB->sql_concat("'course-view-'", 'format') . " + FROM {course} + JOIN {context} ON {course}.id = {context}.instanceid + WHERE {context}.id = contextid) + ELSE pagetypepattern END, + CASE WHEN subpagepattern IS NULL THEN '' + ELSE subpagepattern END, + 0, defaultregion, defaultweight + FROM {block_instances} WHERE visible = 0 AND pagetypepattern <> 'admin-*'"); + + /// Main savepoint reached + upgrade_main_savepoint($result, 2009042818); + } + + if ($result && $oldversion < 2009042819) { + $table = new xmldb_table('block_instances'); + + /// Define field blockid to be dropped from block_instances + $field = new xmldb_field('blockid'); + if ($dbman->field_exists($table, $field)) { + $dbman->drop_field($table, $field); + } + + /// Define field pageid to be dropped from block_instances + $field = new xmldb_field('pageid'); + if ($dbman->field_exists($table, $field)) { + $dbman->drop_field($table, $field); + } + + /// Define field visible to be dropped from block_instances + $field = new xmldb_field('visible'); + if ($dbman->field_exists($table, $field)) { + $dbman->drop_field($table, $field); + } + + /// Main savepoint reached + upgrade_main_savepoint($result, 2009042819); + } + if ($result && $oldversion < 2009043000) { unset_config('grade_report_showgroups'); upgrade_main_savepoint($result, 2009043000); diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 05bc958566..5e63ebc0ae 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -3603,12 +3603,12 @@ function remove_course_contents($courseid, $showfeedback=true) { /// Delete course blocks if ($blocks = $DB->get_records_sql("SELECT * - FROM {block_instance} + FROM {block_instance_old} WHERE pagetype = '".PAGE_COURSE_VIEW."' AND pageid = ?", array($course->id))) { - if ($DB->delete_records('block_instance', array('pagetype'=>PAGE_COURSE_VIEW, 'pageid'=>$course->id))) { + if ($DB->delete_records('block_instance_old', array('pagetype'=>PAGE_COURSE_VIEW, 'pageid'=>$course->id))) { if ($showfeedback) { - notify($strdeleted .' block_instance'); + notify($strdeleted .' block_instance_old'); } require_once($CFG->libdir.'/blocklib.php'); diff --git a/theme/standard/rtl.css b/theme/standard/rtl.css index a934bd476e..7aa38a1953 100755 --- a/theme/standard/rtl.css +++ b/theme/standard/rtl.css @@ -534,7 +534,7 @@ form.mform .fitemtitle { margin-left: 0px; } -#course-view .section td.right { +.course-view .section td.right { border-left-width: 1px; border-left-style: solid; border-right-width: 0px; diff --git a/theme/standard/styles_color.css b/theme/standard/styles_color.css index 20e7ee798d..311683dee5 100644 --- a/theme/standard/styles_color.css +++ b/theme/standard/styles_color.css @@ -653,55 +653,55 @@ table.minicalendar { border-color:#DDDDDD; } -#course-view .weeks .section, -#course-view .topics .section, -#course-view .section td { +.course-view .weeks .section, +.course-view .topics .section, +.course-view .section td { border-color:#DDDDDD; } /* .content should match the body background, sides are white. */ -#course-view .weeks .content , -#course-view .topics .content, -#course-view .weeks .section, -#course-view .topics .section { +.course-view .weeks .content , +.course-view .topics .content, +.course-view .weeks .section, +.course-view .topics .section { background: #FAFAFA; } -#course-view .section td.side { +.course-view .section td.side { background: #FFFFFF; } -#course-view .section .side { +.course-view .section .side { } -#course-view .section .left { +.course-view .section .left { } -#course-view .section .right { +.course-view .section .right { } -#course-view .weeks .current, -#course-view .topics .current, -#course-view .current td.side { +.course-view .weeks .current, +.course-view .topics .current, +.course-view .current td.side { background: #FFD991; } -#course-view .weeks .hidden, -#course-view .topics .hidden, -#course-view .hidden td.side { +.course-view .weeks .hidden, +.course-view .topics .hidden, +.course-view .hidden td.side { background: #DDDDDD; } -#course-view .section .spacer { +.course-view .section .spacer { } -#course-view .section .weekdates { +.course-view .section .weekdates { color: #777777; } -#course-view .weeks .weekdates , -#course-view .topics .weekdates { +.course-view .weeks .weekdates , +.course-view .topics .weekdates { color: #333333; } diff --git a/theme/standard/styles_fonts.css b/theme/standard/styles_fonts.css index e7eb85aa81..6bf707e70c 100644 --- a/theme/standard/styles_fonts.css +++ b/theme/standard/styles_fonts.css @@ -140,7 +140,7 @@ h4 { } #site-index .subscribelink, -#course-view .subscribelink { +.course-view .subscribelink { font-size: 0.8em; } @@ -487,26 +487,26 @@ table.minicalendar { /*** *** Course ***/ -#course-view .section { +.course-view .section { font-size:0.95em; line-height:1.2em; } -#course-view .section .activity { +.course-view .section .activity { padding:0.2em 0; } -#course-view .section .activity a { +.course-view .section .activity a { line-height:1em; } -#course-view .section .weekdates { +.course-view .section .weekdates { margin: 0; font-weight: normal; font-size: 1em; } -#course-view .section .left { +.course-view .section .left { font-weight:bold; } @@ -569,15 +569,15 @@ h2.headingblock { color: #666666; } -#course-view .availabilityinfo { +.course-view .availabilityinfo { font-size:0.85em; color:#aaa; } -#course-view .availabilityinfo strong { +.course-view .availabilityinfo strong { font-weight:normal; color:black; } -#course-view .dimmed_text img { +.course-view .dimmed_text img { opacity:0.3; filter: alpha(opacity='30'); } diff --git a/theme/standard/styles_ie6.css b/theme/standard/styles_ie6.css index 1d38d3f307..366d71fcdf 100755 --- a/theme/standard/styles_ie6.css +++ b/theme/standard/styles_ie6.css @@ -63,7 +63,7 @@ form.mform textarea { display:inline-block; padding-left:2px; } -#course-view li.activity { +.course-view li.activity { height:0; } #mod-quiz-review #middle-column { diff --git a/theme/standard/styles_layout.css b/theme/standard/styles_layout.css index 4e4a66b875..b8515af3a1 100644 --- a/theme/standard/styles_layout.css +++ b/theme/standard/styles_layout.css @@ -2061,11 +2061,11 @@ border-width:0px; text-align:center; } -#course-view .section td { +.course-view .section td { vertical-align:top; } -#course-view .section td.content { +.course-view .section td.content { padding:5px; border-style:solid; border-width:1px; @@ -2073,44 +2073,44 @@ border-width:0px; border-right:0px; } -#course-view .section td.side { +.course-view .section td.side { padding:5px; border-style:solid; border-width:1px; } -#course-view .section td.left { +.course-view .section td.left { border-right:0px; text-align:center; width: 1.5em; } -#course-view .section td.right { +.course-view .section td.right { border-left:0px; text-align:center; width: 1.5em; } -#course-view .current .side { +.course-view .current .side { } -#course-view .section .spacer { +.course-view .section .spacer { height:0.5em; } -#course-view .section .weekdates { +.course-view .section .weekdates { } -#course-view li.activity { +.course-view li.activity { margin-right:20px; /* Space allowed for completion icons if enabled */ position:relative; } -.dir-rtl#course-view li.activity { +.dir-rtl.course-view li.activity { margin-right:0px; margin-left:20px; } -#course-view li.activity form.togglecompletion, -#course-view li.activity span.autocompletion { +.course-view li.activity form.togglecompletion, +.course-view li.activity span.autocompletion { display:inline; position:absolute; right:-20px; @@ -2118,15 +2118,15 @@ border-width:0px; z-index:10; padding:0.2em 0; } -.dir-rtl#course-view li.activity form.togglecompletion, -.dir-rtl#course-view li.activity span.autocompletion { +.dir-rtl.course-view li.activity form.togglecompletion, +.dir-rtl.course-view li.activity span.autocompletion { right:auto; left:-20px; } -#course-view li.activity form.togglecompletion div { +.course-view li.activity form.togglecompletion div { display:inline; } -#course-view .completion-saved-display { +.course-view .completion-saved-display { position:absolute; top:0; left:0; border:1px solid black; @@ -2134,12 +2134,12 @@ border-width:0px; background:white; font-size:0.85em; } -#course-view form.togglecompletion img.iconhelp, -#course-view span.autocompletion img.iconhelp { +.course-view form.togglecompletion img.iconhelp, +.course-view span.autocompletion img.iconhelp { vertical-align:top; } -#course-view ul.section, +.course-view ul.section, #site-index ul.section { margin: 0; padding: 0; @@ -2158,13 +2158,13 @@ border-width:0px; margin-top: 8px; } -/*#course-view ul.section li.activity ul li, +/*.course-view ul.section li.activity ul li, #site-index ul.section li.activity ul li { list-style: disc; }*/ /*Accessibility: No-tables course format. */ -#course-view ul.weeks , #course-view ul.topics{ +.course-view ul.weeks , .course-view ul.topics{ margin: 0; padding: 0; list-style: none; @@ -2245,11 +2245,11 @@ border-width:0px; width:80px; } -body#course-view .unread { +body.course-view .unread { margin-left: 3em; } -body#course-view .sideblock.drag .header { +body.course-view .sideblock.drag .header { cursor: move; } @@ -2291,12 +2291,12 @@ body#course-user .section h2 { } #site-index .subscribelink, -#course-view .subscribelink { +.course-view .subscribelink { text-align:right; } body#site-index .headingblock, -body#course-view .headingblock { +body.course-view .headingblock { margin-bottom: 9px; }