Backup and Restore plugin within plugin

Backup and Restore plugin within plugin

by Roberto Becerra -
Number of replies: 7
Picture of Plugin developers

Hi there, I am trying to write plugins' backup and restore processes so that we can have a custom activity module plugin, based on the poster plugin, that has a custom block plugin displayed on it. 

The custom block plugin is a 'display a file' type of block. 

I am trying to backup and restore the course these are in, but i cannot backup the custom block plugin's data appropriately. 

The files in are not kept, nor the title or any information from the block are kept. Presumably they are not being saved to the xml file because i checked the backup zip and in the plugin_name.xml document, the <configdata></configdata> section was empty. 

How to handle this situation? 

Thanks in advance! 

Average of ratings: -
In reply to Roberto Becerra

Re: Backup and Restore plugin within plugin

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
In reply to Howard Miller

Re: Backup and Restore plugin within plugin

by Roberto Becerra -
Picture of Plugin developers

Hi Howard, 

Yes, actually I read that and the Backup and Restore 'for developers' documents, but still not very clear how this is working. 

Now I noticed that the 'configdata' is not being stored to the xml, but also it is not saved in the HTML block, not inside an activity, nor inside a course only. 

So now I am wondering why is this configdata not saved??? 

In reply to Roberto Becerra

Re: Backup and Restore plugin within plugin

by AL Rachels -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Have you actually created the backup and restore task.class.php files and the backup and restore stepslib.php files for your plugin? The first time I needed to work on backup and restore for a plugin, I just looked at another similar plugin, such as Journal, to see how it was done.
In reply to AL Rachels

Re: Backup and Restore plugin within plugin

by Roberto Becerra -
Picture of Plugin developers
Hi Al, yes in fact i have created all backup and restore tasks.class and stepslib, but to no avail. I noticed that in the block folder, in the backup zip, there is a 'configdata' tag in the 'block' xml file, which is empty also. As David mentions below it might be an issue with Poster, but that doesn't clear why for instance the HTML block also does not backup.
In reply to Roberto Becerra

Re: Backup and Restore plugin within plugin

by David Mudrák -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators

I suspect this will be a specific problem of the Poster plugin. The Poster creates some areas where blocks can be displayed - similarly to how you can create a block to be displayed at a particular module's page, such as on one Forum's page etc. When you backup a single activity, the backup file also does not include data of the blocks that appear on that activity's page. And this is the same situation. Backup of the Poster instance does not have a way to include other plugins' data.

The only way to achieve this is to use the course backup - not only the one activity backup. Only the course backups can contain multiple items - such as the Poster and the blocks together.

In reply to David Mudrák

Re: Backup and Restore plugin within plugin

by Roberto Becerra -
Picture of Plugin developers
Hi David, thanks for your reply!

Just a quick mention: I am using a course backup functionality, in they way that you suggest, so I get a zip file with subfolders for blocks, activities, and blocks inside such activities, where I can see the xml files for the custom block I am creating.

So, I thought it might be also an issue with Poster, because I am creating a custom version of it.

But, when I tried to compare with for example the HMTL block, it didn't matter if i put it inside the Poster plugin or directly at the top course level, the "configdata" tag in its xml file was empty.

I am also not getting a correct backup of the files in the HTML block.

I am now suspecting it has something to do with how the define_decode_contents(), get_configdata_encoded_attributes() and get_fileareas() functions are implemented. So far they only have an empty "return array();" or "return array('content');"
In reply to Roberto Becerra

Re: Backup and Restore plugin within plugin

by Roberto Becerra -
Picture of Plugin developers
News. For now solved part of the the issue. The part of not saving. The reason had been a php error in another custom plugin, (that was completely elsewhere, not even included in the course being backed up). Corrected the error and this backup, and that of the HTML block also started to save the configdata.

I got a cue from this discussion from a years back: https://moodle.org/mod/forum/discuss.php?d=328219

Still have the issue that the files from my custom display file block are either not backed up or restored. So I actually get the files in the filearea in the file picker ,but they are not displayed from the moment the course is restored. I have to go into the block settings and see the files in the filepicker, click on save and only then I see the files displayed in the block as they should be.

I remember reading this exact same issue somewhere in this forum... and I found it: https://moodle.org/mod/forum/discuss.php?d=315000

But I didn't completely understand how to go around this. In this last link, the user Urs says that is as "easy as to declare the »filearea« where the image gets stored in the »get_fileareas« function in the backup and restore task classes of the block". But I couldn't find the documentation to use that get_fileareas function :/