Moodle

Typo in rss/file.php breaking RSS feeds

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Cannot Reproduce
  • Affects Version/s: 1.8.2
  • Fix Version/s: None
  • Component/s: RSS
  • Labels:
    None
  • Affected Branches:
    MOODLE_18_STABLE

Description

Whenever I tried to access an internal Moodle RSS Feed, I got an error. It turns out there is a typo in a block of code in moodle/rss/file.php:

//Check for "security" if the course is hidden or the activity is hidden
if (Unable to render embedded object: File ($isblog and () not found.$course->visible || !$cm->visible) && (!has_capability('moodle/course:viewhiddenactivities', $context))) { rss_not_found(); }

In the if statement above, the "and" should be a "&&". Because of this typo, the rss_not_found() function is being invoked in situations where it shouldn't.

I believe the corrected code should be:

//Check for "security" if the course is hidden or the activity is hidden
if (Unable to render embedded object: File ($isblog && () not found.$course->visible || !$cm->visible) && (!has_capability('moodle/course:viewhiddenactivities', $context))) { rss_not_found(); } }

Activity

Hide
Petr Škoda (skodak) added a comment -

I do not think that the "and" affects the result of the if condition.

I think the problems might be in the has_capability() call, because it can not be used without userid when cookies not used.

Assigning to Yu...

Show
Petr Škoda (skodak) added a comment - I do not think that the "and" affects the result of the if condition. I think the problems might be in the has_capability() call, because it can not be used without userid when cookies not used. Assigning to Yu...
Hide
Doug Vermes added a comment -

Hmm... In my case, when I changed the "and" to "&&", the RSS feeds started working perfectly. I suppose it could be a coincidence, though.

Show
Doug Vermes added a comment - Hmm... In my case, when I changed the "and" to "&&", the RSS feeds started working perfectly. I suppose it could be a coincidence, though.
Hide
Yu Zhang added a comment -

Hi, I don't think it's the && either, maybe you tried to grab the feed before it was generated by cron?

Show
Yu Zhang added a comment - Hi, I don't think it's the && either, maybe you tried to grab the feed before it was generated by cron?
Hide
Doug Vermes added a comment -

I don't think so. When I was having the problems, I checked the file system and the rss.xml file had already been successfully generated. The problem was with moodle/rss/file.php not properly returning that file when it was called. Something in file.php was returning an error instead of reference to the rss.xml file in the moodledata folder. After I changed the "and" to "&&", it worked perfectly. That's why I thought that was the problem.

However, I just went into file.php and changed the "&&" back to "and" and things still seem to be working fine. So I'm totally confused. I don't know why RSS feeds originally were not working when cron had been run and the file had been generated. Maybe Petr was right that it has something to do with the has_capability() calls?

Show
Doug Vermes added a comment - I don't think so. When I was having the problems, I checked the file system and the rss.xml file had already been successfully generated. The problem was with moodle/rss/file.php not properly returning that file when it was called. Something in file.php was returning an error instead of reference to the rss.xml file in the moodledata folder. After I changed the "and" to "&&", it worked perfectly. That's why I thought that was the problem. However, I just went into file.php and changed the "&&" back to "and" and things still seem to be working fine. So I'm totally confused. I don't know why RSS feeds originally were not working when cron had been run and the file had been generated. Maybe Petr was right that it has something to do with the has_capability() calls?
Hide
eamon costello added a comment -

I have seen this problem too. Its odd because it resolves itself after a short time if you don't do anything. I think the code fix you made is a red herring.

I publish a feed. Add it to my reader (netvibes) but get RSS Error and no feeds coming through. But after some time maybe a day or a few hours they start to show up and it works fine from then on.

Show
eamon costello added a comment - I have seen this problem too. Its odd because it resolves itself after a short time if you don't do anything. I think the code fix you made is a red herring. I publish a feed. Add it to my reader (netvibes) but get RSS Error and no feeds coming through. But after some time maybe a day or a few hours they start to show up and it works fine from then on.
Hide
Ian Hochstead added a comment -

I agree with Petr on both points, and this seems to
be a real problem.

"and" vs. "&&" does not seem to matter for this call.

There is a problem in that the has_capability() call is missing $userid.

The problem manifests itself when the course is hidden and a "teacher" tries to access the RSS feed, they get the RSS_Error. However teachers have viewhiddenactivities capabilities, so they should not be getting the error.

Adding the $userid to the has_capability() call corrects the problem.

Show
Ian Hochstead added a comment - I agree with Petr on both points, and this seems to be a real problem. "and" vs. "&&" does not seem to matter for this call. There is a problem in that the has_capability() call is missing $userid. The problem manifests itself when the course is hidden and a "teacher" tries to access the RSS feed, they get the RSS_Error. However teachers have viewhiddenactivities capabilities, so they should not be getting the error. Adding the $userid to the has_capability() call corrects the problem.
Hide
Martin Dougiamas added a comment -

While you're there, Andrew.

Show
Martin Dougiamas added a comment - While you're there, Andrew.

People

Dates

  • Created:
    Updated:
    Resolved: