From 45b9781ed4cf3cbbed73a708c8e9d124ccb8d2e2 Mon Sep 17 00:00:00 2001 From: skodak Date: Tue, 19 Sep 2006 07:35:48 +0000 Subject: [PATCH] fixed missing shortname pg upgrade code, sorry --- lib/db/mysql.php | 3 ++- lib/db/postgres7.php | 25 +++++++++++++++++++++++++ version.php | 2 +- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/db/mysql.php b/lib/db/mysql.php index 91972cc13f..ca97e574b2 100644 --- a/lib/db/mysql.php +++ b/lib/db/mysql.php @@ -2224,7 +2224,7 @@ function main_upgrade($oldversion=0) { delete_records('config', 'name', 'requestedstudentsname'); } - if ($oldversion < 2006091804) { + if ($oldversion < 2006091901) { $roles = get_records('role'); $first = array_shift($roles); if (!empty($first->shortname)) { @@ -2248,6 +2248,7 @@ function main_upgrade($oldversion=0) { } } } + return $result; } diff --git a/lib/db/postgres7.php b/lib/db/postgres7.php index 4846cf5ceb..17de9708c3 100644 --- a/lib/db/postgres7.php +++ b/lib/db/postgres7.php @@ -1824,6 +1824,31 @@ function main_upgrade($oldversion=0) { delete_records('config', 'name', 'requestedstudentsname'); } + if ($oldversion < 2006091901) { + $roles = get_records('role'); + $first = array_shift($roles); + if (!empty($first->shortname)) { + // shortnames already exist + } else { + table_column('role', '', 'shortname', 'varchar', '100', '', '', 'not null', 'name'); + $legacy_names = array('admin', 'coursecreator', 'editingteacher', 'teacher', 'student', 'guest'); + foreach ($legacy_names as $name) { + if ($roles = get_roles_with_capability('moodle/legacy:'.$name, CAP_ALLOW)) { + $i = ''; + foreach ($roles as $role) { + if (empty($role->shortname)) { + $updated = new object(); + $updated->id = $role->id; + $updated->shortname = $name.$i; + update_record('role', $updated); + $i++; + } + } + } + } + } + } + return $result; } diff --git a/version.php b/version.php index 2f4a9980bf..24902c4f25 100644 --- a/version.php +++ b/version.php @@ -6,7 +6,7 @@ // This is compared against the values stored in the database to determine // whether upgrades should be performed (see lib/db/*.php) - $version = 2006091900; // YYYYMMDD = date + $version = 2006091901; // YYYYMMDD = date // XY = increments within a single day $release = '1.7 dev'; // Human-friendly version name -- 2.39.5