Note: You are currently viewing documentation for Moodle 3.11. Up-to-date documentation for the latest stable version of Moodle may be available here: Upload courses.

Upload courses: Difference between revisions

From MoodleDocs
 
(12 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{Courses}}
{{Courses}}
{{Note|This page is about creating courses with a text (.csv) file. If you want to upload a course backup in .mbz or .tgz format, see [[Course restore]].}}
{{Note|This page is about creating courses with a text (.csv) file. If you want to upload a course backup in .mbz or .tgz format, see [[Course restore]].}}
==Upload courses==
==Upload courses==
In addition to creating new courses, the upload courses functionality may also be used to update or delete courses, or import content from another course. For information on using this functionality to create course templates, see [[Adding a new course]].
In addition to creating new courses, the upload courses functionality may also be used to update or delete courses, or import content from another course. For information on using this functionality to create course templates, see [[Adding a new course]].


To upload one or more courses
To upload one or more courses
# Go to ''Administration > Site administration > Courses > Upload courses''
# Go to ''Administration > Site administration > Courses > Upload courses''
# Either drag and drop the CSV file or click the 'Choose a file' button and select the file in the file picker
# Either drag and drop the CSV file or click the 'Choose a file' button and select the file in the file picker
# Select appropriate import options carefully, then click the preview button.
# Select appropriate import options carefully, then click the preview button.
{|
{|
|[[File:26uploadcourses.png|250px|thumb|Upload courses admin screen]]
|[[File:26uploadcourses.png|250px|thumb|Upload courses admin screen]]
Line 17: Line 13:
|[[File:uploadcoursesresults.png|250px|thumb|Courses successfully uploaded]]
|[[File:uploadcoursesresults.png|250px|thumb|Courses successfully uploaded]]
|}
|}
Note: It is also possible to use the command-line tool ''admin/tool/uploadcourse/cli/uploadcourse.php''.
Note: It is also possible to use the command-line tool ''admin/tool/uploadcourse/cli/uploadcourse.php''.


When using the web interface, use the ''Preview'' option to see if any errors were detected in the previewed rows. If you proceed with the upload and there were something wrong detected with a course, it will be ignored.
When using the web interface, use the ''Preview'' option to see if any errors were detected in the previewed rows. If you proceed with the upload and there were something wrong detected with a course, it will be ignored.
=== Short file example ===
=== Short file example ===
uploadcourse.csv:
uploadcourse.csv:
Line 29: Line 23:
The category field takes the id of the category, with the default category Miscellaneous having id 1. Categories must already exist. If you put a category id that does not exist, you will receive a "Could not resolve category by ID" error during upload preview, and courses in that category will not be created.  
The category field takes the id of the category, with the default category Miscellaneous having id 1. Categories must already exist. If you put a category id that does not exist, you will receive a "Could not resolve category by ID" error during upload preview, and courses in that category will not be created.  


<code>
<PRE>
shortname,fullname,category,summary,enrolment_1,enrolment_1_role,enrolment_1_enrolperiod,role_student
shortname,fullname,category,summary,enrolment_1,enrolment_1_role,enrolment_1_enrolperiod,role_student
courserestored,Course restored,1,a summary,manual,student,1 month,
courserestored,Course restored,1,a summary,manual,student,1 month,
Line 35: Line 29:
courserestored3,Course restored 3,1,a summary,,,,padawan
courserestored3,Course restored 3,1,a summary,,,,padawan
courserestored4,Course restored 4,1,"a summary, with comma",manual,student,1 month,padawan
courserestored4,Course restored 4,1,"a summary, with comma",manual,student,1 month,padawan
</code>
</PRE>
Notice there are no spaces between the items.
Notice there are no spaces between the items.


