Creating modules with commands SQLs

Creating modules with commands SQLs

by Guilherme Estevão -
Number of replies: 6

Hello guys 


I have a java script that generates some modules (Chat, Forum, Quiz) with SQLs commands. For example the commands to persist a chat I use the following commands: 


INSERT INTO `mdl_chat` SET course = course_id, name = 'test1', intro = 'intro test1'

INSERT INTO `mdl_course_modules` SET course = course_id, module = (SELECT id FROM `mdl_modules` WHERE name = 'chat') ,instance = chat_id , visible = 1, showavailability = 1

INSERT INTO `mdl_course_sections` SET course = course_id, section = 1, sequence = module_id


and reset the section cache in course table


UPDATE `mdl_course` SET `sectioncache` = NULL WHERE id=course_id;


Well, the last command does not work anymore (I think because of version changes) so it can not persist over these modules. Thank you in advance for your help

Average of ratings: -
In reply to Guilherme Estevão

Re: Creating modules with commands SQLs

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

modinfo and section caches are now stored in MUC. The crude solution is Purge all caches.Finer-grained solutions are probably possible.

In reply to Tim Hunt

Re: Creating modules with commands SQLs

by Guilherme Estevão -

Sorry. Could you be more specific? What is "MUC"?

In reply to Guilherme Estevão

Re: Creating modules with commands SQLs

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Sorry, it stands for 'Moodle Universal Cache'. http://docs.moodle.org/dev/Cache_API

If you go to Admin -> Plugins -> Caches, then you will see all the different caches there, two of which store the Modinfo and Sectioninfo caches. You need to clear them, not the old database column.

In reply to Tim Hunt

Re: Creating modules with commands SQLs

by Douglas Henrique -

When I try to run any sql command with the API moodle get the error "Error on Wrtting Database".
More precisely the method call insert_record.