From 941294ef435aee715edb5b87be1615bff897dc49 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Thu, 10 Jan 2013 17:15:51 +0800 Subject: [PATCH] MDL-36741 mod_forum: fixed the function forum_rss_newstuff that was using count_records_sql incorrectly as well as generating RSS content when no data exists --- mod/forum/rsslib.php | 50 ++++++++++++++++---------------------------- 1 file changed, 18 insertions(+), 32 deletions(-) diff --git a/mod/forum/rsslib.php b/mod/forum/rsslib.php index bb463624ef5..4d5900bdc83 100644 --- a/mod/forum/rsslib.php +++ b/mod/forum/rsslib.php @@ -67,14 +67,15 @@ function forum_rss_get_feed($context, $args) { if (file_exists($cachedfilepath)) { $cachedfilelastmodified = filemtime($cachedfilepath); } - //if the cache is more than 60 seconds old and there's new stuff + // Used to determine if we need to generate a new RSS feed. $dontrecheckcutoff = time()-60; - if ($dontrecheckcutoff > $cachedfilelastmodified && forum_rss_newstuff($forum, $cm, $cachedfilelastmodified)) { - //need to regenerate the cached version + // 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. + if (($cachedfilelastmodified == 0) || (($dontrecheckcutoff > $cachedfilelastmodified) && + forum_rss_newstuff($forum, $cm, $cachedfilelastmodified))) { + // Need to regenerate the cached version. $result = forum_rss_feed_contents($forum, $sql, $params, $modcontext); - if (!empty($result)) { - $status = rss_save_file('mod_forum',$filename,$result); - } + $status = rss_save_file('mod_forum', $filename, $result); } //return the path to the cached version @@ -106,11 +107,8 @@ function forum_rss_newstuff($forum, $cm, $time) { global $DB; list($sql, $params) = forum_rss_get_sql($forum, $cm, $time); - if ($DB->count_records_sql($sql, $params) > 0) { - return true; - } - return false; + return $DB->record_exists_sql($sql, $params); } /** @@ -365,29 +363,17 @@ function forum_rss_feed_contents($forum, $sql, $params, $context) { } $recs->close(); - + // Create the RSS header. + $header = rss_standard_header(strip_tags(format_string($forum->name,true)), + $CFG->wwwroot."/mod/forum/view.php?f=".$forum->id, + format_string($forum->intro,true)); // TODO: fix format + // Now all the RSS items, if there are any. + $articles = ''; if (!empty($items)) { - //First the RSS header - $header = rss_standard_header(strip_tags(format_string($forum->name,true)), - $CFG->wwwroot."/mod/forum/view.php?f=".$forum->id, - format_string($forum->intro,true)); // TODO: fix format - //Now all the rss items - if (!empty($header)) { - $articles = rss_add_items($items); - } - //Now the RSS footer - if (!empty($header) && !empty($articles)) { - $footer = rss_standard_footer(); - } - //Now, if everything is ok, concatenate it - if (!empty($header) && !empty($articles) && !empty($footer)) { - $status = $header.$articles.$footer; - } else { - $status = false; - } - } else { - $status = false; + $articles = rss_add_items($items); } + // Create the RSS footer. + $footer = rss_standard_footer(); - return $status; + return $header . $articles . $footer; } -- 2.43.0