Which tables to update if we are adding a PDF file in a moodle course externally through a JDBC program

Which tables to update if we are adding a PDF file in a moodle course externally through a JDBC program

by Pushkar Narayan -
Number of replies: 2
I am trying to transfer a PDF file to moodle by using an external JDBC program. I have updated the mdl_files, mdl_resource and mdl_context table of moodle. I have also moved the file to the /var/moodledata/filedir/ab/cd directory (where ab is the first two characters of the content hash and cd is the third & fourth characters of the content hash). Kindly, help me in two things:

1. Do I need to update any other table in moodle? Because the file is not appearing in the specific course.
2. I need to know more about source attribute of mdl_files table.
Average of ratings: -
In reply to Pushkar Narayan

Re: Which tables to update if we are adding a PDF file in a moodle course externally through a JDBC program

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

This sounds like a terrible idea - you would be far better to write a script in PHP that calls the appropriate files API to add the files, etc. (For example, your external code could put a file in a temporary location on the server, then call a new command-line PHP script that copies it from the given path, into Moodle itself).

To get new resources to appear within a Moodle course, you need to call the 'rebuild_course_cache' function (there is no way to do this via external access to the database, as the cache is not, usually, stored in the database), assuming you have already set up the entry in mdl_course_modules and the entry in mdl_course_sections to go with it. 

The function 'add_moduleinfo' (in course/modlib.php) does everything you need (assuming you have an up-to-date version of Moodle).

In reply to Davo Smith

Re: Which tables to update if we are adding a PDF file in a moodle course externally through a JDBC program

by Pushkar Narayan -

Thanks a lot! It was helpful. 

I updated the following tables: mdl_files, mdl_resource, mdl_context, mdl_course_modules, mdl_course_sections

Then, I was able to rebuild the course caches by adding an extra plugin: https://moodle.org/plugins/pluginversion.php?id=2400