Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / blocks / db / mysql.php
blob2c58e407377792c1500c65b02ddb86133aac4b66
1 <?PHP //$Id$
3 // THIS FILE IS DEPRECATED! PLEASE DO NOT MAKE CHANGES TO IT!
4 //
5 // IT IS USED ONLY FOR UPGRADES FROM BEFORE MOODLE 1.7, ALL
6 // LATER CHANGES SHOULD USE upgrade.php IN THIS DIRECTORY.
7 //
8 // This file is tailored to MySQL
10 function blocks_upgrade($oldversion=0) {
12 global $CFG;
14 $result = true;
16 if ($oldversion < 2004041000 && $result) {
17 $result = execute_sql("CREATE TABLE `{$CFG->prefix}blocks` (
18 `id` int(10) unsigned NOT NULL auto_increment,
19 `name` varchar(40) NOT NULL default '',
20 `version` int(10) NOT NULL default '0',
21 `cron` int(10) unsigned NOT NULL default '0',
22 `lastcron` int(10) unsigned NOT NULL default '0',
23 `visible` tinyint(1) NOT NULL default '1',
24 PRIMARY KEY (`id`)
26 COMMENT = 'To register and update all the available blocks'");
29 if ($oldversion < 2004101900 && $result) {
30 $result = execute_sql("CREATE TABLE `{$CFG->prefix}block` (
31 `id` int(10) unsigned NOT NULL auto_increment,
32 `name` varchar(40) NOT NULL default '',
33 `version` int(10) NOT NULL default '0',
34 `cron` int(10) unsigned NOT NULL default '0',
35 `lastcron` int(10) unsigned NOT NULL default '0',
36 `visible` tinyint(1) NOT NULL default '1',
37 `multiple` tinyint(1) NOT NULL default '0',
38 PRIMARY KEY (`id`)
40 COMMENT = 'To register and update all the available blocks'");
42 if(!$result) {
43 return false;
46 $records = get_records('blocks');
47 if(!empty($records)) {
48 foreach($records as $block) {
49 $block->multiple = 0;
50 insert_record('block', $block, false);
54 execute_sql("DROP TABLE `{$CFG->prefix}blocks`");
56 $result = execute_sql("CREATE TABLE `{$CFG->prefix}block_instance` (
57 `id` int(10) not null auto_increment,
58 `blockid` int(10) not null default '0',
59 `pageid` int(10) not null default '0',
60 `pagetype` varchar(12) not null default '',
61 `position` enum('l', 'r') not null default 'l',
62 `weight` tinyint(3) not null default '0',
63 `visible` tinyint(1) not null default '0',
64 `configdata` text not null default '',
66 PRIMARY KEY(`id`),
67 INDEX pageid(`pageid`)
68 )");
70 if(!$result) {
71 return false;
74 $records = get_records('course', '','','', 'id, shortname, blockinfo');
75 if(!empty($records)) {
76 foreach($records as $thiscourse) {
77 // The @ suppresses a notice emitted if there is no : in the string
78 @list($left, $right) = split(':', $thiscourse->blockinfo);
79 if(!empty($left)) {
80 $arr = explode(',', $left);
81 foreach($arr as $weight => $blk) {
82 $instance = new stdClass;
83 $instance->blockid = abs($blk);
84 $instance->pageid = $thiscourse->id;
85 $instance->pagetype = PAGE_COURSE_VIEW;
86 $instance->position = BLOCK_POS_LEFT;
87 $instance->weight = $weight;
88 $instance->visible = ($blk > 0) ? 1 : 0;
89 $instance->configdata = '';
90 insert_record('block_instance', $instance, false);
93 if(!empty($right)) {
94 $arr = explode(',', $right);
95 foreach($arr as $weight => $blk) {
96 $instance = new stdClass;
97 $instance->blockid = abs($blk);
98 $instance->pageid = $thiscourse->id;
99 $instance->pagetype = PAGE_COURSE_VIEW;
100 $instance->position = BLOCK_POS_RIGHT;
101 $instance->weight = $weight;
102 $instance->visible = ($blk > 0) ? 1 : 0;
103 $instance->configdata = '';
104 insert_record('block_instance', $instance, false);
110 execute_sql("ALTER TABLE `{$CFG->prefix}course` DROP COLUMN blockinfo");
113 if ($oldversion < 2004112900 && $result) {
114 $result = $result && table_column('block_instance', 'pagetype', 'pagetype', 'varchar', '20', '');
115 $result = $result && table_column('block_instance', 'position', 'position', 'varchar', '10', '');
118 if ($oldversion < 2004112900 && $result) {
119 execute_sql('UPDATE '.$CFG->prefix.'block_instance SET pagetype = \''.PAGE_COURSE_VIEW.'\' WHERE pagetype = \'\'');
122 if ($oldversion < 2005043000 && $result) {
123 $records = get_records('block');
124 if(!empty($records)) {
125 foreach($records as $block) {
126 if(!block_is_compatible($block->name)) {
127 $block->visible = 0;
128 update_record('block', $block);
129 notify('The '.$block->name.' block has been disabled because it is not compatible with Moodle 1.5 and needs to be updated by a programmer.');
135 if ($oldversion < 2005081600) {
136 $result = $result && modify_database('',"CREATE TABLE `prefix_block_pinned` (
137 `id` int(10) not null auto_increment,
138 `blockid` int(10) not null default '0',
139 `pagetype` varchar(20) not null default '',
140 `position` varchar(10) not null default '',
141 `weight` tinyint(3) not null default '0',
142 `visible` tinyint(1) not null default '0',
143 `configdata` text not null default '',
144 PRIMARY KEY(`id`)
145 ) TYPE=MyISAM;");
148 if ($oldversion < 2005090200) {
149 execute_sql("ALTER TABLE {$CFG->prefix}block_instance ADD INDEX pagetype (pagetype);",false); // do it silently, in case it's already there from 1.5
150 modify_database('','ALTER TABLE prefix_block_pinned ADD INDEX pagetype (pagetype);');
153 ////// DO NOT ADD NEW THINGS HERE!! USE upgrade.php and the lib/ddllib.php functions.
155 //Finally, return result
156 return $result;