From: skodak Date: Wed, 27 Sep 2006 22:16:23 +0000 (+0000) Subject: fixed array_shift($roles) warning during upgrade from 1.6 X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=5d0df39db40c77a30bc59b9f5405123c10d9d6c4;p=moodle.git fixed array_shift($roles) warning during upgrade from 1.6 --- diff --git a/lib/db/mysql.php b/lib/db/mysql.php index f4a9bb7f2f..9a168cf0c1 100644 --- a/lib/db/mysql.php +++ b/lib/db/mysql.php @@ -2225,23 +2225,24 @@ function main_upgrade($oldversion=0) { } 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++; + if ($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++; + } } } } diff --git a/lib/db/postgres7.php b/lib/db/postgres7.php index 58e1c564a5..56f6b4c709 100644 --- a/lib/db/postgres7.php +++ b/lib/db/postgres7.php @@ -1825,23 +1825,24 @@ function main_upgrade($oldversion=0) { } 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++; + if ($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++; + } } } }