==Creating the text file==
==Creating the text file==
The text file to upload courses must be a CSV file. It accepts the following columns which are divided in two categories, the course information, and the course actions.
The text file to upload courses must be a CSV file. It accepts the following columns which are divided in two categories, the course information, and the course actions.
===Course information fields===
===Course information fields===
Most of those settings are available on the settings page of a course. Please refer to [[Course settings]] for more information. Field names must be lower-case.
Most of those settings are available on the settings page of a course. Please refer to [[Course settings]] for more information. Field names must be lower-case.
;shortname
;shortname
: The shortname
: The shortname
Line 51: Line 41:
: The full name
: The full name
;idnumber
;idnumber
: The ID number (found on the ‘Edit Category’ page)
: The course ID number
;category
;category
:  This is the ID of the category to place the course in. This takes precedence over ''category_idnumber'' and ''category_path''.
:  This is the database identifier of the category (found in the category URL) to place the course in. This takes precedence over ''category_idnumber'' and ''category_path''.
;category_idnumber
;category_idnumber
: The ID number of the category to place the course in (found in the category url). This takes precedence over ''category_path''.
: The ID number of the category (found and editable on the ‘Edit category’ page) to place the course in. This takes precedence over ''category_path''.
;category_path
;category_path
: The path of the category to place the course in. If you want to place the course in a category named "Science-Fiction" which is located under the category "Movies", the value to provide is: <code>Movies / Science-Fiction</code>. Note that the separator must be <code>[space]/[space]</code>. Also note that the category MUST exist, it will not be created. If you want to place the course in the top-level category "Movies", the value to provide is: <code>Movies</code>
: The path of the category to place the course in. If you want to place the course in a category named "Science-Fiction" which is located under the category "Movies", the value to provide is: <code>Movies / Science-Fiction</code>. Note that the separator must be <code>[space]/[space]</code>. Also note that the category MUST exist, it will not be created. If you want to place the course in the top-level category "Movies", the value to provide is: <code>Movies</code>
;visible
;visible
: 1 if the course is visible, 0 if hidden
: 1 if the course is visible, 0 if hidden
;startdate
;startdate
: The time at which the course starts. Please note that this value is passed to the PHP function [http://php.net/manual/en/function.strtotime.php strtotime] to generate a timestamp. Example 01.12.2014 (1st December 2014)
: The time at which the course starts. Please note that this value is passed to the PHP function [http://php.net/manual/en/function.strtotime.php strtotime] to generate a timestamp. You can use a localized time format based on your server settings, but the standard ISO date format will always work, for example: 2021-05-17 (that is May 17, 2021). You do not need to use quotes for this field when using this format.
;enddate
;enddate
: The time at which the course ends. Please note as with startdate that this value is passed to the PHP function [http://php.net/manual/en/function.strtotime.php strtotime] to generate a timestamp. Example 01.12.2014 (1st December 2014)
: The time at which the course ends. Please note as with startdate that this value needs to be formatted correctly. For example: 2022-11-14.
;summary
;summary
: The summary of the course
: The summary of the course
Line 88: Line 78:
;enablecompletion
;enablecompletion
: 1 to enable the activity completion, 0 not to.
: 1 to enable the activity completion, 0 not to.
'''NEW IN 3.11'''
;downloadcontent
: 1 to enable course content to be downloaded, 0 to not.
;tags
;tags
: A comma-separated list of tags to add to the course. Existing tags will be deleted. Enclose multiple tags in quotes.
: A comma-separated list of tags to add to the course. Existing tags will be deleted. Enclose multiple tags in quotes.
====Enrolment fields====
====Enrolment fields====
Some fields can be constructed to enable and configure enrolment methods. The fields must be named ''enrolment_[number]'' for the enrolment method name, and ''enrolment_[number]_property'' for its properties.
Some fields can be constructed to enable and configure enrolment methods. The fields must be named ''enrolment_[number]'' for the enrolment method name, and ''enrolment_[number]_property'' for its properties.
;enrolment_[number]
;enrolment_[number]
: The name of the enrolment method (eg, manual, guest, self)
: The name of the enrolment method (eg, manual, guest, self)
Line 113: Line 103:
;enrolment_[number]_password
;enrolment_[number]_password
: The course enrolment key
: The course enrolment key
Note: Upload courses is not yet compatible with all [[Enrolments|enrolment methods]] (MDL-43127).
Note: Upload courses is not yet compatible with all [[Enrolments|enrolment methods]] (MDL-43127).


'''Example'''
'''Example'''
  enrolment_1: manual
  enrolment_1: manual
  enrolment_1_role: student
  enrolment_1_role: student
Line 124: Line 112:
  enrolment_2: self
  enrolment_2: self
  enrolment_2_startdate: 2013-01-30
  enrolment_2_startdate: 2013-01-30
====Custom course fields====
Beginning with Moodle 3.9 (see Tracker MDL-66135), you can now fill in data for the custom course fields. The header for these fields is of the form customfield_[shortname] where shortname is the unique shortname of the course custom field.
The custom field must already exist on the site as defined in ''Site administration > Courses > Course custom fields''. If you use a header for a field that does not already exist on the site, it will be ignored by the upload process. The course profile fields '''must''' already exist in your site. You can not use the course upload process to create new ones on the site, only to fill in data for already defined course custom profile fields.
There are five types of course custom fields: Checkbox, Date and time, Dropdown menu, Short text, and Text area. What data you put in the upload file will therefore depend on the type of field you have defined. The possible values for Checkbox fields are 1 (checked) and 0 (unchecked.)
If you leave one of the defined course custom fields off of the upload file, then the upload process will use the default value defined for that field, if there is one, or allow you to set a default during the Preview portion of the upload, just like other settings.
Here is a sample file with an example showing all five of the custom fields types (taken from the Tracker above) where fields with the shortnames "checkbox", "date", "select", "text", and "textarea" have already been created.
<pre>
shortname,fullname,category,customfield_checkbox,customfield_date,customfield_select,customfield_text,customfield_textarea
CF1,Course fields example,1,1,2019-10-01 14:00,b,Hello,Goodbye
</pre>
This creates a course called "Course fields example" with a course shortname of "CF1" in the Miscellaneous category, and fills in data for each of the five custom course fields.


====Role renaming====
====Role renaming====
To rename some roles, using the following pattern:
To rename some roles, using the following pattern:
;role_[shortname]
;role_[shortname]
: The new name of the role ''[shortname]''.
: The new name of the role ''[shortname]''.
'''Example'''
'''Example'''
  role_student: Apprentice
  role_student: Apprentice
  role_teacher: Master
  role_teacher: Master
  role_mycustomrole: Jedi
  role_mycustomrole: Jedi
It is worth noting that the short name for the teacher role is ''editingteacher'' and the short name for the non-editing teacher is ''teacher''.
It is worth noting that the short name for the teacher role is ''editingteacher'' and the short name for the non-editing teacher is ''teacher''.


===Course action fields===
===Course action fields===
Those settings take precedence over the ''Course process'' parameters.
Those settings take precedence over the ''Course process'' parameters.
;delete
;delete
: 1 to delete the course  
: 1 to delete the course  
Line 150: Line 150:
;backupfile
;backupfile
: An absolute path to a backup file (.mbz) to import in the course.
: An absolute path to a backup file (.mbz) to import in the course.
(This means the full path to your course, for example ''/home/yourmoodle/public_html/moodle27/transfert/backup.mbz'' . If you are unsure of this, look at include_path in ''Site administration>Server>PHP info.)''
(This means the full path to your course, for example ''/home/yourmoodle/public_html/moodle27/transfert/backup.mbz'' . If you are unsure of this, look at include_path in ''Site administration>Server>PHP info.)''
;templatecourse
;templatecourse
Line 156: Line 155:
;reset
;reset
: 1 to reset the course
: 1 to reset the course
===Mandatory fields===
===Mandatory fields===
;shortname
;shortname
: This field is mandatory for every operation, with the only exception of creating new courses. See details on the course process parameter ''Shortname template'' for more information.
: This field is mandatory for every operation, with the only exception of creating new courses. See details on the course process parameter ''Shortname template'' for more information.
Line 165: Line 162:
;category, category_idnumber, category_path
;category, category_idnumber, category_path
: One of these is required when creating a course.
: One of these is required when creating a course.
===Import options===
===Import options===
To prevent unexpected behaviour, you have to specify what you want the tool to be able to do.
To prevent unexpected behaviour, you have to specify what you want the tool to be able to do.
;Upload mode
;Upload mode
: This allows you to specify if courses can be created and/or updated.
: This allows you to specify if courses can be created and/or updated.
Line 180: Line 174:
;Allow resets
;Allow resets
: Whether the ''reset'' field is accepted or not
: Whether the ''reset'' field is accepted or not
===Course process===
===Course process===
This allows you to specify actions to be taken for every course uploaded.
This allows you to specify actions to be taken for every course uploaded.
;Shortname template
;Shortname template
: If you are creating courses without a shortname, you can use this field to automatically generate a shortname. This field accepts two placeholders: %i for the ID number, %f for the summary.
: If you are creating courses without a shortname, you can use this field to automatically generate a shortname. This field accepts two placeholders: %i for the ID number, %f for the fullname. You may use template syntax here (%f = fullname, %i = idnumber), or enter an initial value that is incremented.
;Restore file
;Restore file
: A backup file (.mbz) to import in the course after create/update.
: A backup file (.mbz) to import in the course after create/update.
Line 195: Line 186:


===Default course values===
===Default course values===
Those are values that can be set in the web interface for all the fields that are not specified in the CSV file. Note that they are always used when creating a course, but only when specified during update (see ''Update mode'').
Those are values that can be set in the web interface for all the fields that are not specified in the CSV file. Note that they are always used when creating a course, but only when specified during update (see ''Update mode'').
==Increasing speed==
==Increasing speed==
When importing the content of a backup file, or another course, you are advised to enable the setting ''keeptempdirectoriesonbackup''. This will considerably speed up the process of the upload if you are importing multiple times from the same source.
When importing the content of a backup file, or another course, you are advised to enable the setting ''keeptempdirectoriesonbackup''. This will considerably speed up the process of the upload if you are importing multiple times from the same source.
==See also==
==See also==
* Demo screencast: [http://youtu.be/MzK2jb-9SwE Bulk course creation]
* Demo screencast: [http://youtu.be/MzK2jb-9SwE Bulk course creation]
* [[Upload users]]
* [[Upload users]]
* [http://www.moodleblog.net/2013/11/24/creating-course-templates-in-moodle-2-6/ Creating course templates in Moodle 2.6] blog post by Mary Cooch
* [http://www.moodleblog.net/2013/11/24/creating-course-templates-in-moodle-2-6/ Creating course templates in Moodle 2.6] blog post by Mary Cooch
[[fr:Modifier des cours en lots]]
[[fr:Modifier des cours en lots]]
[[de:Kurse hochladen]]
[[de:Kurse hochladen]]
[[es:Subir cursos]]
[[es:Subir cursos]]
[[ja:コースをアップロードする]]
[[ja:コースをアップロードする]]

Latest revision as of 11:27, 29 August 2023

Note: This page is about creating courses with a text (.csv) file. If you want to upload a course backup in .mbz or .tgz format, see Course restore.

Upload courses

In addition to creating new courses, the upload courses functionality may also be used to update or delete courses, or import content from another course. For information on using this functionality to create course templates, see Adding a new course.

To upload one or more courses

  1. Go to Administration > Site administration > Courses > Upload courses
  2. Either drag and drop the CSV file or click the 'Choose a file' button and select the file in the file picker
  3. Select appropriate import options carefully, then click the preview button.
Upload courses admin screen
Courses successfully uploaded

Note: It is also possible to use the command-line tool admin/tool/uploadcourse/cli/uploadcourse.php.

When using the web interface, use the Preview option to see if any errors were detected in the previewed rows. If you proceed with the upload and there were something wrong detected with a course, it will be ignored.

Short file example

uploadcourse.csv:

Note: shortname, fullname, and category are required.

The category field takes the id of the category, with the default category Miscellaneous having id 1. Categories must already exist. If you put a category id that does not exist, you will receive a "Could not resolve category by ID" error during upload preview, and courses in that category will not be created.

shortname,fullname,category,summary,enrolment_1,enrolment_1_role,enrolment_1_enrolperiod,role_student
courserestored,Course restored,1,a summary,manual,student,1 month,
courserestored2,Course restored 2,1,a summary,,,,
courserestored3,Course restored 3,1,a summary,,,,padawan
courserestored4,Course restored 4,1,"a summary, with comma",manual,student,1 month,padawan

Notice there are no spaces between the items.

Creating the text file

The text file to upload courses must be a CSV file. It accepts the following columns which are divided in two categories, the course information, and the course actions.

Course information fields

Most of those settings are available on the settings page of a course. Please refer to Course settings for more information. Field names must be lower-case.

shortname
The shortname
fullname
The full name
idnumber
The course ID number
category
This is the database identifier of the category (found in the category URL) to place the course in. This takes precedence over category_idnumber and category_path.
category_idnumber
The ID number of the category (found and editable on the ‘Edit category’ page) to place the course in. This takes precedence over category_path.
category_path
The path of the category to place the course in. If you want to place the course in a category named "Science-Fiction" which is located under the category "Movies", the value to provide is: Movies / Science-Fiction. Note that the separator must be [space]/[space]. Also note that the category MUST exist, it will not be created. If you want to place the course in the top-level category "Movies", the value to provide is: Movies
visible
1 if the course is visible, 0 if hidden
startdate
The time at which the course starts. Please note that this value is passed to the PHP function strtotime to generate a timestamp. You can use a localized time format based on your server settings, but the standard ISO date format will always work, for example: 2021-05-17 (that is May 17, 2021). You do not need to use quotes for this field when using this format.
enddate
The time at which the course ends. Please note as with startdate that this value needs to be formatted correctly. For example: 2022-11-14.
summary
The summary of the course
format
The course format to use, this must be a valid course format plugin name. E.g. weeks, topics.
theme
The theme to use
lang
The language to use
newsitems
The number of news items
showgrades
1 to show the gradebook to students, 0 to hide it.
showreports
1 to show the activity reports, 0 to hide it.
legacyfiles
1 to enable the legacy course files, 0 not to.
maxbytes
The maximum upload size of the course in bytes. Use 0 for the site limit.
groupmode
0 for No groups, 1 for Separate groups and 2 for Visible groups.
groupmodeforce
1 to force the group mode, otherwise enter 0.
enablecompletion
1 to enable the activity completion, 0 not to.

NEW IN 3.11

downloadcontent
1 to enable course content to be downloaded, 0 to not.
tags
A comma-separated list of tags to add to the course. Existing tags will be deleted. Enclose multiple tags in quotes.

Enrolment fields

Some fields can be constructed to enable and configure enrolment methods. The fields must be named enrolment_[number] for the enrolment method name, and enrolment_[number]_property for its properties.

enrolment_[number]
The name of the enrolment method (eg, manual, guest, self)
enrolment_[number]_delete
1 to delete this enrolment method from the course, if set to 1 all the other properties will be ignored.
enrolment_[number]_disable
1 to disable this enrolment method from the course, if set to 1 all the other properties will be ignored.
enrolment_[number]_startdate
The enrolment start date. This value is passed to the PHP function strtotime().
enrolment_[number]_enddate
The enrolment end date. This value is passed to the PHP function strtotime().
enrolment_[number]_enrolperiod
Number of seconds, or if not a value understood by strtotime() such as "4 days".
enrolment_[number]_role
The role short name
enrolment_[number]_[property]
Where property is understood by the specified enrolment method
enrolment_[number]_password
The course enrolment key

Note: Upload courses is not yet compatible with all enrolment methods (MDL-43127).

Example

enrolment_1: manual
enrolment_1_role: student
enrolment_1_enrolperiod: 1 month

enrolment_2: self
enrolment_2_startdate: 2013-01-30

Custom course fields

Beginning with Moodle 3.9 (see Tracker MDL-66135), you can now fill in data for the custom course fields. The header for these fields is of the form customfield_[shortname] where shortname is the unique shortname of the course custom field.

The custom field must already exist on the site as defined in Site administration > Courses > Course custom fields. If you use a header for a field that does not already exist on the site, it will be ignored by the upload process. The course profile fields must already exist in your site. You can not use the course upload process to create new ones on the site, only to fill in data for already defined course custom profile fields.

There are five types of course custom fields: Checkbox, Date and time, Dropdown menu, Short text, and Text area. What data you put in the upload file will therefore depend on the type of field you have defined. The possible values for Checkbox fields are 1 (checked) and 0 (unchecked.)

If you leave one of the defined course custom fields off of the upload file, then the upload process will use the default value defined for that field, if there is one, or allow you to set a default during the Preview portion of the upload, just like other settings.

Here is a sample file with an example showing all five of the custom fields types (taken from the Tracker above) where fields with the shortnames "checkbox", "date", "select", "text", and "textarea" have already been created.

shortname,fullname,category,customfield_checkbox,customfield_date,customfield_select,customfield_text,customfield_textarea
CF1,Course fields example,1,1,2019-10-01 14:00,b,Hello,Goodbye

This creates a course called "Course fields example" with a course shortname of "CF1" in the Miscellaneous category, and fills in data for each of the five custom course fields.

Role renaming

To rename some roles, using the following pattern:

role_[shortname]
The new name of the role [shortname].

Example

role_student: Apprentice
role_teacher: Master
role_mycustomrole: Jedi

It is worth noting that the short name for the teacher role is editingteacher and the short name for the non-editing teacher is teacher.

Course action fields

Those settings take precedence over the Course process parameters.

delete
1 to delete the course
rename
The shortname to rename the course to
backupfile
An absolute path to a backup file (.mbz) to import in the course.

(This means the full path to your course, for example /home/yourmoodle/public_html/moodle27/transfert/backup.mbz . If you are unsure of this, look at include_path in Site administration>Server>PHP info.)

templatecourse
The short name of a course to import the content from
reset
1 to reset the course

Mandatory fields

shortname
This field is mandatory for every operation, with the only exception of creating new courses. See details on the course process parameter Shortname template for more information.
fullname
Required when creating a new course.
category, category_idnumber, category_path
One of these is required when creating a course.

Import options

To prevent unexpected behaviour, you have to specify what you want the tool to be able to do.

Upload mode
This allows you to specify if courses can be created and/or updated.
Update mode
If you allow courses to be updated, you also have to tell the tool what to update the courses with.
Allow deletes
Whether the delete field is accepted or not
Allow renames
Whether the rename field is accepted or not
Allow resets
Whether the reset field is accepted or not

Course process

This allows you to specify actions to be taken for every course uploaded.

Shortname template
If you are creating courses without a shortname, you can use this field to automatically generate a shortname. This field accepts two placeholders: %i for the ID number, %f for the fullname. You may use template syntax here (%f = fullname, %i = idnumber), or enter an initial value that is incremented.
Restore file
A backup file (.mbz) to import in the course after create/update.
Restore from course
The shortname of a course to import content from after create/update.
Reset after upload
Whether to reset the course after creating/updating it.

Default course values

Those are values that can be set in the web interface for all the fields that are not specified in the CSV file. Note that they are always used when creating a course, but only when specified during update (see Update mode).

Increasing speed

When importing the content of a backup file, or another course, you are advised to enable the setting keeptempdirectoriesonbackup. This will considerably speed up the process of the upload if you are importing multiple times from the same source.

See also