]> git.mjollnir.org Git - moodle.git/commitdiff
Added more overrides during restore process for forums from 1.6. Plus some bug fixes.
authorvyshane <vyshane>
Wed, 20 Sep 2006 02:59:43 +0000 (02:59 +0000)
committervyshane <vyshane>
Wed, 20 Sep 2006 02:59:43 +0000 (02:59 +0000)
mod/forum/db/mysql.php
mod/forum/db/postgres7.php
mod/forum/lib.php
mod/forum/restorelib.php
mod/forum/view.php

index cfb65ee4b52a77e31f5c9e1dab5366ae6d35672d..7cd965d3888be2d0d9d2a32904d2aeb6f835bce2 100644 (file)
@@ -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');
               }
           }
index 5f4d72bb8c95f0ffdf0a45ad3070b5a717b49177..026d0ffaded30bc87b001b333bf135f601d47b56 100644 (file)
@@ -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');
               }
           }
index c180315aadc6fdcb014fa11afa76a99a7619a427..e1d6384f7ae531528359d0a837241de419f2b824 100644 (file)
@@ -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
index a1401889878dec19522cd7fb1b715f6d8592dbb6..806b6f36c2666745a12faf08ddce11ff3dda08ab 100644 (file)
             // 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.');
                 }
                 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);
             }
             
index c2f6e8e7cd635979bfcf93c4a889f3c46ffc7643..10878c57b268280a4def54a753842692f1405a71 100644 (file)
             
             break;
     }
-
     print_footer($course);
 
-?>
+?>
\ No newline at end of file