Updated the HEAD build version to 20080816
[moodle.git] / mod / data / db / upgrade.php
CommitLineData
b8a342d7 1<?php //$Id$
2
aab98aaf 3// This file keeps track of upgrades to
b8a342d7 4// the data module
5//
6// Sometimes, changes between versions involve
7// alterations to database structures and other
8// major things that may break installations.
9//
10// The upgrade function in this file will attempt
11// to perform all the necessary actions to upgrade
12// your older installtion to the current version.
13//
14// If there's something it cannot do itself, it
15// will tell you what you need to do.
16//
17// The commands in here will all be database-neutral,
b1f93b15 18// using the methods of database_manager class
b8a342d7 19
20function xmldb_data_upgrade($oldversion=0) {
21
f33e1ed4 22 global $CFG, $THEME, $DB;
b8a342d7 23
f33e1ed4 24 $dbman = $DB->get_manager();
04366d79 25
f33e1ed4 26 $result = true;
25322ba3 27
f33e1ed4 28//===== 1.9.0 upgrade line ======//
54c1f2d5 29
30 if ($result && $oldversion < 2007101512) {
31 /// Launch add field asearchtemplate again if does not exists yet - reported on several sites
32
a8cb94f6 33 $table = new xmldb_table('data');
69b80cc2 34 $field = new xmldb_field('asearchtemplate', XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null, 'jstemplate');
54c1f2d5 35
f33e1ed4 36 if (!$dbman->field_exists($table, $field)) {
eee5d9bb 37 $dbman->add_field($table, $field);
54c1f2d5 38 }
04264aed 39 upgrade_mod_savepoint($result, 2007101512, 'data');
54c1f2d5 40 }
41
42 if ($result && $oldversion < 2007101513) {
f4306412 43 // Upgrade all the data->notification currently being
44 // NULL to 0
3223bc9e 45 $sql = "UPDATE {data} SET notification=0 WHERE notification IS NULL";
f33e1ed4 46 $result = $DB->execute($sql);
47
a8cb94f6 48 $table = new xmldb_table('data');
69b80cc2 49 $field = new xmldb_field('notification', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'editany');
f4306412 50 // First step, Set NOT NULL
eee5d9bb 51 $dbman->change_field_notnull($table, $field);
f4306412 52 // Second step, Set default to 0
eee5d9bb 53 $dbman->change_field_default($table, $field);
04264aed 54 upgrade_mod_savepoint($result, 2007101513, 'data');
f4306412 55 }
04366d79 56
8185aeb6 57 if ($result && $oldversion < 2008081400) {
58 if ($datainstances = $DB->get_records('data')) {
59 $pattern = '/\#\#delete\#\#(\s+)\#\#approve\#\#/';
60 $replacement = '##delete##$1##approve##$1##export##';
61 foreach ($datainstances as $data) {
62 $data->listtemplate = preg_replace($pattern, $replacement, $data->listtemplate);
63 $data->singletemplate = preg_replace($pattern, $replacement, $data->singletemplate);
64 $DB->update_record('data', $data);
65 }
66 }
67 }
68
b8a342d7 69 return $result;
70}
71
72?>