import_course call error: Invalid parameter value detected: Only arrays accepted.

import_course call error: Invalid parameter value detected: Only arrays accepted.

by Alan Zaitchik -
Number of replies: 2

I am experimenting developing a script hoping to use the core_course_external::import_course function to import blocks and activities from a template course into others.

I am getting an exception on the 4th parameter ($options) that this method expects, which is an array of import options. (I traced the execution to the generic parameter checking in the validate_parameters method in /lib/externallib.php. The error message is detailed in the var_dump of the exception (See attached.)

What I find baffling is that I am clearly passing in an array, as follows!

$importfrom = 23;
$importto = 15;
$deletecontent=1;
$options = array(
    "activities" => 1,
    "blocks" => 1  ,
    "filters" => 1
);

...
try {
    $newcourse = core_course_external::import_course($importfrom,
        $importto,
        $deletecontent,
        $options); 

catch (exception $e) {
    var_dump($e);
}

In fact I added print_r($params); to the code in /lib/externallib.php just to see what it is getting, and I see

Array ( [importfrom] => 23 [importto] => 15 [deletecontent] => 0 [options] => Array ( [activities] => 1 [blocks] => 1 [filters] => 1 ) )

So where is the invalid parameter? I must be missing something obvious. If anyone can help I will surely be grateful!

Alan

I am attaching the var_dump in case anyone can take a look.

Average of ratings: -
In reply to Alan Zaitchik

Re: import_course call error: Invalid parameter value detected: Only arrays accepted.

by Ângelo Rigo -

Hi 

Using this script it works :

<?php
include("../config.php");
require_once($CFG->dirroot . '/course/lib.php');
require_once($CFG->dirroot . '/course/externallib.php');
$importfrom = 2;
$importto = 3;
try {
$newcourse = core_course_external::import_course($importfrom,$importto);
}catch(exception $e) {
print_object($e);
}
?>

In fact you do not need the 2 last parameters. 

Cheers 

In reply to Ângelo Rigo

Re: import_course call error: Invalid parameter value detected: Only arrays accepted.

by Ângelo Rigo -

If you really need to control the options params use this format : 'options' => array(array('name'=>'blocks', 'value'=>1), array('name'=>'activities', 'value'=>1), array('name'=>'filters', 'value'=>1)) // Backup options );