diff --git a/mod/forum/lib.php b/mod/forum/lib.php index e1d6384f7ae..12c87dfd540 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -4448,14 +4448,14 @@ function forum_reset_course_form($course) { * @param $forum - a forum object with the same attributes as a record * from the forum database table * @param $forummodid - the id of the forum module, from the modules table - * @param $studentroles - array of roles that have the moodle/legacy:student - * capability - * @param $guestroles - array of roles that have the moodle/legacy:guest - * capability + * @param $teacherroles - array of roles that have moodle/legacy:teacher + * @param $studentroles - array of roles that have moodle/legacy:student + * @param $guestroles - array of roles that have moodle/legacy:guest * @param $cmid - the course_module id for this forum instance * @return boolean - forum was converted or not */ -function forum_convert_to_roles($forum, $forummodid, $teacherroles=array(), $studentroles=array(), $guestroles=array(), $cmid=NULL) { +function forum_convert_to_roles($forum, $forummodid, $teacherroles=array(), + $studentroles=array(), $guestroles=array(), $cmid=NULL) { global $CFG; @@ -4634,6 +4634,35 @@ function forum_convert_to_roles($forum, $forummodid, $teacherroles=array(), $stu } break; } + + if (empty($cm)) { + $cm = get_record('course_modules', 'id', $cmid); + } + + // $cm->groupmode: + // 0 - No groups + // 1 - Separate groups + // 2 - Visible groups + switch ($cm->groupmode) { + case 0: + break; + case 1: + foreach ($studentroles as $studentrole) { + assign_capability('moodle/site:accessallgroups', CAP_PREVENT, $studentrole->id, $context->id); + } + foreach ($teacherroles as $teacherrole) { + assign_capability('moodle/site:accessallgroups', CAP_ALLOW, $teacherrole->id, $context->id); + } + break; + case 2: + foreach ($studentroles as $studentrole) { + assign_capability('moodle/site:accessallgroups', CAP_ALLOW, $studentrole->id, $context->id); + } + foreach ($teacherroles as $teacherrole) { + assign_capability('moodle/site:accessallgroups', CAP_ALLOW, $teacherrole->id, $context->id); + } + break; + } } return true; } diff --git a/mod/forum/restorelib.php b/mod/forum/restorelib.php index 806b6f36c26..90574083fa0 100644 --- a/mod/forum/restorelib.php +++ b/mod/forum/restorelib.php @@ -171,9 +171,8 @@ // we need to convert the forum to use Roles. It means the backup // was made pre Moodle 1.7. We check the backup_version to make // sure. - if (($restore->backup_version < 2006082300) || - (isset($forum->open) && isset($forum->assesspublic))) { - + if (isset($forum->open) && isset($forum->assesspublic)) { + $forummod = get_record('modules', 'name', 'forum'); if (!$teacherroles = get_roles_with_capability('moodle/legacy:teacher', CAP_ALLOW)) {