From 6adc1e975daadbca56e22b1ef49ef9d0ec520bca Mon Sep 17 00:00:00 2001 From: vyshane Date: Wed, 20 Sep 2006 02:59:43 +0000 Subject: [PATCH] Added more overrides during restore process for forums from 1.6. Plus some bug fixes. --- mod/forum/db/mysql.php | 9 +++++-- mod/forum/db/postgres7.php | 50 ++++++-------------------------------- mod/forum/lib.php | 30 +++++++++++++++++------ mod/forum/restorelib.php | 10 +++++--- mod/forum/view.php | 3 +-- 5 files changed, 45 insertions(+), 57 deletions(-) diff --git a/mod/forum/db/mysql.php b/mod/forum/db/mysql.php index cfb65ee4b5..7cd965d388 100644 --- a/mod/forum/db/mysql.php +++ b/mod/forum/db/mysql.php @@ -237,6 +237,11 @@ function forum_upgrade($oldversion) { if ($forums = get_records('forum')) { + if (!$teacherroles = get_roles_with_capability('moodle/legacy:teacher', CAP_ALLOW)) { + notify('Default teacher role was not found. Roles and permissions '. + 'for all your forums will have to be manually set after '. + 'this upgrade.'); + } if (!$studentroles = get_roles_with_capability('moodle/legacy:student', CAP_ALLOW)) { notify('Default student role was not found. Roles and permissions '. 'for all your forums will have to be manually set after '. @@ -248,8 +253,8 @@ function forum_upgrade($oldversion) { 'this upgrade.'); } foreach ($forums as $forum) { - if (!forum_convert_to_roles($forum, $forummod->id, - $studentroles, $guestroles)) { + if (!forum_convert_to_roles($forum, $forummod->id, $teacherroles, + $studentroles, $guestroles)) { notify('Forum with id '.$forum->id.' was not upgraded'); } } diff --git a/mod/forum/db/postgres7.php b/mod/forum/db/postgres7.php index 5f4d72bb8c..026d0ffade 100644 --- a/mod/forum/db/postgres7.php +++ b/mod/forum/db/postgres7.php @@ -179,47 +179,6 @@ function forum_upgrade($oldversion) { execute_sql("INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('forum', 'user report', 'user', 'firstname||\' \'||lastname')"); } - if ($oldversion < 2006081800) { - // Upgrades for new roles and capabilities support. - require_once($CFG->dirroot.'/mod/forum/lib.php'); - - $forummod = get_record('modules', 'name', 'forum'); - - if ($forums = get_records('forum')) { - - if (!$studentroles = get_roles_with_capability('moodle/legacy:student', CAP_ALLOW)) { - notify('Default student role was not found. Roles and permissions '. - 'for all your forums will have to be manually set after '. - 'this upgrade.'); - } - if (!$guestroles = get_roles_with_capability('moodle/legacy:guest', CAP_ALLOW)) { - notify('Default guest role was not found. Roles and permissions '. - 'for teacher forums will have to be manually set after '. - 'this upgrade.'); - } - - foreach ($forums as $forum) { - if (!forum_convert_to_roles($forum, $forummod->id, - $studentroles, $guestroles)) { - notify('Forum with id '.$forum->id.' was not upgraded'); - } - } - - // Drop column forum.open. - modify_database('', 'ALTER TABLE prefix_forum DROP COLUMN open;'); - - // Drop column forum.assesspublic. - modify_database('', 'ALTER TABLE prefix_forum DROP COLUMN assesspublic;'); - - // We need to rebuild all the course caches to refresh the state of - // the forum modules. - include_once( "$CFG->dirroot/course/lib.php" ); - rebuild_course_cache(); - - } // End if. - } - - if ($oldversion < 2006081800) { // Upgrades for new roles and capabilities support. require_once($CFG->dirroot.'/mod/forum/lib.php'); @@ -228,6 +187,11 @@ function forum_upgrade($oldversion) { if ($forums = get_records('forum')) { + if (!$teacherroles = get_roles_with_capability('moodle/legacy:teacher', CAP_ALLOW)) { + notify('Default teacher role was not found. Roles and permissions '. + 'for all your forums will have to be manually set after '. + 'this upgrade.'); + } if (!$studentroles = get_roles_with_capability('moodle/legacy:student', CAP_ALLOW)) { notify('Default student role was not found. Roles and permissions '. 'for all your forums will have to be manually set after '. @@ -239,8 +203,8 @@ function forum_upgrade($oldversion) { 'this upgrade.'); } foreach ($forums as $forum) { - if (!forum_convert_to_roles($forum, $forummod->id, - $studentroles, $guestroles)) { + if (!forum_convert_to_roles($forum, $forummod->id, $teacherroles, + $studentroles, $guestroles)) { notify('Forum with id '.$forum->id.' was not upgraded'); } } diff --git a/mod/forum/lib.php b/mod/forum/lib.php index c180315aad..e1d6384f7a 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -4455,7 +4455,7 @@ function forum_reset_course_form($course) { * @param $cmid - the course_module id for this forum instance * @return boolean - forum was converted or not */ -function forum_convert_to_roles($forum, $forummodid, $studentroles=array(), $guestroles=array(), $cmid=NULL) { +function forum_convert_to_roles($forum, $forummodid, $teacherroles=array(), $studentroles=array(), $guestroles=array(), $cmid=NULL) { global $CFG; @@ -4598,11 +4598,17 @@ function forum_convert_to_roles($forum, $forummodid, $studentroles=array(), $gue foreach ($studentroles as $studentrole) { assign_capability('mod/forum:rate', CAP_ALLOW, $studentrole->id, $context->id); } - // The legacy teacher role can already rate forum posts by default. + foreach ($teacherroles as $teacherrole) { + assign_capability('mod/forum:rate', CAP_ALLOW, $teacherrole->id, $context->id); + } break; case 2: - // The legacy student role cannot rate forum posts by default. - // The legacy teacher role can already rate forum posts by default. + foreach ($studentroles as $studentrole) { + assign_capability('mod/forum:rate', CAP_PREVENT, $studentrole->id, $context->id); + } + foreach ($teacherroles as $teacherrole) { + assign_capability('mod/forum:rate', CAP_ALLOW, $teacherrole->id, $context->id); + } break; } @@ -4612,10 +4618,20 @@ function forum_convert_to_roles($forum, $forummodid, $studentroles=array(), $gue // 1 = Students can see everyone's ratings switch ($forum->assesspublic) { case 0: - // This is already the behavior of the default legacy roles. + foreach ($studentroles as $studentrole) { + assign_capability('mod/forum:viewanyrating', CAP_PREVENT, $studentrole->id, $context->id); + } + foreach ($teacherroles as $teacherrole) { + assign_capability('mod/forum:viewanyrating', CAP_ALLOW, $teacherrole->id, $context->id); + } break; case 1: - assign_capability('mod/forum:viewanyrating', CAP_ALLOW, $studentrole->id, $context->id); + foreach ($studentroles as $studentrole) { + assign_capability('mod/forum:viewanyrating', CAP_ALLOW, $studentrole->id, $context->id); + } + foreach ($teacherroles as $teacherrole) { + assign_capability('mod/forum:viewanyrating', CAP_ALLOW, $teacherrole->id, $context->id); + } break; } } @@ -4624,4 +4640,4 @@ function forum_convert_to_roles($forum, $forummodid, $studentroles=array(), $gue -?> +?> \ No newline at end of file diff --git a/mod/forum/restorelib.php b/mod/forum/restorelib.php index a140188987..806b6f36c2 100644 --- a/mod/forum/restorelib.php +++ b/mod/forum/restorelib.php @@ -171,11 +171,15 @@ // 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 (($restore->backup_version < 2006082300) || + (isset($forum->open) && isset($forum->assesspublic))) { $forummod = get_record('modules', 'name', 'forum'); + if (!$teacherroles = get_roles_with_capability('moodle/legacy:teacher', CAP_ALLOW)) { + notice('Default teacher role was not found. Roles and permissions '. + 'for all your forums will have to be manually set.'); + } if (!$studentroles = get_roles_with_capability('moodle/legacy:student', CAP_ALLOW)) { notice('Default student role was not found. Roles and permissions '. 'for all your forums will have to be manually set.'); @@ -186,7 +190,7 @@ } require_once($CFG->dirroot.'/mod/forum/lib.php'); forum_convert_to_roles($forum, $forummod->id, - $studentroles, $guestroles, + $teacherroles, $studentroles, $guestroles, $restore->mods['forum']->instances[$mod->id]->restored_as_course_module); } diff --git a/mod/forum/view.php b/mod/forum/view.php index c2f6e8e7cd..10878c57b2 100644 --- a/mod/forum/view.php +++ b/mod/forum/view.php @@ -289,7 +289,6 @@ break; } - print_footer($course); -?> +?> \ No newline at end of file -- 2.39.5