]> git.mjollnir.org Git - moodle.git/commitdiff
blocklib: MDL-19010 upgrade database tables ready for now blocks system
authortjhunt <tjhunt>
Wed, 6 May 2009 09:12:03 +0000 (09:12 +0000)
committertjhunt <tjhunt>
Wed, 6 May 2009 09:12:03 +0000 (09:12 +0000)
20 files changed:
admin/blocks.php
admin/replace.php
admin/roles/tabs.php
admin/settings.php
backup/backuplib.php
blocks/moodleblock.class.php
blocks/section_links/block_section_links.php
blog/lib.php
course/search.php
course/view.php
lib/accesslib.php
lib/blocklib.php
lib/db/install.xml
lib/db/upgrade.php
lib/moodlelib.php
theme/standard/rtl.css
theme/standard/styles_color.css
theme/standard/styles_fonts.css
theme/standard/styles_ie6.css
theme/standard/styles_layout.css

index 99216f824959181537aa42e3995dea8c412a350e..eccd748a5cf5dd59d0d8f0412c97fc0bdc8cdd7a 100644 (file)
@@ -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);
         // 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 = "<a href=\"{$CFG->wwwroot}/course/search.php?blocklist=$blockid&amp;sesskey=".sesskey()."\" ";
index bf54affd65509b2fe1c75ea4ae3677760b6592eb..2ee8f6f6e9a769154a7e7f4dc4ddad92dceafbec 100644 (file)
@@ -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)) {
index e2921311909b783c779b9d7c580a3ef093a5f0f8..bedf540101071aa2552901fa6de2b580c8763488 100755 (executable)
@@ -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);
 
index da6ca837c3aee25c9e80459938dd46ce31185ab1..ae239ed427c88685c8748b178e4fb4964c4226c0 100644 (file)
@@ -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);
index d11e5096007c0cca99072f7b4475fa801accee0a..349d894c4d2b01b3654ef18fa4d8b7bc1ad2ea03 100644 (file)
 
         // 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;
             }
         }
