Preventing restore of an activity when no user data selected

Preventing restore of an activity when no user data selected

by Jennifer Edmondson -
Number of replies: 2

I was wondering if somebody could help me prevent the restore of a Moodle activity without user data (in particular gracefully prevent the 'duplicate' function).

Background:

Adobe Connect activities are linked to an Adobe Connect meeting on an external server. A shortcut ID (SCOID) is used to identify which meeting the activity is linked to, and the activity displays a button to join said meeting and display any recordings. By default, restored (with or without user data), the new Adobe Connect activity is linked to the same SCOID as the original activity.

Example scenario: You have an established course with an AC activity with recordings. You create a new course which you want to base off the first one. You import its course content (which does not bring across user data) into the new site. You enter the AC activity in the new course and realise that it has recordings attached to it from the first course.

Possible solutions:

The only solution I can see (in the case where 'no user data' is selected) is to either:
1. Create a new (fresh) meeting on the AC server and point to that (this has some difficulties to do with how to name it (especially in group mode). The new meeting can't have the same name on the AC server, and there are other limitations (for example a very short allowable title length (60 characters including group names in group mode)) that would be difficult to pick up on/resolve without manual involvement)).
2. Do not bring over the activity at all.

I would like to go with option #2 for now, as it best fits the immediate needs of our users. I'd rather have AC activities re-created by hand as necessary than inadvertantly expose other courses' recordings. The goal would to eventually implement #1.

Attempted solution:

https://github.com/jamedmondson/moodle-mod_adobeconnect/commit/7bc44f78bd171f482062cbe3ebfb465aca55b69e

This solution works for:

  1. A course backup/restore (restores Adobe Connect activities where 'user data' selected, doesn't restore Adobe Connect activities where 'user data' not checked)
  2. A course import (doesn't restore Adobe Connect activities)

However, it doesn't work for:

     3.  Gracefully preventing the 'duplication' of an activity. When you try to duplicate an activity with my attempted solution, Moodle throws the following error:

Can not find data record in database.

More information about this error

Debug info: SELECT cm.*, m.name, md.name AS modname , cw.section AS sectionnum
FROM {course_modules} cm
JOIN {modules} md ON md.id = cm.module
JOIN {adobeconnect} m ON m.id = cm.instance
LEFT JOIN {course_sections} cw ON cw.id = cm.section
WHERE cm.id = :cmid AND md.name = :modulename
AND cm.course = :courseid
[array (
'cmid' => 30,
'modulename' => 'adobeconnect',
'courseid' => '5',
)]
Stack trace:
  • line 1300 of /lib/dml/moodle_database.php: dml_missing_record_exception thrown
  • line 1402 of /lib/datalib.php: call to moodle_database->get_record_sql()
  • line 109 of /course/modduplicate.php: call to get_coursemodule_from_id()

So, I guess I'd like to know:

  1. Is there a better way for me to prevent the restore of a Moodle activity when 'no userdata' is selected?
  2. Is it possible to have the 'duplicate activity' functionality fail gracefully?
  3. Does anyone have any creative ideas on how to deal with backing up/restoring a Moodle activity without user data when the user data sits on external server?
  4. Does anyone have an example of another module that achieves something similar to what I am trying to achieve that I can learn from?

Tracker Job (more detailed information including use cases): http://tracker.moodle.org/browse/CONTRIB-3563

Thank you!

Average of ratings: -
In reply to Jennifer Edmondson

Re: Preventing restore of an activity when no user data selected

by Jennifer Edmondson -

This is how I ended up addressing the issue:

Description of the issue(s) from the aforementioned fix (https://github.com/jamedmondson/moodle-mod_adobeconnect/commit/7bc44f78bd171f482062cbe3ebfb465aca55b69e)
---------------------------------------------------------------------------------
1. It was causing an error when you tried to duplicate an activity ("Can not find data record in database.")
2. During course backup/restore without userdata, there was an orphan record in the course_modules table

Resolution
---------------------------------------------------------------------------------
1. This was very difficult, because the core duplicate functionality (in modduplicate.php) would fail if it couldn't find the ID of the new activity (which we are trying to prevent, as duplicating an activity is supposed to create a new activity with the same settings but no userdata, which isn't currently possible with Adobe Connect). The only way to fix this without modifying core Moodle functionality was to identify when modduplicate.php was attempting a backup/restore of an adobe connect activity and stop it. You now get an error message saying "Adobe Connect activities cannot be duplicated. Please create a new activity instead." and a "Continue" button which takes you back to the course page.
2. Remove the database entry in restore_adobeconnect_activity_structure_step::after_execute() if no userdata selected for that activity

 

I have updated http://tracker.moodle.org/browse/CONTRIB-3563 with the patch / link to github repo for the final fix.

Any comments are welcome. The way I prevented duplication is a bit of a hack but I couldn't find an elegant way to flag that a particular module's activities cannot be duplicated (so that it doesn't fail ungracefully) without modifying core code. And realistically, this is not likely to be a common situation for modules.