Blocks: Restore courses from remote Moodles

Maintained by Picture of Céline PervesCéline Perves
block my_external_backup_courses : Restore courses from remote moodle platforms my_external_backup_restore_courses is a Moodle block that enable a user to restore courses from external moodles this block must be installed in each moodle course clients and course servers involved
14 sites
11 fans
Current versions available: 2

# block my_external_backup_courses : Restore courses from remote moodle platforms

my_external_backup_restore_courses is a Moodle block that enable a user to restore courses from external moodles
this block must be installed in each moodle course clients and course servers involved

## Features

  * enable a user to program course restoration where courses comes from external moodles
  * possibility to find the original category based on unique category identifier threw plugin settings on database relation (user must hace moodle/course:create in the category context)
  * restore cours in a default category (user must hace moodle/course:create in that context)
  * a scheduled task will launch remote backups and restorations of these courses
  * Log and messaging include to notify of succes or failure


We use this block to enable teachers of our university to transfert their courses from an yearly archived version of moodle to a new empty moodle platform.

This is also usefull while migrationg a platform :

we migrate the platform, archve it (hide it) and let teacher retrieve therir courses from the new empty platform thanks to this block

## Security warning

* This plugin use a capability block/my_external_backup_restore_courses:can_retrieve_courses that enable webservice account to donload backup files of other users
* To improve security it is strongly recommended to generate token with IPrestriction on server side IPs

## mnet warning usage

this plugin may not work in MNet environments fully because the username in that conditions username is not unique

## Download

from moodle plugin repository

## Installation

### Block installation

Install block on blocks directory in course clients moodles and in each course servers moodle you need to connect to

### webservice settings

On moodles that serves courses
* create role for webservice
  * add the protocol rest capability to this role webservice/rest:use
  * add capabilility block/my_external_backup_restore_courses:can_retrieve_courses
  * add capbility block/my_external_backup_restore_courses:can_see_backup_courses
 * Create a user account for webservice account
* assign role on system context for this newly created account
* Under webservice administration :
  * Under Site administration -> Plugins -> Web Services -> External services, add a new custom service
    * check Enabled
    * ckeck Authorised users only
    * check  Can download files
    * select capability block/my_external_backup_restore_courses:can_see_backup_courses
  * once created add funtions to the new custom external service
    * core_webservice_get_site_info
    * block_my_external_backup_restore_courses_get_courses
    * block_my_external_backup_restore_courses_get_courses_zip
  *  add the webservice user account created previously to the authorized users of the new custom service
  * Under Site administration -> Plugins -> Web Services -> Manage Tokens
    * create a new token, restrited on your php server(s) for the custom external sservice previously created
    * This token will be one to enter in the block parameters off block_my_external_backup_restore_courses

### Block setting

Under Plugins -> Blocks -> Restore courses from remote Moodles
For each moodles you need to fill the following setting parameters

  * in my_external_backup_course | search_roles enter roles to include in course search simple quote delimited text shortname separated by commas
  * in my_external_backup_course | restorecourseinoriginalcategory activate the mode that enable to try to search the original category of a remote course
  * in my_external_backup_course | categorytable the database table name where to find unique identifier information in order to search/find category, common for both client and server moodles
  * in my_external_backup_course | categorytable_foreignkey the database foreign key for categorytable
  * in my_external_backup_course | categorytable_categoryfield the database field in categorytable unique for a category and common for both client and server moodles

course clients moodles
  * in my_external_backup_course | defaultcategory the categoryid where the course will be restored by default, users that restore must have capability to moodle/course:create
  * in my_external_backup_course | externalmoodles formatted list of course servers moodles formatted as moodle_url1,token_compte_webservice_moodle_externe1;moodle_url2,token_compte_webservice_moodle_externe2;...

### Messaging

  * Site administration / ► Plugins / ► Message outputs / ► Default message outputs
  * 2 message outputs :
    * Notify that an external course as failed to restore
    * Notify that an external course is successfully restored
  * by default allowed and permitted for mails

### capability

in order to use this block in dashboard a capability block/my_external_backup_restore_courses:view is provided and by default allowed for coursecreator and manager profile
This enable to controle block visibility in dashboard

## Contributions

Contributions of any form are welcome. Github pull requests are preferred.

Fill any bugs, improvements, or feature requiests in our [issue tracker][issues].

## License

* GNU GPL v3 or later


Screenshot #0


Picture of Céline Perves
Céline Perves (Lead maintainer)
Please login to view contributors details and/or to contact them

Comments RSS