index cecf71fdc09108b71608e4ea8b4a99129895a617..906496103d8ec2e32777f6dad95d67e704b7cc0e 100644 (file)
@@ -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));
     }
 
      /**
index 7201d946c5cf9f11304cb6d0e206bce6daa0f6ee..7117ad925fa1b7a6fa81c6922945470fd0a0ca30 100644 (file)
@@ -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() {
index 8f0fbc1c5ecf21ecdcd27b4b282ddf975f74dd3e..d23cd343cf535faf6b828ea0bb97d7798efdb0be 100755 (executable)
                 $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);
index a15762c6a6adfc9227ac2eeb4c27b4703fbd1a8f..99e149a89034a1c0bdb1fa26092388e9f311ee9c 100644 (file)
     // 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);
         }
 
index d68aff45080fca06b9f5f9f935aec37e855a04b0..274a6eecc111f058504b6f58d437192740935cee 100644 (file)
@@ -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);
 
index 2ded5fb2b6e367b448707c22d07754152cd88356..0e5393f6309e34eda2f9a0f3eedc7c204ef4e6e9 100755 (executable)
@@ -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);
index 282e67092c8c9833e6b200c725cfa3348d2bb8dc..78234b953ee497e0cfe26b46b6398f22da90c38e 100644 (file)
@@ -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;
             }
         }
index ad4ea3567aaed03a53fe46cbfe0f7a2f1d307c00..0c12ced41c0a0bb38a26ce72aa56dd4d7de728b4 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="lib/db" VERSION="20090403" COMMENT="XMLDB file for core Moodle tables"
+<XMLDB PATH="lib/db" VERSION="20090501" COMMENT="XMLDB file for core Moodle tables"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
 >
         <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">
+    <TABLE NAME="block" COMMENT="contains all installed blocks" PREVIOUS="backup_log" NEXT="block_instances">
       <FIELDS>
         <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="name"/>
         <FIELD NAME="name" TYPE="char" LENGTH="40" NOTNULL="true" SEQUENCE="false" PREVIOUS="id" NEXT="version"/>
       <KEYS>
         <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
       </KEYS>
+      <INDEXES>
+        <INDEX NAME="name" UNIQUE="true" FIELDS="name"/>
+      </INDEXES>
     </TABLE>
-    <TABLE NAME="block_pinned" COMMENT="to pin blocks" PREVIOUS="block" NEXT="block_instance">
+    <TABLE NAME="block_instances" COMMENT="This table stores block instances. The type of block this is is given by the block name column. The places this block instance appears is controlled by the contextid, showinsubcontexts, pagetypepattern and subpagepattern fields. Where the block appears on the page (by default) is controlled by the defaultposition and defaultweight columns. The block's own configuration is stored serialized in configdata." PREVIOUS="block" NEXT="block_positions">
       <FIELDS>
-        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="blockid"/>
-        <FIELD NAME="blockid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="pagetype"/>
-        <FIELD NAME="pagetype" TYPE="char" LENGTH="20" NOTNULL="true" SEQUENCE="false" PREVIOUS="blockid" NEXT="position"/>
-        <FIELD NAME="position" TYPE="char" LENGTH="10" NOTNULL="true" SEQUENCE="false" PREVIOUS="pagetype" NEXT="weight"/>
-        <FIELD NAME="weight" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="position" NEXT="visible"/>
-        <FIELD NAME="visible" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="weight" NEXT="configdata"/>
-        <FIELD NAME="configdata" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" PREVIOUS="visible"/>
+        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="blockname"/>
+        <FIELD NAME="blockname" TYPE="char" LENGTH="40" NOTNULL="true" SEQUENCE="false" COMMENT="The type of block this is. Foreign key, references block.name." PREVIOUS="id" NEXT="contextid"/>
+        <FIELD NAME="contextid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="The context within which this block appears. Foreign key, references context.id." PREVIOUS="blockname" NEXT="showinsubcontexts"/>
+        <FIELD NAME="showinsubcontexts" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="false" SEQUENCE="false" COMMENT="If 1, this block appears on all matching pages in subcontexts of this contextid, as well in contextid." PREVIOUS="contextid" NEXT="pagetypepattern"/>
+        <FIELD NAME="pagetypepattern" TYPE="char" LENGTH="64" NOTNULL="true" SEQUENCE="false" COMMENT="The types of page this block appears on. Either an exact page type like mod-quiz-view, or a pattern like mod-quiz-* or course-view-*. Note that course-view-* will match course-view." PREVIOUS="showinsubcontexts" NEXT="subpagepattern"/>
+        <FIELD NAME="subpagepattern" TYPE="char" LENGTH="16" NOTNULL="false" SEQUENCE="false" COMMENT="Further restrictions on where this block appears. In some places, e.g. during a quiz or lesson attempt, different pages have different subpage ids. If this field is not null, the block only appears on that particular subpage." PREVIOUS="pagetypepattern" NEXT="defaultregion"/>
+        <FIELD NAME="defaultregion" TYPE="char" LENGTH="16" NOTNULL="true" SEQUENCE="false" COMMENT="Which block region this block should appear in on each page, in the absence of a specific position in the block_positions table." PREVIOUS="subpagepattern" NEXT="defaultweight"/>
+        <FIELD NAME="defaultweight" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" SEQUENCE="false" COMMENT="Used to order the blocks within a block region. Again, may be overridden by the block_positions table for a specific page where this block appears." PREVIOUS="defaultregion" NEXT="configdata"/>
+        <FIELD NAME="configdata" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" COMMENT="A serialized blob of configuration data for this block instance." PREVIOUS="defaultweight"/>
       </FIELDS>
       <KEYS>
-        <KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="blockid"/>
-        <KEY NAME="blockid" TYPE="foreign" FIELDS="blockid" REFTABLE="block" REFFIELDS="id" PREVIOUS="primary"/>
+        <KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="contextid"/>
+        <KEY NAME="contextid" TYPE="foreign" FIELDS="contextid" REFTABLE="context" REFFIELDS="id" PREVIOUS="primary"/>
       </KEYS>
       <INDEXES>
-        <INDEX NAME="pagetype" UNIQUE="false" FIELDS="pagetype"/>
+        <INDEX NAME="contextid-showinsubcontexts-pagetypepattern-subpagepattern" UNIQUE="false" FIELDS="contextid, showinsubcontexts, pagetypepattern, subpagepattern"/>
       </INDEXES>
     </TABLE>
-    <TABLE NAME="block_instance" COMMENT="to store block instances in pages" PREVIOUS="block_pinned">
+    <TABLE NAME="block_positions" COMMENT="Stores the position of a sticky block_instance on a another page than the one where it was added." PREVIOUS="block_instances">
       <FIELDS>
-        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="blockid"/>
-        <FIELD NAME="blockid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="pageid"/>
-        <FIELD NAME="pageid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="blockid" NEXT="pagetype"/>
-        <FIELD NAME="pagetype" TYPE="char" LENGTH="20" NOTNULL="true" SEQUENCE="false" PREVIOUS="pageid" NEXT="position"/>
-        <FIELD NAME="position" TYPE="char" LENGTH="10" NOTNULL="true" SEQUENCE="false" PREVIOUS="pagetype" NEXT="weight"/>
-        <FIELD NAME="weight" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="position" NEXT="visible"/>
-        <FIELD NAME="visible" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="weight" NEXT="configdata"/>
-        <FIELD NAME="configdata" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" PREVIOUS="visible"/>
+        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="blockinstanceid"/>
+        <FIELD NAME="blockinstanceid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="The block_instance this position relates to." PREVIOUS="id" NEXT="contextid"/>
+        <FIELD NAME="contextid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="With pagetype and subpage, defines the page we are setting the position for." PREVIOUS="blockinstanceid" NEXT="pagetype"/>
+        <FIELD NAME="pagetype" TYPE="char" LENGTH="64" NOTNULL="true" SEQUENCE="false" COMMENT="With contextid and subpage, defines the page we are setting the position for." PREVIOUS="contextid" NEXT="subpage"/>
+        <FIELD NAME="subpage" TYPE="char" LENGTH="16" NOTNULL="true" SEQUENCE="false" COMMENT="With contextid and pagetype, defines the page we are setting the position for." PREVIOUS="pagetype" NEXT="visible"/>
+        <FIELD NAME="visible" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="false" SEQUENCE="false" COMMENT="Whether this block instance is visible on this page." PREVIOUS="subpage" NEXT="region"/>
+        <FIELD NAME="region" TYPE="char" LENGTH="16" NOTNULL="true" SEQUENCE="false" COMMENT="Which block region on this page this block should appear in." PREVIOUS="visible" NEXT="weight"/>
+        <FIELD NAME="weight" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" SEQUENCE="false" COMMENT="Used to order the blocks within a block region." PREVIOUS="region"/>
       </FIELDS>
       <KEYS>
-        <KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="blockid"/>
-        <KEY NAME="blockid" TYPE="foreign" FIELDS="blockid" REFTABLE="block" REFFIELDS="id" PREVIOUS="primary"/>
+        <KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="blockinstanceid"/>
+        <KEY NAME="blockinstanceid" TYPE="foreign" FIELDS="blockinstanceid" REFTABLE="block_instances" REFFIELDS="id" PREVIOUS="primary" NEXT="contextid"/>
+        <KEY NAME="contextid" TYPE="foreign" FIELDS="contextid" REFTABLE="context" REFFIELDS="id" PREVIOUS="blockinstanceid"/>
       </KEYS>
       <INDEXES>
-        <INDEX NAME="pageid" UNIQUE="false" FIELDS="pageid" NEXT="pagetype"/>
-        <INDEX NAME="pagetype" UNIQUE="false" FIELDS="pagetype" PREVIOUS="pageid"/>
+        <INDEX NAME="blockinstanceid-contextid-pagetype-subpage" UNIQUE="true" FIELDS="blockinstanceid, contextid, pagetype, subpage"/>
       </INDEXES>
     </TABLE>
   </TABLES>
-</XMLDB>
+</XMLDB>
\ No newline at end of file
index f091be8ef998d6ca34065388916637cc3cc6b15d..a6cb92212256a38439716278be66e8687a66f218 100644 (file)
@@ -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);
index 05bc958566a2668d532c9b8916058bfb3b5a46e8..5e63ebc0ae98b0325c3263c59f16d42a40594275 100644 (file)
@@ -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');
index a934bd476e36e5c8ad2cf2e146ce9fdb48250cfa..7aa38a1953488c642ed26ca6e77d5433330a0dab 100755 (executable)
@@ -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;
index 20e7ee798d8a34d941dd19cbfe5aeec48b7abeb2..311683dee515f399d4a36d11250ffaf402c71f7d 100644 (file)
@@ -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;
 }
 
index e7eb85aa818ddb944f0a1ccdcdc6bdd9e27bedf9..6bf707e70cc4026447f867b0a88f7fe24a06bf53 100644 (file)
@@ -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');
 }
index 1d38d3f307ba4de3d55e0b182168cc8f3c8042dc..366d71fcdf6bfb51aa3158184e356ea5a498f187 100755 (executable)
@@ -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 {
index 4e4a66b875e02c1eda05355f6218ce8e3b349333..b8515af3a1e63558b5d1644a0ed05e9914932a76 100644 (file)
@@ -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;
 }