by Iñaki Arenaza.
Hi,
I've been playing a bit with that function, and this is what I've come up with (as a really simple skeleton). I use the default values for the backups, i.e., no user enrolments cloning, or grade history, or user completion, etc. but they could work (I think there's a small bug in core_course_external::duplicate_course(), but I'm not 100% sure as I don't master the web services code).
<?php
define('CLI_SCRIPT', 1);
require_once(dirname(__FILE__).'/config.php');
require_once($CFG->dirroot . '/course/externallib.php');
// The id of the course we are importing FROM
$importcourseid = 2;
// The id of category where we want to place the CLONED course into.
$categoryid = 1;
// If the CLONED course should be visible or not.
$visible = 1;
// The CLONEing options (these are the defaults).
$options = array(
array ('name' => 'activities', 'value' => 1),
array ('name' => 'blocks', 'value' => 1),
array ('name' => 'filters', 'value' => 1),
);
// To simplify the skeleton code, let's run the whole thing as an admin. You probably *don't*
// want to do this in production code.
$USER = get_admin();
try {
$newcourse = core_course_external::duplicate_course($importcourseid,
'The new course full name',
'The-Shortname',
$categoryid,
$visible,
$options);
} catch (exception $e) {
// Some debugging information to see what went wrong
var_dump($e);
}
echo 'Cloned new course with shortname "'. $newcourse['shortname'] . '" and id "' . $newcourse['id'] . "\"\n";
I've only tried with very simple courses (just some resources, a forum, some tasks and a couple of wikis), but it works reliably for me.
Saludos.
Iñaki.
I've been playing a bit with that function, and this is what I've come up with (as a really simple skeleton). I use the default values for the backups, i.e., no user enrolments cloning, or grade history, or user completion, etc. but they could work (I think there's a small bug in core_course_external::duplicate_course(), but I'm not 100% sure as I don't master the web services code).
<?php
define('CLI_SCRIPT', 1);
require_once(dirname(__FILE__).'/config.php');
require_once($CFG->dirroot . '/course/externallib.php');
// The id of the course we are importing FROM
$importcourseid = 2;
// The id of category where we want to place the CLONED course into.
$categoryid = 1;
// If the CLONED course should be visible or not.
$visible = 1;
// The CLONEing options (these are the defaults).
$options = array(
array ('name' => 'activities', 'value' => 1),
array ('name' => 'blocks', 'value' => 1),
array ('name' => 'filters', 'value' => 1),
);
// To simplify the skeleton code, let's run the whole thing as an admin. You probably *don't*
// want to do this in production code.
$USER = get_admin();
try {
$newcourse = core_course_external::duplicate_course($importcourseid,
'The new course full name',
'The-Shortname',
$categoryid,
$visible,
$options);
} catch (exception $e) {
// Some debugging information to see what went wrong
var_dump($e);
}
echo 'Cloned new course with shortname "'. $newcourse['shortname'] . '" and id "' . $newcourse['id'] . "\"\n";
I've only tried with very simple courses (just some resources, a forum, some tasks and a couple of wikis), but it works reliably for me.
Saludos.
Iñaki.