Where are the legacy course files stored?

Where are the legacy course files stored?

by Ali Hastie -
Number of replies: 7

Pardon my ignorance (and I know file handling has changed with Moodle 2) but where are the legacy course files stored within the moodledata folder.

Previously the course files folders would be named 2, 3, 4 etc to coincide with the course ID. I can't seem to find where these folders are held within the moodledata/filedir folder.

Running a clean install of Moodle 2.0 (build 20101125) and have enabled legacy course files within the appropriate areas.

Thanks

Ali

Average of ratings: -
In reply to Ali Hastie

Re: Where are the legacy course files stored?

by Gabriel García -

I know this has been post long time ago... Now I'm running a clean 2.0.3+ install and I have sort of the same problem.  Could you find the folders or the place where they are stored now?

In reply to Gabriel García

Re: Where are the legacy course files stored?

by Stefan Nychka -

Hey.

First, it's likely safest to pretend they're not stored in the file system anymore.  This isn't true, but may be soon.  So, I'm assuming you like to use a script or other method to directly manipulate or read from files in 1.9.x or earlier Moodle Files areas.  It's probably best to just not do this.

Nonetheless, technically, they are in fact stored in 2.0.x (well, at least 2.0.2).

A disclaimer:  I'm determining this by glancing at the code and by some simple spot-checking.  Although I'm fairly certain, I can't guarantee I'm right.  Plus, this requires at least a passing understanding of Moodle code, files hashes and Linux.

The files are stored in your $CFG->dataroot dir., under the filedir dir. (at least they are in 2.0.2).  They are named according to an sha1 file hash.  See file.php in $CFG->dirroot dir.  They are, within filedir, stored in 2 levels of dirs., the 1st being the first 2 chars. of the hash, the 2nd being the 3rd and 4th chars (only based on empirical evidence, not by looking at the code ... this may be incorrect if there are more or less files than our install)  e.g., a contrived but illustrative example using the Linux command line from in the filedir directory:

% sha1 5x/29/5x294b696bd26a371afl95e32e05625fdf7da6cq
SHA1(5x/29/5x294b696bd26a371afl95e32e05625fdf7da6cq)= 5x294b696bd26a371afa95e32e05125fdf7da6cd

So, this file when uploaded was named myFile.txt and appears to have this name in Moodle, and when you do an sha1 hash on it, you'd get back 5x294b696bd26a371afa95e32e05125fdf7da6cd.  So, the contents of the file in filedir/5x/29/ named 5x294b696bd26a371afl95e32e05625fdf7da6cq will exactly match myFile.txt.

For reading or accessing these files, you're likely okay.  No guarantees, and use at your discretion.  I'd strongly recommend against trying to update the files, as these entries are likely stored in the database, and any external changes could cause serious problems.

So, likely not the answer you were looking for, but it's also likely correct.

Before doing anything, I'd strongly recommend confirming my assumptions for yourself.  Look at the related code, experiment on a development server, and find all documentation you can at moodle.org (I could only find http://docs.moodle.org/en/Development:File_API).

In reply to Stefan Nychka

Re: Where are the legacy course files stored?

by Mary Cooch -
Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators

Are legacy course files not the "course files" that are in /repository/coursefiles along with other repositories?

In reply to Mary Cooch

Re: Where are the legacy course files stored?

by Stefan Nychka -

Hi.

No.  Those are php files, not files uploaded by Moodle users.

In reply to Stefan Nychka

Re: Where are the legacy course files stored?

by Mary Cooch -
Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators

So what is the course files in the repository directory then?

In reply to Mary Cooch

Re: Where are the legacy course files stored?

by Stefan Nychka -

Hey.

That's what I was previously trying to explain.  I was very brief, though, so I'll do a better job here.

Still, so focus isn't lost, a summary of all this:  coursefiles is a directory containing static, .php code and it will not contain (in a sane install) the directory to which files are uploaded.  I can only guess at what the programs in coursefiles do, though.

Here are more details.

What I do know:

  • coursefiles is a directory
  • coursefiles is in the repository directory
  • repository/coursefiles is in the "dirroot" area, or the location where .php files are installed.
  • The uploaded files are located in a separate directory, known as the "dataroot" directory.  (I'm technically lying, but considering these locations to be separate is in reality accurate most if not all the time.  I'm fairly certain they cannot be the same, but one could have one inside the other ... it'd just be a bit weird and counter-productive, and thus is rarely or never done)
  • So, to repeat, this is the area where Moodle programs are stored (so, the code).  It's static.  This does not contain files uploaded by users.

To better answer your question:

  • I don't know for sure.  The following is just an educated (arguable) guess.
  • The coursefiles directory contains files for a course files plugin.
  • This is, I believe, the code that controls the Legacy Course Files area. 
    • Again, note it doesn't contain uploaded files; it contains programs--so, php code--that controls, if I'm right, files uploaded to the Legacy Course Files area (and the ability to upload said files).
  • A hand-wavy explanation:
    • The comments in repository/coursefiles/lib.php implies what I say above.
    • repository/coursefiles/lib.php contains a $filearea variable which is given the value 'legacy'
    • Through a, to me, convoluted set of class/child related functions and calls, I believe lib.php calls the get_area_course_legacy function inlib/filebrowser/file_info_context_course.php, which checks the value of the parameter representing the previous lip.php's $filearea, and does what seems to be Legacy Course Files area "stuff".  Further, again in a tough-to-follow-way, get_area_course_legacy instantiates a file_info_area_course_legacy object which uses Martin's file.php hack for the Legacy Course Files area (file.php is in the "dirroot" directory).
  • This is a bad way to understand a program; if I needed to know more than the fact that coursefiles does not contain uploaded files, I'd have to be way more certain.

Cheers

Average of ratings: Useful (2)