MDL-24520 use different name if manager role already exists
authorPetr Skoda <skodak@moodle.org>
Tue, 5 Oct 2010 08:25:58 +0000 (08:25 +0000)
committerPetr Skoda <skodak@moodle.org>
Tue, 5 Oct 2010 08:25:58 +0000 (08:25 +0000)
lib/db/upgrade.php

index e648446..3b7940a 100644 (file)
@@ -2851,9 +2851,16 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL");
             $role->archetype = substr($role->capability, $substart);
             unset($role->capability);
             if ($role->archetype === 'admin') {
+                $i = '';
+                if ($DB->record_exists('role', array('shortname'=>'manager'))) {
+                    $i = 2;
+                    while($DB->record_exists('role', array('shortname'=>'manager'.$i))) {
+                        $i++;
+                    }
+                }
                 $role->archetype = 'manager';
                 if ($role->shortname === 'admin') {
-                    $role->shortname   = 'manager';
+                    $role->shortname   = 'manager'.$i;
                     $role->name        = get_string('manager', 'role');
                     $role->description = get_string('managerdescription', 'role');
                 }