How to give modules a way to "refuse deletion"

How to give modules a way to "refuse deletion"

by Joseph Rézeau -
Number of replies: 4
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

1.- On a Moodle course page, when the Delete icon is clicked on an activity, a notice is issued asking for deletion confirmation. If deletion is confirmed by the user, then that activity is deleted, going through the activity's activityname_delete_instance($id) lib function.

2.- However, there may be cases where a given activity instance has dependencies, i.e. other instances (of the same activity) depending on it. The example I am working on at the moment is the Questionnaire add-on, where a "Public" instance has dependent "Private" instances (in other courses). Upon the user deleting a Public instance, I need to issue a warning (and further confirmation) about the potential consequences of the deletion. Maybe there are no other activities (core or add-on) in Moodle that present this problem, but there may well be in the future, so I think this issue must be seriously addressed.

3.- Of course, in my activity's lib activityname_delete_instance($id) function I can conduct tests and return false if my tests say that the instance must not be deleted.

3a.-If AJAX is disabled on the moodle site, the following test in course/lib.php results in an ugly error message being displayed. Something more graceful is really needed!

    // Call the delete_instance function, if it returns false throw an exception.
    if (!$deleteinstancefunction($cm->instance)) {
        throw new moodle_exception('cannotdeletemoduleinstance', '', '', null,
            "Cannot delete the module $modulename (instance).");
    }

One way to do it would be to offer activities a choice of returning, instead of false, some kind of "message" which would get printed by courselib.

3b.- If AJAX is enabled, things look different. No ugly error message is displayed, but the instance seems to have been deleted, but it re-appears upon refreshing the page, which is disconcerting for the user. Also, in that case, it's impossible for the activity to display its own warning or confirmation.

Any ideas?

Joseph

Average of ratings: -
In reply to Joseph Rézeau

Re: How to give modules a way to "refuse deletion"

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hi all,

Here is one more argument in favour of issuing a "delete activity warning" when trying to delete an activity/resource that has "dependencies".

  1. In a course create quiz "Quiz01".
  2. Create another quiz "Quiz02".
  3. In Quiz02, set Restrict access condition to Quiz01 grade "must be at least" 50%.
  4. Now delete Quiz01.
  5. Quiz02 shows: Not available until you achieve a required score in !missing.

May I insist that the "delete activity/resource" feature should be modified in Moodle core to provide a warning in this case (as well as in the case of Questionnaire dependencies described in my original post).

Please vote for MDL-43868.

Joseph

 

Average of ratings: Useful (2)
In reply to Joseph Rézeau

Re: How to give modules a way to "refuse deletion"

by Séverin Terrier -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators

Hi,

As Joseph shows, it's (in my opinion) really a problem that an activity can be deleted, even if it's part of a condition of accessibility for another activity sad

There should at least be a warning !

Séverin

In reply to Séverin Terrier

Re: How to give modules a way to "refuse deletion"

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

I posted this request almost a year ago and got no answer so far. sad

Joseph