Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.8.5, 1.9
-
Fix Version/s: 1.9.8
-
Component/s: Blocks
-
Labels:None
-
Environment:Servers: MySQL 5, Apache 2.0.59 on Windows and Ubuntu
Browsers: IE6 & Firefox 2
-
Affected Branches:MOODLE_18_STABLE, MOODLE_19_STABLE
-
Fixed Branches:MOODLE_19_STABLE
Description
We've been experiencing unpredicatble behaviour with our blocks as well. By default, we have the following blocks displayed in a course view:
People HTML Block
Activities Latest News
Search Forums Upcoming Events
Administration Recent Activity
Course Categories
With editing turned on, moving blocks between columns, and up or down within a column, means that some blocks disappear. For instance, if I move "Recent Activity" to the left column, "Search Forums" will disappear. As soon as it disappears, it is included in the drop-down list of blocks that can be added.
So I add it back again. It appears in the right-hand column. If I then try to move "Recent Activity" up one position in the left-hand column, it disappears, only to be replaced by "Search Forums". This means there are two instances of "Search Forums" and no instances of "Recent Activity".
I've tagged this as Major because it's worrying our users a lot.
You can recreate this problem on our test server:
http://elearning.lse.ac.uk/moodle-1.8/course/view.php?id=63
Log in as "moodletracker" with password "moodletracker"
Attachments
Issue Links
| This issue will help resolve: | ||||
| MDL-13859 | AJAX for dropping boxes onto the right column is broken (fix inside) |
|
|
|
| This issue is duplicated by: | ||||
| MDL-19204 | Adding/removing course sticky blocks causes blocks to disappear from front page |
|
|
|
| This issue has been marked as being related by: | ||||
| MDL-19204 | Adding/removing course sticky blocks causes blocks to disappear from front page |
|
|
|
The problem, at least as far as it occurs when moving blocks up and down, is caused by a bug in /lib/blocklib.php.
The code to move blocks up and down is in the function blocks_execute_action(). This uses the $pageblocks array, which in this case is created by the function blocks_get_by_page_pinned().
Now, when moving a block ($instance) up, blocks_execute_action() [line 553] tries to find the block above ($other), and move it down so that the 2 blocks swap positions. However, it does this by using ($instance->weight - 1) as an key in $pageblocks. This doesn't work, because blocks_get_by_page_pinned() has constructed $pageblocks by simply sticking the pinned and user blocks together in a single array, without accounting for that fact that the values of 'weight' for pinned and user blocks can be the same.
Therefore blocks_execute_action() fails to identify the correct block to move down and, depending on the number of pinned and user blocks on that side, we get all sorts of weird results.
The attached patch is only a temporary fix. It sidesteps the issue by searching backwards from the end of $pageblocks to make sure that the first match it finds is a user block, not a pinned block.
However the real solution must be to make sure that the array of blocks received by blocks_execute_action() properly distinguishes between pinned and user blocks - perhaps 2 arrays should be passed. I haven't dared to start messing with $pageblocks as it is used throughout this script. I think a proper fix needs to be done by someone with a wider understanding of blocklib.php than I have.