FMCorz
5/18/2017 - 2:33 AM

Webservice test for duplicating Moodle courses

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