core_course_duplicate_course: error/setting_locked_by_permission problem

core_course_duplicate_course: error/setting_locked_by_permission problem

by Anis Jradah -
Number of replies: 1
Dear All, Kindly, I am getting the error below while trying to duplicate a course using core_course_duplicate_course function:
<?xml version="1.0" encoding="UTF-8" ?>
<EXCEPTION class="base_setting_exception">
<ERRORCODE>setting_locked_by_permission</ERRORCODE>
<MESSAGE>error/setting_locked_by_permission</MESSAGE>
</EXCEPTION>


my code:

$functionname = 'core_course_duplicate_course';

$restformat = 'xml';


$params = array(

  'courseid' => 2,

  'fullname' => 'duplicated Introduction to Moodle', // New course full name

  'shortname' => 'dup Introduction to Moodle', // New course shortname

  'categoryid' => 1, // New course category id

  'visible' => 1, // Make the course visible after duplicating

  'options' => array( array('name'=>'activities', 'value'=>1)

                    ) // Backup options

);

/// REST CALL

header('Content-Type: text/plain');

$serverurl = $domainname . '/webservice/rest/server.php'. '?wstoken=' . $token . '&wsfunction='.$functionname;

$curl = new curl;

//if rest format == 'xml', then we do not add the param for backward compatibility with Moodle < 2.2

$restformat = ($restformat == 'json')?'&moodlewsrestformat=' . $restformat:'';

$resp = $curl->post($serverurl . $restformat, $params);

print_r($resp);

Moodle version: 3.3.4

Thank you for all your help.

Best regards,

Anis


Average of ratings: -
In reply to Anis Jradah

Re: core_course_duplicate_course: error/setting_locked_by_permission problem

by Anis Jradah -

Dear All,

I was able to run my code, I just removed the backup options part in $params and a course was duplicated.


Best regards,

Anis