At the end of every academic year we take a snapshot of our Moodle and set it up on a separate archive server, and then make it read-only for everyone.
This was always achieved in 1.x/1.9 by making the datastore read-only, and the database user restricted to SELECT only.
This is the first year that we have attempted this with 2.x (2.2.6) and it isn't working in the same way, we just get stuck with the error "Error writing to database" and no one is able to log in.
At the moment all I can think to do is to edit the Authenticated users role to prohibit almost everything. Though this would still mean that admins were able to make changes which is not ideal but might do the job.
Does anyone else have a similar requirement for a blanket read-only mode for Moodle? Would be interested to hear others' solutions.
Thanks in advance
Alastair
Re: Making Moodle 2.2 read-only globally (for archive purposes)
By default, doesn't Moodle 2 use the DB for sessions? Thus the error?
Try this on the 'read only' site ... add to config.php file:
$CFG->dbsessions=0;
That should create a sessions folder in moodledata ... which still needs to be writable. So that folder would need: chmod ugo+rw at least.
There could be other minor things like above - but can't think of any right now.
'spirit of sharing', Ken
Re: Making Moodle 2.2 read-only globally (for archive purposes)
Thanks Ken
We were using file based sessions already for performance reasons, it seems post-1.9 many more checks have been introduced.
Re: Making Moodle 2.2 read-only globally (for archive purposes)
> This was always achieved in 1.x/1.9 by making the datastore read-only, and the database user restricted to SELECT only.
Nice approach. I can't see a reason why it shouldn't work in Moodle 2.
Talking of snapshots, a trivial solution whould be to restore the snapshot (copy) into a virtual machine and take a snapshot in the virtualization system(?)
Re: Making Moodle 2.2 read-only globally (for archive purposes)
> This was always achieved in 1.x/1.9 by making the datastore read-only, and the database user restricted to SELECT only.
What about logs being inserted into mdl_log when you login/browse the site?
Tomek
Re: Making Moodle 2.2 read-only globally (for archive purposes)
My recollection is that in 1.9 writing to the log table failed silently, users were still able to log in and browse courses
Re: Making Moodle 2.2 read-only globally (for archive purposes)
It no longer works in Moodle 2 as there seem to be a lot of extra checks that the data folder is writable and that the database is writeable (or at least fatal errors are produced if it is read-only, preventing logins)
Regarding snapshots we would much rather have the data truly read-only so that it can be relied upon as a true archive instead of reverting to a snapshot every so often.
Re: Making Moodle 2.2 read-only globally (for archive purposes)
Hi All
My solution as it stands is to make a few code tweaks for use on the archive copy of Moodle.
The general approach is to prevent functions from attempting to write to the database, and to suppress errors. This includes:
lib/datalib.php:add_to_log - return immediately
lib/dml/moodle_database.php:query_end - return before exception handling
lib/dml/mysqli_native_moodle_database.php:insert_record - return true immediately
In 2.5 I also disabled the check for writability of the data folder, oddly this didn't seem to be necessary in 2.2.6 so I've left that as is for now.
Edit: also worth mentioning that we have left the cache and sessions directories writeable as this doesn't impact the integrity of the archive (and obviously is necessary for normal operation)
Alastair
Re: Making Moodle 2.2 read-only globally (for archive purposes)
Hi,
There is a way to make moodle 2.7 read only?
In moodle 2.5 I tried the solution above and it's worked perfectly, but now in 2.7 version I haven't found a way to make it work.