import activities and resources from one course to multiple courses

import activities and resources from one course to multiple courses

by Shivanesh Lal -
Number of replies: 3

Hi experts,

is it possible to import activities and resources from one course to multiple courses in moodle? 

Average of ratings: -
In reply to Shivanesh Lal

Re: import activities and resources from one course to multiple courses

by Neill Magill -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers
Depends on what you mean:

You can use the Import functionality in each coarse separately, or you can backup (without user data from one course) and then restore that file into multiple courses.

But doing it as a single process/step for an end user is not something currently part of Moodle,.. it is probably possible to develop something that would though.
In reply to Neill Magill

Re: import activities and resources from one course to multiple courses

by Shivanesh Lal -
Thanks for your response Neill, 

what I actually mean is I want to import activity to multiple courses (over100 courses)

so far what I have done is:
1. created a blank course and added the activity I want to be imported to the other courses.
2. removed all other blocks from the course so when importing it only the activity goes with it.

I have created a script using the core_course_import_course REST API service sharing the code below: 
_______________________________________________________________________________
<?php

$token = 'Tokan goes here';

$domainname = 'https://my.Moodle.url';

$functionname = 'core_course_import_course';

$params = array('importfrom' => 1736,

'importto'=> 1739,

'deletecontent'=>0,

'options'=>array(array('name'=>'blocks', 'value'=>'0'), 

array('name'=>'activities', 'value'=>'1'), 

array('name'=>'filters', 'value'=>'0')) 

);

/// REST CALL

header('Content-Type: text/plain');

$serverurl = $domainname . '/webservice/rest/server.php'. '?wstoken=' . $token . '&wsfunction='.$functionname;

require_once('./curl.php');

$curl = new curl;

$restformat = ($restformat == 'json')?'&moodlewsrestformat=' . $restformat:'';

$resp = $curl->post($serverurl . $restformat, $params);

print_r($resp);

?>

------------------------------------------------------------------------------------------------------------------------------------------------------------------

I am successfully able to import the activity now my situation is I have multiple course Id's I am trying to figure out what would be the best possible way to import it to all the remaining courses.


In reply to Shivanesh Lal

Re: import activities and resources from one course to multiple courses

by Ken Task -
Picture of Particularly helpful Moodlers

moosh (cli only) has a restore command.

https://moosh-online.com/commands/
course-restore

Restore course from path/to/backup.mbz to category or existig course.

Example 1: Restore backup.mbz into category with id=1

moosh course-restore backup.mbz 1

Example 2: Restore backup.mbz into existing course with id=3

moosh course-restore -e backup.mbz 3

one could create a looping bash shell script for the changing course ID numbers and get a lot done in a short time frame ... that's after testing one or two restores to see if it 'fits'.

'SoS', Ken