core_course_duplicate_course (Web Service)

core_course_duplicate_course (Web Service)

by Syed Nayab Bukhari -
Number of replies: 1
Picture of Core developers

Dear members and seniors

May you all live in peace!

Today, while working with core_course_duplicate_course (web service). I am error given below.

"Notice: Array to string conversion in moodle\bpms\lib\filelib.php on line 3000
invalidparameter Invalid parameter value detected options => Invalid parameter value detected: Only arrays accepted. The bad value is: 'Array'"

My Code is here in below:-

require_once( '../../../lib/zend/Zend/Http/Client/Adapter/Curl.php' );

define( "MOODLE_URL", "http://localhost/bpms/" );

define( "TOKEN_FOR_BUILT_IN_FUNCTIONS", '1e5deac8a0ba32dc542ad7add11df5' );

$params = array(
'courseid' => 4,
'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'=>0)
, array('name'=>'activities', 'value'=>1)
, array('name'=>'filters', 'value'=>0)
, array('name'=>'users', 'value'=>0)
, array('name'=>'userscompletion', 'value'=>0)
, array('name'=>'grade_histories', 'value'=>0)
) // 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;


$curl = new curl;

$response = $curl->post( $serverurl, $params );

echo $response;

 

I am using core_course_duplicate_course  (Web Service) with stable Moodle 2.3. version. I applied all changes, roles, user token, web service use procedure. All done.

bt why this error occur.

filelib.php code from 2977 to 3003 lines

curl_setopt($curl, CURLOPT_HEADERFUNCTION, array(&$this,'formatHeader'));
// set headers
if (empty($this->header)){
$this->setHeader(array(
'User-Agent: MoodleBot/1.0',
'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7',
'Connection: keep-alive'
));
}
curl_setopt($curl, CURLOPT_HTTPHEADER, $this->header);

if ($this->debug){
echo '<h1>Options</h1>';
var_dump($this->options);
echo '<h1>Header</h1>';
var_dump($this->header);
}

// set options
foreach($this->options as $name => $val) {
if (is_string($name)) {
$name = constant(strtoupper($name));
}
curl_setopt($curl, $name, $val);
}
return $curl;
}

 

Waiting for your positive response.

 

Attachment error.jpg
Average of ratings: -
In reply to Syed Nayab Bukhari

Re: core_course_duplicate_course (Web Service)

by Dave Arnold -

I realize this is an old post but I'm not finding much informaiton on this. Does anyone have a working example of core_course_duplicate_course?

I'm attempting to use it on version 2.6 and I keep getting. 

Calling parameters do not match signature

Here is my code

function duplicateCourse($params){
	/// XML-RPC CALL
		header('Content-Type: text/plain');
		$path = $this->server.$this->dir."/webservice/xmlrpc/server.php?wstoken=".$this->token;
		$functionname = 'core_course_duplicate_course';
		$curl = new curl;

		$post = xmlrpc_encode_request($functionname, $params);
		$resp = xmlrpc_decode($curl->post($path, $post));
		print_r($post);
		print_r($resp);
		if(isset($resp['faultCode'])):
			error_log('faultCode '.$resp['faultCode'].' faultString '.$resp['faultString']);
		endif;
	}

$name = "Sample Duplicated Course";
$courseid = 4;
$fullname = $name.' '.date('M d, Y H:i:s');
$shortname = $name.' '.rand(1000,1000000);


$params = array(
'courseid' => $courseid, // Course id to be duplicated 
'fullname' => $fullname, // New course full name
'shortname' => $shortname, // New course shortname
'categoryid' => 3, // 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'=>'filters', 'value'=>1)) // Backup options 
);

duplicateCourse($params);