Hi. I'm back after an absence of about a year and a half, now working with Moodle 2.5. I'm trying to copy a course using the core_course_duplicate_course Web service, but am getting a "base_setting_exception" with the errorcode "setting_locked_by_permission".
My code is at the end of this posting. Most of it is copied from the test example in MDL-34085: Fix the backup options names in core_course_duplicate_course. I'm therefore pretty confident that it's OK. If I give it a non-existent course ID, it tells me so, indicating that it is finding the Web service and the courses in our Moodle. I'm not very familiar with using and administering Moodle, as distinct from programming it, so I want to know whether I might need to set some permission that allows courses to be copied, or to unset some default that prohibits it. Perhaps I need to set a permission on the courses? I can't see anything when I examine them, though. I have given our Web service role every permission that Moodle allows, by ticking all the boxes when I edit it.
This is my code:
define( "MOODLE_URL", "moodle.me.com" ); define( "TOKEN_FOR_BUILT_IN_FUNCTIONS", 'bb586d9beef2c289af91fd9e4stewe7c3' ); $params = array( 'courseid' => 5, 'fullname' => 'core_course_duplicate_course test', // New course full name 'shortname' => 'core_course_duplicate_course', // New course shortname 'categoryid' => 1, // New course category id 'visible' => 1, // Make the course visible after duplicating 'options' => array( array('name'=>'blocks', 'value'=>1) , array('name'=>'activities', 'value'=>1) , array('name'=>'users', 'value'=>1) , array('name'=>'userscompletion', 'value'=>1) , array('name'=>'grade_histories', 'value'=>1), ) // Backup options ); $function_name = 'core_course_duplicate_course'; $token = TOKEN_FOR_BUILT_IN_FUNCTIONS; $serverurl = MOODLE_URL . '/webservice/rest/server.php'. '?wstoken=' . $token . '&wsfunction=' . $function_name; require_once( './curl.php' ); $curl = new curl; $response = $curl->post( $serverurl, $params ); echo $response;
And this is its output:
<?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>
Any ideas?