Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'wip-MDL-34223-MOODLE_23_STABLE' of git://github.com/mar…

…inaglancy/moodle into MOODLE_23_STABLE
  • Loading branch information...
commit 561cbb8967a6e0f2138fd7687f210d317cb08642 2 parents bdd6847 + 1ab628b
@samhemelryk samhemelryk authored
Showing with 25 additions and 8 deletions.
  1. +25 −8 mod/forum/lib.php
View
33 mod/forum/lib.php
@@ -4106,15 +4106,34 @@ function forum_get_file_info($browser, $areas, $course, $cm, $context, $filearea
return new forum_file_info_container($browser, $course, $cm, $context, $areas, $filearea);
}
- if (!$post = $DB->get_record('forum_posts', array('id' => $itemid))) {
+ static $cached = array();
+ // $cached will store last retrieved post, discussion and forum. To make sure that the cache
+ // is cleared between unit tests we check if this is the same session
+ if (!isset($cached['sesskey']) || $cached['sesskey'] != sesskey()) {
+ $cached = array('sesskey' => sesskey());
+ }
+
+ if (isset($cached['post']) && $cached['post']->id == $itemid) {
+ $post = $cached['post'];
+ } else if ($post = $DB->get_record('forum_posts', array('id' => $itemid))) {
+ $cached['post'] = $post;
+ } else {
return null;
}
- if (!$discussion = $DB->get_record('forum_discussions', array('id' => $post->discussion))) {
+ if (isset($cached['discussion']) && $cached['discussion']->id == $post->discussion) {
+ $discussion = $cached['discussion'];
+ } else if ($discussion = $DB->get_record('forum_discussions', array('id' => $post->discussion))) {
+ $cached['discussion'] = $discussion;
+ } else {
return null;
}
- if (!$forum = $DB->get_record('forum', array('id' => $cm->instance))) {
+ if (isset($cached['forum']) && $cached['forum']->id == $cm->instance) {
+ $forum = $cached['forum'];
+ } else if ($forum = $DB->get_record('forum', array('id' => $cm->instance))) {
+ $cached['forum'] = $forum;
+ } else {
return null;
}
@@ -4131,12 +4150,10 @@ function forum_get_file_info($browser, $areas, $course, $cm, $context, $filearea
return null;
}
// Make sure groups allow this user to see this file
- if ($discussion->groupid > 0) {
+ if ($discussion->groupid > 0 && !has_capability('moodle/site:accessallgroups', $context)) {
$groupmode = groups_get_activity_groupmode($cm, $course);
- if ($groupmode == SEPARATEGROUPS) {
- if (!groups_is_member($discussion->groupid) and !has_capability('moodle/site:accessallgroups', $context)) {
- return null;
- }
+ if ($groupmode == SEPARATEGROUPS && !groups_is_member($discussion->groupid)) {
+ return null;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.