37
37
COMMENT = 'To register and update all the available blocks'");
40
if ($oldversion < 2004101900 && $result) {
41
$result = execute_sql("CREATE TABLE `{$CFG->prefix}block` (
42
`id` int(10) unsigned NOT NULL auto_increment,
43
`name` varchar(40) NOT NULL default '',
44
`version` int(10) NOT NULL default '0',
45
`cron` int(10) unsigned NOT NULL default '0',
46
`lastcron` int(10) unsigned NOT NULL default '0',
47
`visible` tinyint(1) NOT NULL default '1',
48
`multiple` tinyint(1) NOT NULL default '0',
51
COMMENT = 'To register and update all the available blocks'");
57
$records = get_records('blocks');
58
if(!empty($records)) {
59
foreach($records as $block) {
61
insert_record('block', $block);
65
execute_sql("DROP TABLE `{$CFG->prefix}blocks`");
67
$result = execute_sql("CREATE TABLE `{$CFG->prefix}block_instance` (
68
`id` int(10) not null auto_increment,
69
`blockid` int(10) not null default '0',
70
`pageid` int(10) not null default '0',
71
`pagetype` varchar(12) not null default '',
72
`position` enum('l', 'r') not null,
73
`weight` tinyint(3) not null default '0',
74
`visible` tinyint(1) not null default '0',
75
`configdata` text not null default '',
78
INDEX pageid(`pageid`)
85
$records = get_records('course');
86
if(!empty($records)) {
87
foreach($records as $thiscourse) {
88
// The @ suppresses a notice emitted if there is no : in the string
89
@list($left, $right) = split(':', $thiscourse->blockinfo);
91
$arr = explode(',', $left);
92
foreach($arr as $weight => $blk) {
93
$instance = new stdClass;
94
$instance->blockid = abs($blk);
95
$instance->pageid = $thiscourse->id;
96
$instance->pagetype = PAGE_COURSE_VIEW;
97
$instance->position = BLOCK_POS_LEFT;
98
$instance->weight = $weight;
99
$instance->visible = ($blk > 0) ? 1 : 0;
100
$instance->configdata = '';
101
insert_record('block_instance', $instance);
105
$arr = explode(',', $right);
106
foreach($arr as $weight => $blk) {
107
$instance = new stdClass;
108
$instance->blockid = abs($blk);
109
$instance->pageid = $thiscourse->id;
110
$instance->pagetype = PAGE_COURSE_VIEW;
111
$instance->position = BLOCK_POS_RIGHT;
112
$instance->weight = $weight;
113
$instance->visible = ($blk > 0) ? 1 : 0;
114
$instance->configdata = '';
115
insert_record('block_instance', $instance);
121
execute_sql("ALTER TABLE `{$CFG->prefix}course` DROP COLUMN blockinfo");
124
if ($oldversion < 2004112900 && $result) {
125
$result = $result && table_column('block_instance', 'pagetype', 'pagetype', 'varchar', '20', '');
126
$result = $result && table_column('block_instance', 'position', 'position', 'varchar', '10', '');
129
if ($oldversion < 2004112900 && $result) {
130
execute_sql('UPDATE '.$CFG->prefix.'block_instance SET pagetype = \''.PAGE_COURSE_VIEW.'\' WHERE pagetype = \'\'');
133
if ($oldversion < 2005043000 && $result) {
134
$records = get_records('block');
135
if(!empty($records)) {
136
foreach($records as $block) {
137
if(!block_is_compatible($block->name)) {
139
update_record('block', $block);
140
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.');
41
146
//Finally, return result