From 441b8d6e699affd0ca8c30d1b7eef2337f83bf28 Mon Sep 17 00:00:00 2001 From: Andrew Davis Date: Mon, 7 Oct 2013 14:58:58 +0700 Subject: [PATCH] MDL-26170 RSS: fixed RSS cache clearing when items are deleted --- blog/edit.php | 1 + blog/rsslib.php | 14 ++++++++++++++ mod/forum/discuss.php | 4 +--- mod/forum/lib.php | 10 ++++++++-- mod/forum/rsslib.php | 10 +++++++--- 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/blog/edit.php b/blog/edit.php index 6a182332238..2bae26cb710 100644 --- a/blog/edit.php +++ b/blog/edit.php @@ -120,6 +120,7 @@ if ($action === 'delete'){ print_error('nopermissionstodeleteentry', 'blog'); } else { $entry->delete(); + blog_rss_delete_file($userid); redirect($returnurl); } } else if (blog_user_can_edit_entry($entry)) { diff --git a/blog/rsslib.php b/blog/rsslib.php index 22c9612fd9f..5f81d201d44 100644 --- a/blog/rsslib.php +++ b/blog/rsslib.php @@ -330,3 +330,17 @@ function blog_rss_save_file($type, $id, $tagid=0, $contents='') { return $status; } +/** + * Delete the supplied user's cached blog post RSS feed. + * Only user blogs are available by RSS. + * This doesn't call rss_delete_file() as blog RSS caching uses it's own file structure. + * + * @param int $userid + */ +function blog_rss_delete_file($userid) { + $filename = blog_rss_file_name('user', $userid); + if (file_exists($filename)) { + unlink($filename); + } +} + diff --git a/mod/forum/discuss.php b/mod/forum/discuss.php index c387790549b..28fe7f8ba9c 100644 --- a/mod/forum/discuss.php +++ b/mod/forum/discuss.php @@ -94,10 +94,8 @@ $DB->set_field('forum_read', 'forumid', $forumto->id, array('discussionid' => $discussion->id)); add_to_log($course->id, 'forum', 'move discussion', "discuss.php?d=$discussion->id", $discussion->id, $cmto->id); - require_once($CFG->libdir.'/rsslib.php'); - require_once($CFG->dirroot.'/mod/forum/rsslib.php'); - // Delete the RSS files for the 2 forums to force regeneration of the feeds + require_once($CFG->dirroot.'/mod/forum/rsslib.php'); forum_rss_delete_file($forum); forum_rss_delete_file($forumto); diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 00a3bc16413..ede52632c42 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -4516,7 +4516,7 @@ function forum_delete_post($post, $children, $course, $cm, $forum, $skipcompleti } } - //delete ratings + // Delete ratings. require_once($CFG->dirroot.'/rating/lib.php'); $delopt = new stdClass; $delopt->contextid = $context->id; @@ -4526,11 +4526,17 @@ function forum_delete_post($post, $children, $course, $cm, $forum, $skipcompleti $rm = new rating_manager(); $rm->delete_ratings($delopt); - //delete attachments + // Delete attachments. $fs = get_file_storage(); $fs->delete_area_files($context->id, 'mod_forum', 'attachment', $post->id); $fs->delete_area_files($context->id, 'mod_forum', 'post', $post->id); + // Delete cached RSS feeds. + if (!empty($CFG->enablerssfeeds)) { + require_once($CFG->dirroot.'/mod/forum/rsslib.php'); + forum_rss_delete_file($forum); + } + if ($DB->delete_records("forum_posts", array("id" => $post->id))) { forum_tp_delete_read_records(-1, $post->id); diff --git a/mod/forum/rsslib.php b/mod/forum/rsslib.php index 4d5900bdc83..a73900719e9 100644 --- a/mod/forum/rsslib.php +++ b/mod/forum/rsslib.php @@ -24,6 +24,9 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +/* Include the core RSS lib */ +require_once($CFG->libdir.'/rsslib.php'); + /** * Returns the path to the cached rss feed contents. Creates/updates the cache if necessary. * @param stdClass $context the context @@ -68,9 +71,10 @@ function forum_rss_get_feed($context, $args) { $cachedfilelastmodified = filemtime($cachedfilepath); } // Used to determine if we need to generate a new RSS feed. - $dontrecheckcutoff = time()-60; - // If it hasn't been generated we will need to create it, otherwise only update - // if there is new stuff to show and it is older than the cut off date set above. + $dontrecheckcutoff = time() - 60; // Sixty seconds ago. + + // If it hasn't been generated we need to create it. + // Otherwise, if it has been > 60 seconds since we last updated, check for new items. if (($cachedfilelastmodified == 0) || (($dontrecheckcutoff > $cachedfilelastmodified) && forum_rss_newstuff($forum, $cm, $cachedfilelastmodified))) { // Need to regenerate the cached version.