Anyone using after_restore_module hook?

Anyone using after_restore_module hook?

by Rex Lorenzo -
Number of replies: 6

Does anyone know of a plugin that implements the restore hook "after_restore_module"? I have a local plugin that needs to perform something on a course module after it has been setup, but I need access to the newly created module and the module in the backup file's information. I created some custom tags in the module's module.xml file.

I tried using the define_module_plugin_structure() hook in the restore class for my plugin, but it appears that the data I set in the module's availability field is getting erased somewhere. So I think I need to do the setting of availability conditions after the module is fully restored.

Average of ratings: -
In reply to Rex Lorenzo

Re: Anyone using after_restore_module hook?

by Juan Ibarra -

Hi Rex, 

I had a similar problem. I needed to update some values on a table after my module was restored. I did exactly what you said: first, implement define_module_plugin_structure() inside my restore class and return the paths for the data being restored and the functions for restoring it. Afterward, implement the after_restore_module() to restore all extra data getting the new module id and course id like this:

$cmid = $this->task->get_moduleid();
list($course, $cm) = get_course_and_cm_from_cmid($cmid, $modulename);

I hope this helps.

 

In reply to Juan Ibarra

Re: Anyone using after_restore_module hook?

by Rex Lorenzo -

When I implemented define_module_plugin_structure() it gets passed a $data object. I am assuming I don't have access to that in after_restore_module(), so I need to store the $data object in a static variable or cache.

Then I can use that data in after_restore_module(). 

Glad I can get the moduleid in after_restore_module() and it is completely setup. So that should help. Would be nice to see a complete implementation by someone in the plugin database.

I am curious what in the restore code wipes out the availability data, because I am seeing that data set  in the scope that define_module_plugin_structure() is called, but not after the restore is done.

In reply to Rex Lorenzo

Re: Anyone using after_restore_module hook?

by Andreas Grabs -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Translators

Hi Rex,

just an idea. I did not try this.

Is it possible for you to create a temporary table during the backup? Then you could implement a course_module_created event listener that allows you to use the previously created temporary table.

Best regards
Andreas

In reply to Andreas Grabs

Re: Anyone using after_restore_module hook?

by Andreas Grabs -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Translators

sorry, I mean during the restore!

In reply to Andreas Grabs

Re: Anyone using after_restore_module hook?

by Rex Lorenzo -

From my understanding the course_module_created event does not trigger during a restore. I already have an event listener for that event to add some availability conditions to new course modules and it is not getting triggered on a restore.

In reply to Rex Lorenzo

Re: Anyone using after_restore_module hook?

by Andreas Grabs -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Translators
You also could use the "course_restored" event what will be fired after finishing the restore. Then you could use the given courseid to check whether your temp table exists or not. The temp table could use the courseid in its name to find it. The name must be unique just in your db session.