From: moodler Date: Fri, 25 Oct 2002 08:47:53 +0000 (+0000) Subject: Upgrading all news and social forums (except those in social courses) X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=7beb45d8a05c9a267c9e5b3bdffdd3a29de46d09;p=moodle.git Upgrading all news and social forums (except those in social courses) so that they are course modules in an (invisible) section, which means they are now editable and parameters, names etc can be changed. --- diff --git a/lib/db/mysql.php b/lib/db/mysql.php index 9eb5363792..1807473fed 100644 --- a/lib/db/mysql.php +++ b/lib/db/mysql.php @@ -19,6 +19,8 @@ function main_upgrade($oldversion=0) { + global $CFG; + if ($oldversion == 0) { execute_sql(" CREATE TABLE `config` ( @@ -85,6 +87,86 @@ function main_upgrade($oldversion=0) { execute_sql(" UPDATE modules SET name = 'resource' WHERE name = 'reading' "); } + if ($oldversion < 2002102503) { + require_once("$CFG->dirroot/mod/forum/lib.php"); + require_once("$CFG->dirroot/course/lib.php"); + + if (! $module = get_record("modules", "name", "forum")) { + notify("Could not find forum module!!"); + return false; + } + + // First upgrade the site forums + if ($site = get_site()) { + print_heading("Making News forums editable for main site (moving to section 1)..."); + if ($news = forum_get_course_forum($site->id, "news")) { + $mod->course = $site->id; + $mod->module = $module->id; + $mod->instance = $news->id; + $mod->section = 1; + if (! $mod->coursemodule = add_course_module($mod) ) { + notify("Could not add a new course module to the site"); + return false; + } + if (! $sectionid = add_mod_to_section($mod) ) { + notify("Could not add the new course module to that section"); + return false; + } + if (! set_field("course_modules", "section", $sectionid, "id", $mod->coursemodule)) { + notify("Could not update the course module with the correct section"); + return false; + } + } + } + + + // Now upgrade the courses. + if ($courses = get_records_sql("SELECT * FROM course WHERE category > 0")) { + print_heading("Making News and Social forums editable for each course (moving to section 0)..."); + foreach ($courses as $course) { + if ($course->format == "social") { // we won't touch them + continue; + } + if ($news = forum_get_course_forum($course->id, "news")) { + $mod->course = $course->id; + $mod->module = $module->id; + $mod->instance = $news->id; + $mod->section = 0; + if (! $mod->coursemodule = add_course_module($mod) ) { + notify("Could not add a new course module to the course '$course->fullname'"); + return false; + } + if (! $sectionid = add_mod_to_section($mod) ) { + notify("Could not add the new course module to that section"); + return false; + } + if (! set_field("course_modules", "section", $sectionid, "id", $mod->coursemodule)) { + notify("Could not update the course module with the correct section"); + return false; + } + } + if ($social = forum_get_course_forum($course->id, "social")) { + $mod->course = $course->id; + $mod->module = $module->id; + $mod->instance = $social->id; + $mod->section = 0; + if (! $mod->coursemodule = add_course_module($mod) ) { + notify("Could not add a new course module to the course '$course->fullname'"); + return false; + } + if (! $sectionid = add_mod_to_section($mod) ) { + notify("Could not add the new course module to that section"); + return false; + } + if (! set_field("course_modules", "section", $sectionid, "id", $mod->coursemodule)) { + notify("Could not update the course module with the correct section"); + return false; + } + } + } + } + } + return true; } diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 8a9cd5b4f3..bf9f824266 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -1208,7 +1208,7 @@ function forum_print_latest_discussions($forum_id=0, $forum_numdiscussions=5, $f if (! $course = get_record("course", "category", 0)) { error("Could not find a top-level course!"); } - if (! $forum = forum_get_course_news_forum($course->id)) { + if (! $forum = forum_get_course_forum($course->id, "news")) { error("Could not find or create a main forum in this course (id $course->id)"); } } diff --git a/mod/forum/mod.html b/mod/forum/mod.html index 83ad44bfa8..68472fe154 100644 --- a/mod/forum/mod.html +++ b/mod/forum/mod.html @@ -17,8 +17,14 @@ if (! $form->type) { $form->type = "general"; } - choose_from_menu($FORUM_TYPES, "type", $form->type, ""); - helpbutton("forumtype", get_string("forumtype", "forum"), "forum"); + if ($form->type == "news") { + print_string("namenews", "forum"); + } else if ($form->type == "social") { + print_string("namesocial", "forum"); + } else { + choose_from_menu($FORUM_TYPES, "type", $form->type, ""); + helpbutton("forumtype", get_string("forumtype", "forum"), "forum"); + } ?> diff --git a/version.php b/version.php index db301e2e3b..3cc87c9257 100644 --- a/version.php +++ b/version.php @@ -5,7 +5,7 @@ // database to determine whether upgrades should // be performed (see lib/db/*.php) -$version = 2002102200; // The current version is a date (YYYYMMDDXX) +$version = 2002102503; // The current version is a date (YYYYMMDDXX) -$release = "1.0.6 beta 1"; // User-friendly version number +$release = "1.0.6 beta 2"; // User-friendly version number