add assignments from command line

add assignments from command line

by Dane Miller -
Number of replies: 3
I would like to manually add an assignment to Moodle without using the web interface. This ought to be possible by adding records to the mysql tables, but I'm stuck. Here's what I tried:

1. create mdl_assignment record, auto-id
2. create mdl_event record, instance=mdl_assignment::id

3. create mdl_course_modules record, instance=mdl_assignment::id
4. update mdl_course_sections record, sequence=mdl_course_modules::id





...which doesn't quite work. On the course frontpage, it creates an assignment icon without the assignment name. On the course's assignment page, there is no listing at all for this assignment.

Are there other tables to update besides 1-4 above? Or maybe I added the records incorrectly.

I'm testing the "manual" process with phpmyadmin before finalizing it as a perl script. Moodle 1.5.3 on Debian Sarge. Mysql 4.0.24,

Guidance appreciated,
Dane
Average of ratings: -
In reply to Dane Miller

Re: add assignments from command line

by Jan Dierckx -
Some things I can think of mixed

The sequence field is made up of a list of numbers

In php after adding a module you have to call Moodle's function rebuild_course_cache. I guess you would have to mimic what happens there inside your perl script as well.


In reply to Jan Dierckx

Re: add assignments from command line

by Dane Miller -
Thanks Jan.  This looks promising.  It looks like  rebuild_course_cache changes the "modinfo" field in the mdl_course table.  The modinfo field contains a long string, created by serializing an array of activity objects.  The array of activity objects is created by the function get_array_of_activities, and contains all the activities for the course.

Here's an example of an array of activity objects after being processed by the function serialize (in lib/nusoap/nusoap.php):
a:48:{
    i:187;
    O:8:"stdClass":6:{
        s:2:"cm";        s:3:"187";
        s:3:"mod";      s:10:"assignment";
        s:7:"section";  s:1:"1";
        s:4:"name";     s:9:"wk1+Hum+9";
        s:7:"visible";   s:1:"0";
        s:5:"extra";     s:0:"";
     }
    i:188;
    O:8:"stdClass":6:{
        s:2:"cm";        s:3:"188";
        s:3:"mod";      s:10:"assignment";
        s:7:"section";  s:1:"1";
        s:4:"name";     s:9:"wk1+Hum10";
        s:7:"visible";   s:1:"0";
        s:5:"extra";     s:0:"";
     }
}

So maybe if I update this field it will all work...  goes off to try...
Dane
In reply to Dane Miller

Re: add assignments from command line

by Dane Miller -
oops.  doing that removes the assignment name from _all_ my assigments on the course front page.  so now I'm left with a bunch of assignment icons without names.

better undo that and keep trying...
Dane