Hello Alan,
I've testet the script with all Moodle 2.X Versions without success. : (
There is an alternative Script package I am acutally testing. Unfortunatitly I am workin with Solaris an the script ist a cli Script based on linux servers. Today I will test it in a XAMPP environment. Hope it works.
Here is the link :https://moodle.org/mod/forum/discuss.php?d=196596
DO you know the scripts from piers Harding? He wrote "uploadcourse tool" a browser-based ( and in the new version also batch-based) Course Upload via csv.
I tried to implement the user restore in his scripts without success:
Here is the link to Piers Scripts:h ttps://github.com/piersharding/moodle-tool_uploadcourse
And here my not working code manipulation in locallib.php. I altered the part where the backupfile is restored in a new created course.
---schnipp----
// after creation/update, do we need to import a Moodle backup?
if (!empty($backupfile)) {
$backupdefaults = array(
'activities' => 1,
'blocks' => 1,
'filters' => 1,
'users' => 1,
'role_assignments'=> 1
);
$backupsettings = array();
// Check for backup and restore options.
// if (!empty($params['options'])) {
foreach ($params['options'] as $option) {
// Strict check for a correct value (allways 1 or 0, true or false).
$value = clean_param($option['value'], PARAM_INT);
if ($value !== 0 and $value !== 1) {
throw new moodle_exception('invalidextparam', 'webservice', '', $option['name']);
}
if (!isset($backupdefaults[$option['name']])) {
throw new moodle_exception('invalidextparam', 'webservice', '', $option['name']);
}
$backupsettings[$option['name']] = $value;
}
//}
// check if tmp dir exists
$tmpdir = $CFG->tempdir . '/backup';
if (!check_dir_exists($tmpdir, true, true)) {
throw new restore_controller_exception('cannot_create_backup_temp_dir');
}
$filename = restore_controller::get_tempdir_name($course->id, $USER->id);
$pathname = $tmpdir . '/' . $filename;
$packer = get_file_packer('application/zip');
$packer->extract_to_pathname($backupfile, $pathname);
// restore the backup immediately
$rc = new restore_controller($filename, $course->id,
backup::INTERACTIVE_NO, backup::MODE_IMPORT, $USER->id, backup::TARGET_CURRENT_ADDING);
foreach ($backupsettings as $name => $value) {
$rc->get_plan()->get_setting($name)->set_status(base_setting::NOT_LOCKED);
$rc->get_plan()->get_setting($name)->set_value($value);
}
// I do not really know what I am making there...
// But If I don't set this to unlocked I got a permission denied error
// wich one is the right one or is there a general setting to unlock the whole array for writing
// $rc->get_plan()->get_setting('users')->set_status(base_setting::NOT_LOCKED);
$rc->get_plan()->get_setting('users')->set_status(backup_setting::NOT_LOCKED);
$rc->get_plan()->get_setting('users')->set_value(1);
$rc->get_plan()->get_setting('role_assignments')->set_status(base_setting::NOT_LOCKED);
$rc->get_plan()->get_setting('role_assignments')->set_status(backup_setting::NOT_LOCKED);
$rc->get_plan()->get_setting('role_assignments')->set_value(1);
// check if the format conversion must happen first
----schnapp----
Hope this helps a bit
Thorsten