I'm trying to manually add courses in a moodle website by importing directly into mdl_course table from a csv file. I've managed to import the courses but only the first shows up. Must I edit another table in order for the courses to show up in the website? Or is there a field that I must give a specific value ? Thanks in advance.
I'm not sure why your courses aren't showing up. Make sure the category and sortorder fields are set correctly, in particular make sure sortorder is different for everything. If in doubt, try making it run fix_course_sort_order (various things will trigger this ie go to edit courses and click the 'Sort into alphabetical order' button), maybe that will make your courses appear...
I was careful with the category and sortorder fields, i set sortorder as a unique number for each course,and the correct category number, but only the first course appears. I'm attaching the mdl_course .csv file so you'd check if there's something wrong.
Also i'm trying to the same thing with mdl_resource, that is manually add text resources to courses, but they won't appear either.
As for mdl_resource, if adding resources you need to add:
1) new mdl_resource row
2) new mdl_course_modules row
3) entry for cmid in existing mdl_course_sections row
4) make sure to call rebuild_course_cache (which you can do by setting the modinfo field of mdl_course to null/blank)
Again I don't have time to go into detail but this one is definitely possible, we use it a lot. However you can't do it purely with uploading CSV files into the database because of the adding-sections malarkey and all that interrelated data, ie you can't add #2 until you know the id of #1, etc. You really need to be writing proper software scripts for the task.
NOTE: In the categories screen, next to the category the courses number is correct,it shows all the courses I added.
Hey just wondering if you ever solved your issue. I am running into something simmilar
When I have less than 200 courses after migration I have to access the course using the URL path (http://localhost/moodle19/course/view.php?id=3) to get the course to show up in both the “Add/edit courses” section and front page. (pain if I have to do each by hand.
When the amount of courses added reach 201, even after doing the above, the front page (set to courses) goes blank but they still show up in the "Add/edit courses".
If interested in helping me you can read more at: http://moodle.org/mod/forum/discuss.php?d=159589#p699186
I can not help you for the moment, as I am investigating on the same issue. But as you were already told, you can not simply import a csv-file into the moodle-database, because Moodle was not designed so. Moodle was designed with a programmer API, which means you have to write php-code using Moodle-API function calls. Using these functions you will be sure not to break anything in the logic and database.
I found a hint yesterday which can give you a first idea on how to solve your problem, which is also mine: I export data from a "school administration system" and want to import/create those courses with an automated script into Moodle. So exporting the data may give us a csv-file but we will have to read in those lines from a php script and then create the courses with Moodle API functions like create_course(). Read the developer docs to know where to find the Moodle function cross-reference. Here is the hint with sample code:
For your information: what happens when you click on a submit button in the web-form of the CREATE NEW COURSE link in your browser? A request is sent to the Moodle server with all the parameters you can choose and type in on the web-form. And the request tells Moodle also which function or php-script should be called/run to process the parameter data. So, using a php-script you are free to prepare the needed parameter data and then to call the php-script or a series of functions contained in a php-file (usually called a library), with your parameters without going throug the process of clicking in a web-form. This will ensure that everything remains consistent and nothing is broken.
I will be glad to post my solution in a couple of days or weeks, but I am sure a lot of programmers already wrote what we are looking for.
I just found very useful logic and hints in the webCT import tool (particularly in the lib.php file contained there) you can find in the modules & plugins section and in the corresponding thread
So I will have to investigate and study the enrolment plugins first.
a) use the flat file or external database enrolment plugin. You can find it in AdminBlock -> Courses -> Enrolments
There you can configure everything and if something is not clear you/we have to study the corresponding moodle docs.
b) write own php-code you can deduce from existing code samples you can find either in the modules & plugins section or the Moodle forums, as I already indicated. But I just looked into the code you find in yourMoodleDir/enrol/database/enrol.php and there is contained every clean Moodle API function call you need, including enrolment of students and teachers.
I've written a perl script to manually add courses to the mdl_course table. I run it from the command line. The script just reads lines from a text file and inserts the data directly into the database table.
It's an X-1. It works, but there are a few glitches when I look at the courses using moodle; they're not as serious as the problem you're having, though, Christofer. My guess is that the newline character in your text file is not one that is being recognized by whatever script you're using to batch upload courses, so that whatever "reads" the text file never finds a second line.