~ubuntu-branches/ubuntu/breezy/moodle/breezy

« back to all changes in this revision

Viewing changes to blocks/db/mysql.php

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Mitchell
  • Date: 2005-10-13 02:00:59 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051013020059-y2qcyo41t7nqppcg
Tags: 1.5.2-1ubuntu1
* Resync with debian (security update)
* changed dependencys to php5
* changed apache dependency to apache2 
* References
  CAN-2005-2247

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?PHP  //$Id: mysql.php,v 1.1.8.3 2004/08/30 15:57:09 moodler Exp $
 
1
<?PHP  //$Id: mysql.php,v 1.8 2005/04/30 03:25:28 defacer Exp $
2
2
//
3
3
// This file keeps track of upgrades to Moodle's
4
4
// blocks system.
24
24
    
25
25
    $result = true;
26
26
    
27
 
    if ($oldversion < 2004041000 and $result) {
 
27
    if ($oldversion < 2004041000 && $result) {
28
28
        $result = execute_sql("CREATE TABLE `{$CFG->prefix}blocks` (
29
29
                        `id` int(10) unsigned NOT NULL auto_increment,
30
30
                        `name` varchar(40) NOT NULL default '',
37
37
                     COMMENT = 'To register and update all the available blocks'");
38
38
    }
39
39
 
 
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',
 
49
                        PRIMARY KEY (`id`)
 
50
                     ) 
 
51
                     COMMENT = 'To register and update all the available blocks'");
 
52
 
 
53
        if(!$result) {
 
54
            return false;
 
55
        }
 
56
 
 
57
        $records = get_records('blocks');
 
58
        if(!empty($records)) {
 
59
            foreach($records as $block) {
 
60
                $block->multiple = 0;
 
61
                insert_record('block', $block);
 
62
            }
 
63
        }
 
64
 
 
65
        execute_sql("DROP TABLE `{$CFG->prefix}blocks`");
 
66
 
 
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 '',
 
76
                        
 
77
                        PRIMARY KEY(`id`),
 
78
                        INDEX pageid(`pageid`)
 
79
                    )");
 
80
 
 
81
        if(!$result) {
 
82
            return false;
 
83
        }
 
84
 
 
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);
 
90
                if(!empty($left)) {
 
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);
 
102
                    }
 
103
                }
 
104
                if(!empty($right)) {
 
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);
 
116
                    }
 
117
                }
 
118
            }
 
119
        }
 
120
 
 
121
        execute_sql("ALTER TABLE `{$CFG->prefix}course` DROP COLUMN blockinfo");
 
122
    }
 
123
 
 
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', '');
 
127
    }
 
128
 
 
129
    if ($oldversion < 2004112900 && $result) {
 
130
        execute_sql('UPDATE '.$CFG->prefix.'block_instance SET pagetype = \''.PAGE_COURSE_VIEW.'\' WHERE pagetype = \'\'');
 
131
    }
 
132
 
 
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)) {
 
138
                    $block->visible = 0;
 
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.');
 
141
                }
 
142
            }
 
143
        }
 
144
    }
40
145
 
41
146
    //Finally, return result
42
147
    return $result;