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.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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)");
|
||||
}
|
||||
}
|
||||
|
||||
+8
-2
@@ -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");
|
||||
}
|
||||
?>
|
||||
|
||||
</td>
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user