Notice for block developers

Notice for block developers

by Tim Hunt -
Number of replies: 5
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
If you know about backup and restore in Moodle, you will know that when you create a backup, internal links like
<img src="http://example.com/moodle/file.php/22/mypicture.jpg" />
get encoded as
<img src="$@FILEPHP@$mypicture.jpg" />
Then on restore they get put back, only with the correct course id for the restored course - and similarly for links to activity modules, and so on.

Now this was not being done for links hidden inside blocks sad. This is because the content for, say, an HTML block is stored in the database in the block_instance.configdata column, which contains base64_encode(serialize($this->config)) - which means that the link is totally obfuscated.

I have just fixed this in Moodle 1.9 and HEAD. See MDL-12066 smile. If you block's configdata column may contain links, and if you want them backed up and restored properly, then you will need to implement the methods backup_encode_absolute_links_in_config and restore_decode_absolute_links_in_config in your block class. There is documentation of these methods in the base class in /blocks/moodleblock.class.php, and an good example of the kind of thing you have to do in the HTML block /blocks/html/block_html.php - you will see that what you have to do is actually quite simple, and adding these methods won't stop your block working with older versions of Moodle.

I have only fixed the HTML block, because that was the only one causing pain for our users. Actually, I can't think of any other standard blocks that contain links right now.


Average of ratings: -
In reply to Tim Hunt

Re: Notice for block developers

by Michael Penney -
Hi Tim, why not http://tracker.moodle.org/browse/#MDL-8270 which completely fixes backup and restore for blocks?

The attached diffs add the following functionality to blocks:

- Write to the backup file during the backup routine.
- Encode links during the backup routine.
- Restore its information written to the backup file during the restore routine.
- Decode links during the restore routine.
- Decode content links during restore routine.

Basically, everything a module can do a block can do (in regards to backup/restore).
In reply to Michael Penney

Re: Notice for block developers

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Because I had not seen that bug before. I can't remember what searches I did in the tracker before creating a new issue, but clearly they weren't good enough.

I needed to get the HTML block backup and restore bug fixed, so I discussed it with Eloy who is the backup and restore expert, then did the simplest fix I could do.

This was clearly an important set of patches, so it is a pity that it did not get onto people's radars. I know you assigned it to Martin, but there are nearly 2000 bugs assigned to Martin in the tracker (http://tracker.moodle.org/browse/MDL) so the chances of that getting it noticed are small.

You only marked it as being in Component Blocks. You can select multiple components, so if you had added Backup too, Eloy might have seen it and done something.

You could also have set the fix version/s field to include 1.9, to indicate that you think it should go into that release. That would have got it onto this list: http://tracker.moodle.org/secure/IssueNavigator.jspa?mode=hide&requestId=10251 which would have got people to look at it.

Finally, you could have pingged Martin, or one of the other HQ developers outside the tracker, to ask them look at it.
In reply to Tim Hunt

Re: Notice for block developers

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Instead of blame, let's look forward and get this wider set of patches in. How does it conflict with Tim's quick fix?
In reply to Martin Dougiamas

Re: Notice for block developers

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
I really hope that my post did not come across as trying to blame anyone - but then I was posting late at night.

I was trying to make two points:

1. That it was a real pity that a good patch had remained negelected in the tracker since January. It is entirely understandable, since we all are so busy (especially you, Martin). We should worry about it, and try to stop it happening again.

2. That Mark Nielsen/Michael Penney could have done more to get the patch looked at, and I was trying to be helpful by suggesting some ways that they could have done that.
In reply to Tim Hunt

Re: Notice for block developers

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
No problems, the blame is as much mine as anyone's smile

I've asked Yu to work on integrating these two patches.