2006-10-04 09:47:05 +00:00
|
|
|
<?PHP //$Id$
|
|
|
|
|
|
|
|
// This file keeps track of upgrades to Moodle.
|
|
|
|
//
|
|
|
|
// Sometimes, changes between versions involve
|
|
|
|
// alterations to database structures and other
|
|
|
|
// major things that may break installations.
|
|
|
|
//
|
|
|
|
// The upgrade function in this file will attempt
|
|
|
|
// to perform all the necessary actions to upgrade
|
|
|
|
// your older installtion to the current version.
|
|
|
|
//
|
|
|
|
// If there's something it cannot do itself, it
|
|
|
|
// will tell you what you need to do.
|
|
|
|
//
|
|
|
|
// The commands in here will all be database-neutral,
|
|
|
|
// using the functions defined in lib/ddllib.php
|
|
|
|
|
|
|
|
|
|
|
|
function xmldb_main_upgrade($oldversion=0) {
|
|
|
|
|
2008-05-15 21:40:00 +00:00
|
|
|
global $CFG, $THEME, $USER, $DB;
|
2006-10-04 09:47:05 +00:00
|
|
|
|
|
|
|
$result = true;
|
|
|
|
|
2008-05-23 22:30:42 +00:00
|
|
|
$dbman = $DB->get_manager(); // loads ddl manager and xmldb classes
|
2008-05-15 21:40:00 +00:00
|
|
|
|
2008-05-01 20:29:04 +00:00
|
|
|
////////////////////////////////////////
|
|
|
|
///upgrade supported only from 1.9.x ///
|
|
|
|
////////////////////////////////////////
|
2008-02-21 09:27:11 +00:00
|
|
|
|
2008-03-07 13:23:38 +00:00
|
|
|
if ($result && $oldversion < 2008030700) {
|
|
|
|
|
|
|
|
/// Define index contextid-lowerboundary (not unique) to be dropped form grade_letters
|
2008-05-20 23:24:40 +00:00
|
|
|
$table = new xmldb_table('grade_letters');
|
2008-05-22 00:09:59 +00:00
|
|
|
$index = new xmldb_index('contextid-lowerboundary', XMLDB_INDEX_NOTUNIQUE, array('contextid', 'lowerboundary'));
|
2008-03-07 13:23:38 +00:00
|
|
|
|
|
|
|
/// Launch drop index contextid-lowerboundary
|
2008-05-15 21:40:00 +00:00
|
|
|
$result = $result && $dbman->drop_index($table, $index);
|
2008-03-07 13:23:38 +00:00
|
|
|
|
|
|
|
/// Define index contextid-lowerboundary-letter (unique) to be added to grade_letters
|
2008-05-20 23:24:40 +00:00
|
|
|
$table = new xmldb_table('grade_letters');
|
2008-05-22 00:09:59 +00:00
|
|
|
$index = new xmldb_index('contextid-lowerboundary-letter', XMLDB_INDEX_UNIQUE, array('contextid', 'lowerboundary', 'letter'));
|
2008-03-07 13:23:38 +00:00
|
|
|
|
|
|
|
/// Launch add index contextid-lowerboundary-letter
|
2008-05-15 21:40:00 +00:00
|
|
|
$result = $result && $dbman->add_index($table, $index);
|
2008-03-07 13:23:38 +00:00
|
|
|
|
|
|
|
/// Main savepoint reached
|
2008-04-18 23:15:44 +00:00
|
|
|
upgrade_main_savepoint($result, 2008030700);
|
|
|
|
}
|
2008-03-07 13:23:38 +00:00
|
|
|
|
2008-05-01 20:29:04 +00:00
|
|
|
if ($result && $oldversion < 2008050100) {
|
|
|
|
// Update courses that used weekscss to weeks
|
2008-05-20 23:24:40 +00:00
|
|
|
$result = $DB->set_field('course', 'format', 'weeks', array('format' => 'weekscss'));
|
2008-05-01 20:29:04 +00:00
|
|
|
upgrade_main_savepoint($result, 2008050100);
|
|
|
|
}
|
|
|
|
|
2008-05-02 09:42:43 +00:00
|
|
|
if ($result && $oldversion < 2008050200) {
|
|
|
|
// remove unused config options
|
|
|
|
unset_config('statsrolesupgraded');
|
|
|
|
upgrade_main_savepoint($result, 2008050200);
|
|
|
|
}
|
|
|
|
|
2008-05-07 13:34:54 +00:00
|
|
|
if ($result && $oldversion < 2008050700) {
|
|
|
|
/// Fix minor problem caused by MDL-5482.
|
|
|
|
require_once($CFG->dirroot . '/question/upgrade.php');
|
|
|
|
$result = $result && question_fix_random_question_parents();
|
|
|
|
upgrade_main_savepoint($result, 2008050700);
|
|
|
|
}
|
|
|
|
|
2008-05-12 14:05:46 +00:00
|
|
|
if ($result && $oldversion < 2008051200) {
|
|
|
|
// if guest role used as default user role unset it and force admin to choose new setting
|
|
|
|
if (!empty($CFG->defaultuserroleid)) {
|
2008-05-30 16:50:00 +00:00
|
|
|
if ($role = $DB->get_record('role', array('id'=>$CFG->defaultuserroleid))) {
|
2008-05-12 14:05:46 +00:00
|
|
|
if ($guestroles = get_roles_with_capability('moodle/legacy:guest', CAP_ALLOW)) {
|
|
|
|
if (isset($guestroles[$role->id])) {
|
|
|
|
set_config('defaultuserroleid', null);
|
|
|
|
notify('Guest role removed from "Default role for all users" setting, please select another role.', 'notifysuccess');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
set_config('defaultuserroleid', null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-12 14:38:45 +00:00
|
|
|
if ($result && $oldversion < 2008051201) {
|
|
|
|
notify('Increasing size of user idnumber field, this may take a while...', 'notifysuccess');
|
|
|
|
|
2008-05-15 17:03:49 +00:00
|
|
|
/// Under MySQL and Postgres... detect old NULL contents and change them by correct empty string. MDL-14859
|
|
|
|
if ($CFG->dbfamily == 'mysql' || $CFG->dbfamily == 'postgres') {
|
2008-05-30 16:50:00 +00:00
|
|
|
$DB->execute("UPDATE {user} SET idnumber = '' WHERE idnumber IS NULL", true);
|
2008-05-15 17:03:49 +00:00
|
|
|
}
|
|
|
|
|
2008-05-12 14:38:45 +00:00
|
|
|
/// Define index idnumber (not unique) to be dropped form user
|
2008-05-20 23:24:40 +00:00
|
|
|
$table = new xmldb_table('user');
|
2008-05-22 00:09:59 +00:00
|
|
|
$index = new xmldb_index('idnumber', XMLDB_INDEX_NOTUNIQUE, array('idnumber'));
|
2008-05-12 14:38:45 +00:00
|
|
|
|
|
|
|
/// Launch drop index idnumber
|
2008-05-15 21:40:00 +00:00
|
|
|
if ($dbman->index_exists($table, $index)) {
|
|
|
|
$result = $result && $dbman->drop_index($table, $index);
|
2008-05-12 14:38:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Changing precision of field idnumber on table user to (255)
|
2008-05-20 23:24:40 +00:00
|
|
|
$table = new xmldb_table('user');
|
2008-05-22 00:09:59 +00:00
|
|
|
$field = new xmldb_field('idnumber', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null, 'password');
|
2008-05-12 14:38:45 +00:00
|
|
|
|
|
|
|
/// Launch change of precision for field idnumber
|
2008-05-15 21:40:00 +00:00
|
|
|
$result = $result && $dbman->change_field_precision($table, $field);
|
2008-05-12 14:38:45 +00:00
|
|
|
|
|
|
|
/// Launch add index idnumber again
|
2008-05-22 00:09:59 +00:00
|
|
|
$index = new xmldb_index('idnumber', XMLDB_INDEX_NOTUNIQUE, array('idnumber'));
|
2008-05-15 21:40:00 +00:00
|
|
|
$result = $result && $dbman->add_index($table, $index);
|
2008-05-12 14:38:45 +00:00
|
|
|
|
|
|
|
/// Main savepoint reached
|
|
|
|
upgrade_main_savepoint($result, 2008051201);
|
|
|
|
}
|
|
|
|
|
2008-05-16 02:15:23 +00:00
|
|
|
if ($result && $oldversion < 2008051202) {
|
2008-05-30 16:50:00 +00:00
|
|
|
$log_action = new object();
|
2008-05-16 02:15:23 +00:00
|
|
|
$log_action->module = 'course';
|
|
|
|
$log_action->action = 'unenrol';
|
|
|
|
$log_action->mtable = 'course';
|
|
|
|
$log_action->field = 'fullname';
|
2008-05-30 16:50:00 +00:00
|
|
|
if (!$DB->record_exists('log_display', array('action'=>'unenrol', 'module'=>'course'))) {
|
|
|
|
$result = $result && $DB->insert_record('log_display', $log_action);
|
2008-05-16 02:15:23 +00:00
|
|
|
}
|
|
|
|
upgrade_main_savepoint($result, 2008051202);
|
|
|
|
}
|
|
|
|
|
2008-05-15 21:40:00 +00:00
|
|
|
/*
|
|
|
|
* TODO:
|
|
|
|
* drop adodb_logsql table and create a ner general sql log table
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2007-06-20 23:06:29 +00:00
|
|
|
return $result;
|
2006-10-04 09:47:05 +00:00
|
|
|
}
|
2007-08-09 21:51:09 +00:00
|
|
|
|
|
|
|
|
2006-10-04 09:47:05 +00:00
|
|
|
?>
|