Show comments
  • Picture of Mike Churchward
    Wed, Nov 2, 2016, 9:39 PM
    Hi Celine. I read your comments, and I'm still unclear on what those settings should be. Are you saying you use them because you have non-standard tables in Moodle to store category information? If so, it is unlikely that someone installing this plugin would have the same non-standard tables.
    If these settings are intended to override using standard Moodle tables, it would be best if they defaulted to what would be used in a standard Moodle install.

    So, I think it would be:
    "Database table name where category informations are stored" = 'course_categories".
    "Database table foreign key for category id" = 'id'.
    ""Unique database table field that represent category..." = ?? (I don't know what this would be)
  • Picture of Céline Perves
    Wed, Nov 2, 2016, 11:12 PM
    to work since you have 2 moodles you need to be sure that you have a unique category identifier common for that two moodles.
    Since id can't be garanted to be the same (since generated by database) two make the category retreieving to work you need a field with this unique value. I suggest to put idnumber.
    I can put what you ask as default values for settings since it would be a default case
  • Picture of Mike Churchward
    Thu, Nov 3, 2016, 12:17 AM
    So, you are saying:
    "Database table name where category informations are stored" = 'course_categories".
    "Database table foreign key for category id" = 'idnumber'.

    That makes sense. But what should be set for:
    "Unique database table field that represent category..."
  • Picture of David Mudrák
    Thu, Nov 3, 2016, 3:47 PM

    I'll have to put tool_my_external_backup_restore_courses_admin in the block plugin distribution

    No, sorry for not being clear. It was actually meant as a note for ourselves (me and Mike) that these two dependent plugins are best to be reviewed together. We can't approve the dependent one without having the other one approved first.

  • Picture of Céline Perves
    Thu, Nov 3, 2016, 3:55 PM
  • Picture of Céline Perves
    Thu, Nov 10, 2016, 10:20 PM
    too much impact if I correct all code style errors and warning.
    I tried to do this but the risk to make in unstable while in production on our moodle is too high
  • Picture of Céline Perves
    Thu, Nov 10, 2016, 10:20 PM
    I changed the default value as asked and change the documentation to be a little more comprehensive
  • Picture of David Mudrák
    Sat, Dec 3, 2016, 6:01 PM

    Thanks Céline for sharing the plugin. I have published it now.

  • Picture of Céline Perves
    Tue, Dec 6, 2016, 5:54 PM
    Thak you, Hope it will be as usefull as in our case.
  • Picture of Jacques Barzic
    Wed, Jan 17, 2018, 11:19 PM
    For testing, I'v install block_my_external_backup_restore_courses on two Moodle, one like "server", one like "client".
    I follow exactly the install process.
    On the client, the user see the list of courses there are possible to restore.
    But after the restore it give an error status for the course in the list and the courses is not restore.
    For my tests, I launch manually the cron. In the log of the cron there is this : "file retrieve : no files in zip".

    Perhaps I'ave forgot something.
    Can you help me ?

    Best regards,

  • Picture of Céline Perves
    Thu, Jan 18, 2018, 9:58 PM
    Hi, in order to help you
    Are your two moodles client and server in same version?
    is the token correctly configured beetween to servers?
    Whate are your parameters?
    What are the errors in notification?
  • Picture of Jacques Barzic
    Thu, Jan 18, 2018, 11:27 PM
    Hi Céline,
    Thanks for your reply.
    The two Moodles' version is 3.0.10 (Build : 20170508).
    For the token : the toked created on server is set in client in "external moodle list to connect to" with the server's URL.
    In the notification the error is "file retrieve : no files in zip".

    For the parameters, you can see sreanshoots here :

    Thanks for your help.

  • Picture of Jean-François PETIT
    Thu, Mar 8, 2018, 11:14 PM
    I follow this plug in and some erreur with the Cron
    Execute scheduled task: tâche du plugin restaurer vos cours depuis des Moodle distants (block_my_external_backup_restore_courses\task\backup_restore_task)
    ... started 15:56:39. Current memory use 9.9Mo.
    ... used 37 dbqueries
    ... used 3.9998121261597 seconds
    Scheduled task failed: tâche du plugin restaurer vos cours depuis des Moodle distants (block_my_external_backup_restore_courses\task\backup_restore_task),error/setting_by_name_not_found
    * line 97 of /backup/util/plan/base_task.class.php: call to base_plan->get_setting()
    * line 439 of /blocks/my_external_backup_restore_courses/locallib.php: call to base_task->get_setting()
    * line 322 of /blocks/my_external_backup_restore_courses/locallib.php: call to block_my_external_backup_restore_courses_task->restore_course_from_backup_file()
    * line 25 of /blocks/my_external_backup_restore_courses/classes/task/backup_restore_task.php: call to block_my_external_backup_restore_courses_task_helper::run_automated_backup_restore()
    * line 104 of /lib/cronlib.php: call to block_my_external_backup_restore_courses\task\backup_restore_task->execute()
    * line 292 of /lib/cronlib.php: call to cron_run_inner_scheduled_task()
    * line 91 of /admin/tool/task/schedule_task.php: call to cron_run_single_task()
  • Picture of Azmat Ullah
    Thu, May 9, 2019, 5:37 PM
    Hi Celline,

    I'm also facing same problem as Jacques mentioned above.

    I'm using Moodle3.5.2 as client and Moodle3.6 as server.

  • Picture of Céline Perves
    Mon, May 13, 2019, 3:23 PM
    Hello, I am migrating this plugin into 3.5 version and will publish it as soon as possible
    But you mus'nt use this plugin with 2 different version of moodle
1 2
Please login to post comments