Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / backup / db / mysql.php
blobaf93afa8a62753d35cd8eac7ba3bc86af08c42ad
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 backup_upgrade($oldversion=0) {
12 global $CFG;
14 $result = true;
16 if ($oldversion < 2003050300 and $result) {
17 $result = execute_sql("CREATE TABLE `{$CFG->prefix}backup_ids` (
18 `backup_code` INT(12) UNSIGNED NOT NULL,
19 `table_name` VARCHAR(30) NOT NULL,
20 `old_id` INT(10) UNSIGNED NOT NULL,
21 `new_id` INT(10) UNSIGNED,
22 PRIMARY KEY (`backup_code`, `table_name`, `old_id`)
24 COMMENT = 'To store and convert ids in backup/restore'");
27 if ($oldversion < 2003050301 and $result) {
28 $result = execute_sql("ALTER TABLE `{$CFG->prefix}backup_ids`
29 ADD `info` VARCHAR(30)");
32 if ($oldversion < 2003050400 and $result) {
33 $result = execute_sql("ALTER TABLE `{$CFG->prefix}backup_ids`
34 MODIFY `info` VARCHAR(255)");
37 if ($oldversion < 2003050401 and $result) {
38 $result = execute_sql("CREATE TABLE `{$CFG->prefix}backup_files` (
39 `backup_code` INT( 10 ) UNSIGNED NOT NULL ,
40 `file_type` VARCHAR( 10 ) NOT NULL ,
41 `path` VARCHAR( 255 ) NOT NULL ,
42 `old_id` INT( 10 ) UNSIGNED,
43 `new_id` INT( 10 ) UNSIGNED,
44 PRIMARY KEY ( `backup_code` , `file_type` , `path` )
45 ) COMMENT = 'To store and recode ids to user & course files.'");
48 if ($oldversion < 2003052000 and $result) {
49 $result = execute_sql("ALTER TABLE `{$CFG->prefix}backup_ids`
50 MODIFY `info` TEXT");
53 if ($oldversion < 2003061100 and $result) {
54 $result = execute_sql("ALTER TABLE `{$CFG->prefix}backup_ids`
55 MODIFY `info` MEDIUMTEXT");
58 if ($oldversion < 2003082600 and $result) {
59 print_simple_box("This is the first non-alpha release of the Backup/Restore module.<p>Thanks for upgrading!","center", "50%", '', "20", "noticebox");
62 if ($oldversion < 2003112700 and $result) {
63 $result = execute_sql("CREATE TABLE `{$CFG->prefix}backup_config` (
64 `id` int(10) unsigned NOT NULL auto_increment,
65 `name` varchar(255) NOT NULL default '',
66 `value` varchar(255) NOT NULL default '',
67 PRIMARY KEY (`id`),
68 UNIQUE KEY `name` (`name`)
69 ) TYPE=MyISAM COMMENT='To store backup configuration variables'");
72 if ($oldversion < 2003120800 and $result) {
73 $result = execute_sql("CREATE TABLE `{$CFG->prefix}backup_courses` (
74 `id` int(10) unsigned NOT NULL auto_increment,
75 `courseid` int(10) unsigned NOT NULL default '0',
76 `laststarttime` int(10) unsigned NOT NULL default '0',
77 `lastendtime` int(10) unsigned NOT NULL default '0',
78 `laststatus` varchar(1) NOT NULL default '0',
79 `nextstarttime` int(10) unsigned NOT NULL default '0',
80 PRIMARY KEY (`id`),
81 UNIQUE KEY `courseid` (`courseid`)
82 ) TYPE=MyISAM COMMENT='To store every course backup status'");
84 if ($result) {
85 $result = execute_sql("CREATE TABLE `{$CFG->prefix}backup_log` (
86 `id` int(10) unsigned NOT NULL auto_increment,
87 `courseid` int(10) unsigned NOT NULL default '0',
88 `time` int(10) unsigned NOT NULL default '0',
89 `laststarttime` int(10) unsigned NOT NULL default '0',
90 `info` varchar(255) NOT NULL default '',
91 PRIMARY KEY (`id`)
92 ) TYPE=MyISAM COMMENT='To store every course backup log info'");
96 if ($oldversion < 2006011600 and $result) {
97 $result = execute_sql("DROP TABLE {$CFG->prefix}backup_files");
98 if ($result) {
99 $result = execute_sql("CREATE TABLE `{$CFG->prefix}backup_files` (
100 `id` int(10) unsigned NOT NULL auto_increment,
101 `backup_code` int(10) unsigned NOT NULL default '0',
102 `file_type` varchar(10) NOT NULL default '',
103 `path` varchar(255) NOT NULL default '',
104 `old_id` int(10) unsigned NOT NULL default '0',
105 `new_id` int(10) unsigned NOT NULL default '0',
106 PRIMARY KEY (`id`),
107 UNIQUE KEY `{$CFG->prefix}backup_files_uk` (`backup_code`,`file_type`,`path`)
108 ) TYPE=MyISAM COMMENT='To store and recode ids to user and course files.'");
110 if ($result) {
111 $result = execute_sql("DROP TABLE {$CFG->prefix}backup_ids");
113 if ($result) {
114 $result = execute_sql("CREATE TABLE `{$CFG->prefix}backup_ids` (
115 `id` int(10) unsigned NOT NULL auto_increment,
116 `backup_code` int(12) unsigned NOT NULL default '0',
117 `table_name` varchar(30) NOT NULL default '',
118 `old_id` int(10) unsigned NOT NULL default '0',
119 `new_id` int(10) unsigned NOT NULL default '0',
120 `info` mediumtext,
121 PRIMARY KEY (`id`),
122 UNIQUE KEY `{$CFG->prefix}backup_ids_uk` (`backup_code` ,`table_name`,`old_id`)
123 ) TYPE=MyISAM COMMENT='To store and convert ids in backup/restore'");
128 // code to drop the prefix in tables
129 if ($oldversion < 2006042100) {
130 // see bug 5205, silent drops, so should not panic anyone
131 $result = execute_sql("ALTER TABLE {$CFG->prefix}backup_files DROP INDEX backup_files_uk", false);
132 $result = execute_sql("ALTER TABLE {$CFG->prefix}backup_files DROP INDEX {$CFG->prefix}backup_files_uk", false);
133 $result = execute_sql("ALTER TABLE {$CFG->prefix}backup_ids DROP INDEX backup_ids_uk", false);
134 $result = execute_sql("ALTER TABLE {$CFG->prefix}backup_ids DROP INDEX {$CFG->prefix}backup_ids_uk", false);
135 $result = execute_sql("ALTER TABLE {$CFG->prefix}backup_files ADD UNIQUE INDEX backup_files_uk(backup_code,file_type(10),path(255))");
136 $result = execute_sql("ALTER TABLE {$CFG->prefix}backup_ids ADD UNIQUE INDEX backup_ids_uk(backup_code,table_name(30),old_id)");
139 // chaing default nulls to not null default 0
141 if ($oldversion < 2006042800) {
143 execute_sql("UPDATE {$CFG->prefix}backup_files SET old_id='0' WHERE old_id IS NULL");
144 table_column('backup_files','old_id','old_id','int','10','unsigned','0','not null');
146 execute_sql("UPDATE {$CFG->prefix}backup_files SET new_id='0' WHERE new_id IS NULL");
147 table_column('backup_files','new_id','new_id','int','10','unsigned','0','not null');
149 execute_sql("UPDATE {$CFG->prefix}backup_ids SET new_id='0' WHERE new_id IS NULL");
150 table_column('backup_ids','new_id','new_id','int','10','unsigned','0','not null');
152 execute_sql("UPDATE {$CFG->prefix}backup_ids SET info='' WHERE info IS NULL");
153 table_column('backup_ids','info','info','mediumtext','','','','not null');
156 ////// DO NOT ADD NEW THINGS HERE!! USE upgrade.php and the lib/ddllib.php functions.
158 //Finally, return result
159 return $result;