Skip to content

Instantly share code, notes, and snippets.

@FMCorz
Created May 18, 2017 02:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FMCorz/f369c7554642dc68c493c1a786323d9c to your computer and use it in GitHub Desktop.
Save FMCorz/f369c7554642dc68c493c1a786323d9c to your computer and use it in GitHub Desktop.
Webservice test for duplicating Moodle courses
#!/bin/bash
API="http://10.1.1.13/sm/webservice/rest/server.php" # WS entry point.
COURSEID=25 # Course to duplicated.
CATEGORYID=1 # Category to duplicate to.
TOKEN="490b48f8cd71e88a37fa70cc6eff3fb2" # WS Token.
# SCRIPT STARTS HERE.
SUFFIX=`date +"%s"`
echo "Duplicate without user data"
SHORTNAME="Duplicated${COURSEID}_NODATA_${SUFFIX}"
curl $API\
-d moodlewsrestformat=json\
-d wstoken=$TOKEN\
-d wsfunction=core_course_duplicate_course\
-d courseid=$COURSEID\
-d fullname="Duplicated $COURSEID (without user data) - $SUFFIX"\
-d shortname="$SHORTNAME"\
-d categoryid=$CATEGORYID\
-d 'options[0][name]=users'\
-d 'options[0][value]=0'
echo
echo "Duplicate with user data"
SHORTNAME="Duplicated${COURSEID}_${SUFFIX}"
curl $API\
-d moodlewsrestformat=json\
-d wstoken=$TOKEN\
-d wsfunction=core_course_duplicate_course\
-d courseid=$COURSEID\
-d fullname="Duplicated $COURSEID (with user data) - $SUFFIX"\
-d shortname="$SHORTNAME"\
-d categoryid=$CATEGORYID\
-d 'options[0][name]=users'\
-d 'options[0][value]=1'
echo
@haw-fachadmin
Copy link

Dear FMCorz,
do you have a clue how to pass the roles that should be enroled in the duplicated course?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment