General developer forum

delete_instance not called on deleting a resource

 
Picture of Steffen Hippeli
delete_instance not called on deleting a resource
Plugin developers

I found the following bug in my plugin (edusharing):

When i delete a resource from a course the method "edusharing_delete_instance" is not being called. For testing i renamed this method which leads to an error message (something like could not delete because edusharing_delete_instance is not implemented, sounds good).

I put some error_log(), die() right at the beginning of the method with no success.

The response from lib/ajax/service.php?sesskey=fTPZMkSQsA&info=core_course_edit_module (with  payload {index: 0, methodname: "core_course_edit_module", args: {id: 13, action: "delete", sectionreturn: "0"}}) is always [{"error":false,"data":""}]

After deleting the resource is not available in the course anymore but i have to delete it from the DB and inform another application.

Some ideas how to debug this?

Source code can be found here https://github.com/edu-sharing/plugin-moodle/blob/master/mod/edusharing/lib.php beginning at line 305.

Thanks in advance


 
Average of ratings: -
Picture of Steffen Hippeli
Re: delete_instance not called on deleting a resource
Plugin developers

push

 
Average of ratings: -
Picture of Patrick Guillou
Re: delete_instance not called on deleting a resource
 

Hi !

I've got the same problem... mymodule_delete_instance is implemented in lib.php if I rename it I have an error (same thing as you describe)... The module instance is removed from the course but the module itself is not removed from it's DB table... Did you find any solution / workaround ?

Moodle version 3.3.2+ (Build: 20171013)

 
Average of ratings: -
Picture of Steffen Hippeli
Re: delete_instance not called on deleting a resource
Plugin developers

Not yet. I created an issue in the Moodle bugtracker.

 
Average of ratings: -
Davo
Re: delete_instance not called on deleting a resource
Core developersParticularly helpful MoodlersPlugin developers

Have you tried using Xdebug and putting a breakpoint in your function to see if it is being hit?

If that doesn't help, try searching for the place an error is thrown if you don't define the required function and see if you can trace up from there to work out why it isn't being called.

It would also be helpful if you have created a tracker ticket for this to post the ticket link in the forum, so anyone interested can find it without searching.

As an aside, I've written several activity plugins and the instance_delete functions for them were all working the last time I checked - but I don't regularly investigate, so it's always possible (although unlikely?) that this has been broken in recent versions of Moodle.


 
Average of ratings: -
Picture of Steffen Hippeli
Re: delete_instance not called on deleting a resource
Plugin developers

Hi,

so far i had not much time to debug...

I've already created a ticket but it is not published yet, i guess.

 
Average of ratings: -
Davo
Re: delete_instance not called on deleting a resource
Core developersParticularly helpful MoodlersPlugin developers

If you've created a ticket, please copy + paste the ticket URL here, so other users can see it and comment on it.

 
Average of ratings: -
Davo
Re: delete_instance not called on deleting a resource
Core developersParticularly helpful MoodlersPlugin developers

OK - this is a new one for me. It looks like course module deletion is now handed off to an ad-hoc background task if the recycle bin is enabled (as it will need to do a backup of the activity, before it completes the deletion process).

That means that if you want to see the deletion complete, you need to run the Moodle cron script (or disable the recycle bin feature).



 
Average of ratings: Useful (1)
Picture of Steffen Hippeli
Re: delete_instance not called on deleting a resource
Plugin developers
This is the URL to the bug tracker https://tracker.moodle.org/browse/MDL-61008


Is there any other method that will be invoked where i can run my code? The asynchronous cron solution does not fit the needs of my plugin causing integrity issues.

 
Average of ratings: -
Picture of Darko Miletić
Re: delete_instance not called on deleting a resource
Core developersParticularly helpful Moodlers

You have two options:

  1. Disable Recycle bin for courses.
  2. Live with it.

The way async deletion is implemented does not give you any notification that your activity is queued for deletion. You will need to manually check course_modules.deletioninprogress field for any of your activities to actually know.



 
Average of ratings: -
Picture of Steffen Hippeli
Re: delete_instance not called on deleting a resource
Plugin developers

Clear answer - thanks all!

 
Average of ratings: -