]> git.mjollnir.org Git - moodle.git/commitdiff
Upgrading all news and social forums (except those in social courses)
authormoodler <moodler>
Fri, 25 Oct 2002 08:47:53 +0000 (08:47 +0000)
committermoodler <moodler>
Fri, 25 Oct 2002 08:47:53 +0000 (08:47 +0000)
so that they are course modules in an (invisible) section, which means
they are now editable and parameters, names etc can be changed.

lib/db/mysql.php
mod/forum/lib.php
mod/forum/mod.html
version.php

index 9eb5363792da6e61f9309bb5a40d032875af2eca..1807473fed0fa7317b2c797d1659938d165e2eb0 100644 (file)
@@ -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;
 }
 
index 8a9cd5b4f38557932b76b18aaf9f30f5dbeddc5a..bf9f8242666264c53c74babdb0786bdc42ee6d1a 100644 (file)
@@ -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)");
         }
     }
index 83ad44bfa8b533c4b81ffb21f0e2dea7f19c877e..68472fe15486475c360c9604c2ab9f8585360be1 100644 (file)
        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>
index db301e2e3b92446f7935a152c7aba59d9ef55a44..3cc87c925704fb7d00d1ab79590b9e44e46c4564 100644 (file)
@@ -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