URLs for arbitrary resources

URLs for arbitrary resources

by Basil Gohar -
Number of replies: 8
I am working on a fix for our instance of Moodle, which is riddled with thousands of invalid links that have accumulated over time.  Basically, I've written a script that parses each Moodle resource (located in the {prefix}resources table) that will extract each link.  Then, it will check each link for validity, more or less just storing the HTTP response code of accessing that link's file.  It also parses URLs for validity.

One feature I have partially implented is a report that allows the user to jump to the specific resource being worked on.  However, not all resources can be accessed directly via their resource id.  So, I am correct in assuming that some resources can only be accessed from within other modules?  And if that is the case, can someone point me to somewhere where I can figure out how to access any arbitrary resource, given its resource id?

Thank you all in advance!
Average of ratings: -
In reply to Basil Gohar

Re: URLs for arbitrary resources

by Jan Dierckx -

I don't understand your question, but here is a link check script we have been using.

In reply to Jan Dierckx

Re: URLs for arbitrary resources

by Basil Gohar -
I skimmed the code for linkcheck.php, and it does not do exactly what I need.  My link-checker firsts parses the fields reference, summary, & alltext from the resource table, and extracts any links.  It does this by scanning for src or href attributes in the summary & alltext fields, and scanning for an http:// string in the reference field.

After storing these in a table, another script will run which will actually check each link and store its response code.

So, the big difference is that what I need to do is actually check the validity of links embedded within the HTML of other resources.  I hope it makes sense now.

As for what I was asking initially, I wanted to know how to get to a resource if it is not normally accessible by its resource id.
In reply to Basil Gohar

Re: URLs for arbitrary resources

by Basil Gohar -
For clarification, this is the error I'm getting when I try to access some resources via their id: 
 

Course Module ID was incorrect

In reply to Basil Gohar

Re: URLs for arbitrary resources

by Basil Gohar -
I discovered the problem, and it was really innocent (in my opinion, anyway...).  I was formatting the URLs to the individual resource as follows:
echo $CFG->wwwroot . '/mod/resource/view.php?id=' . $resource_id;
Whereas, if $resource_id was referring to an actual resource id, the correct parameter is r, and not id.  So, simply substituting id for r as follows:
echo $CFG->wwwroot . '/mod/resource/view.php?id=' . $resource_id;
Seems to fix all the problems I was having.
In reply to Basil Gohar

Re: URLs for arbitrary resources

by Basil Gohar -
That second link is supposed to be like this:
echo $CFG->wwwroot . '/mod/resource/view.php?r=' . $resource_id;
I just forgot to fix it when I copied-and-pasted the link above it.
In reply to Basil Gohar

Re: URLs for arbitrary resources

by Jan Dierckx -

Glad you could solve it. I am interested in seeing your code once it is finished, as it is certainly more versatile than my link check script.

In reply to Jan Dierckx

Re: URLs for arbitrary resources

by N Hansen -
Jan-Maybe your script could be modified to work with URLs stored within the database module? Just an idea...
In reply to Basil Gohar

Re: URLs for arbitrary resources

by Jon Bolton -
Picture of Particularly helpful Moodlers Picture of Testers
Hi Basil - this sounds really good. I too would like to see the code when you're ready smile

Is there any possibility it could also check Forum posts?