3 // THIS FILE IS DEPRECATED! PLEASE DO NOT MAKE CHANGES TO IT!
5 // IT IS USED ONLY FOR UPGRADES FROM BEFORE MOODLE 1.7, ALL
6 // LATER CHANGES SHOULD USE upgrade.php IN THIS DIRECTORY.
8 // This file is tailored to PostgreSQL
10 function blocks_upgrade($oldversion=0) {
16 if ($oldversion < 2004041000 and $result) {
17 $result = execute_sql("
18 CREATE TABLE {$CFG->prefix}blocks
20 id SERIAL8 PRIMARY KEY,
21 name varchar(40) NOT NULL default '',
22 version INT8 NOT NULL default '0',
23 cron INT8 NOT NULL default '0',
24 lastcron INT8 NOT NULL default '0',
25 visible int NOT NULL default '1'
31 if ($oldversion < 2004101900 && $result) {
32 $result = execute_sql("CREATE TABLE {$CFG->prefix}block (
33 id SERIAL8 PRIMARY KEY,
34 name varchar(40) NOT NULL default '',
35 version INT8 NOT NULL default '0',
36 cron INT8 NOT NULL default '0',
37 lastcron INT8 NOT NULL default '0',
38 visible int NOT NULL default '1',
39 multiple int NOT NULL default '0'
47 $records = get_records('blocks');
48 if(!empty($records)) {
49 foreach($records as $block) {
51 insert_record('block', $block, false);
53 execute_sql("SELECT setval('{$CFG->prefix}block_id_seq', (SELECT MAX(id) FROM {$CFG->prefix}block), true)");
56 execute_sql("DROP TABLE {$CFG->prefix}blocks");
58 $result = execute_sql("CREATE TABLE {$CFG->prefix}block_instance (
59 id SERIAL8 PRIMARY KEY,
60 blockid INT8 not null default '0',
61 pageid INT8 not null default '0',
62 pagetype varchar(12) not null default '',
63 position char not null default 'l' check (position in ('l', 'r')) ,
64 weight int not null default '0',
65 visible int not null default '0',
66 configdata text not null default ''
73 $records = get_records('course', '','','', 'id, shortname, blockinfo');
74 if(!empty($records)) {
75 foreach($records as $thiscourse) {
76 // The @ suppresses a notice emitted if there is no : in the string
77 @list
($left, $right) = split(':', $thiscourse->blockinfo
);
79 $arr = explode(',', $left);
80 foreach($arr as $weight => $blk) {
81 $instance = new stdClass
;
82 $instance->blockid
= abs($blk);
83 $instance->pageid
= $thiscourse->id
;
84 $instance->pagetype
= PAGE_COURSE_VIEW
;
85 $instance->position
= BLOCK_POS_LEFT
;
86 $instance->weight
= $weight;
87 $instance->visible
= ($blk > 0) ?
1 : 0;
88 $instance->configdata
= '';
89 insert_record('block_instance', $instance, false);
93 $arr = explode(',', $right);
94 foreach($arr as $weight => $blk) {
95 $instance = new stdClass
;
96 $instance->blockid
= abs($blk);
97 $instance->pageid
= $thiscourse->id
;
98 $instance->pagetype
= PAGE_COURSE_VIEW
;
99 $instance->position
= BLOCK_POS_RIGHT
;
100 $instance->weight
= $weight;
101 $instance->visible
= ($blk > 0) ?
1 : 0;
102 $instance->configdata
= '';
103 insert_record('block_instance', $instance, false);
109 execute_sql("ALTER TABLE {$CFG->prefix}course DROP COLUMN blockinfo");
112 if ($oldversion < 2004112900 && $result) {
113 $result = $result && table_column('block_instance', 'pagetype', 'pagetype', 'varchar', '20', '');
114 $result = $result && table_column('block_instance', 'position', 'position', 'varchar', '10', '');
117 if ($oldversion < 2005043000 && $result) {
118 $records = get_records('block');
119 if(!empty($records)) {
120 foreach($records as $block) {
121 if(!block_is_compatible($block->name
)) {
123 update_record('block', $block);
124 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.');
130 if ($oldversion < 2005022401 && $result) { // Mass cleanup of bad upgrade scripts
131 execute_sql("CREATE INDEX {$CFG->prefix}block_instance_pageid_idx ON {$CFG->prefix}block_instance (pageid)",false); // this one should be quiet...
132 modify_database('','ALTER TABLE prefix_block_instance ALTER pagetype SET DEFAULT \'\'');
133 modify_database('','ALTER TABLE prefix_block_instance ALTER position SET DEFAULT \'\'');
134 modify_database('','ALTER TABLE prefix_block_instance ALTER pagetype SET NOT NULL');
135 modify_database('','ALTER TABLE prefix_block_instance ALTER position SET NOT NULL');
138 if ($oldversion < 2005081600) {
139 modify_database('',"CREATE TABLE prefix_block_pinned (
140 id SERIAL8 PRIMARY KEY,
141 blockid INT8 NOT NULL default 0,
142 pagetype varchar(20) NOT NULL default '',
143 position varchar(10) NOT NULL default '',
144 weight INT NOT NULL default 0,
145 visible INT NOT NULL default 0,
146 configdata text NOT NULL default 0
150 if ($oldversion < 2005090200) {
151 execute_sql("CREATE INDEX {$CFG->prefix}block_instance_pagetype_idx ON {$CFG->prefix}block_instance (pagetype);",false); // do it silently, in case it's already there from 1.5
152 modify_database('','CREATE INDEX prefix_block_pinned_pagetype_idx ON prefix_block_pinned (pagetype);');
155 ////// DO NOT ADD NEW THINGS HERE!! USE upgrade.php and the lib/ddllib.php functions.
157 //Finally, return result