-
Bug
-
Resolution: Fixed
-
Critical
-
3.3.4, 3.4.1, 3.5
-
MOODLE_33_STABLE, MOODLE_34_STABLE, MOODLE_35_STABLE
-
MOODLE_33_STABLE, MOODLE_34_STABLE
-
wip-
MDL-61268-master -
I discovered this while debugging failures of block_html in Moodle 3.4.1 on php 7.1. Text blocks were not rendered at all unless edit mode was turned on, when the blocks appeared but were empty and all had the title set to default. With debug messages turned on i got lots of 'Notice: block_html::specialization(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "object" of the object you are trying to operate on was loaded before unserialize() gets called or provide a __autoload() function to load the class definition in /some/path/moodle/blocks/html/block_html.php on line 40 '.
I found out that the db field configdata in table block_instances contains serialized objects of type 'stdClass' (which do not fail on being unserialized) but also of type 'object' which is no longer part of the Moodle core since 3.4 (MDL-60281). Therefore unserialize classifies the latter objects as being of type __PHP_Incomplete_Class.
Steps to reproduce and fix:
1. have a text block in your moodle with serialized configdata of type object (probably created before update to Moodle 3.4). If you don't have one you might set the configdata field in table block_instances to 'Tzo2OiJvYmplY3QiOjM6e3M6NToidGl0bGUiO3M6MjQ6Ik15IHByZXR0aWVzdCBibG9jayB0aXRsZSI7czo2OiJmb3JtYXQiO3M6MToiMSI7czo0OiJ0ZXh0IjtzOjIwOiJNeSBwcmV0dGllc3QgY29udGVudCI7fQo=' (without quotes).
2. check moodle page (block is not visible)
3. check moodle page with editmode turned on (block is visible but empty and has default title)
4. check moodle page with debugging messages turned on (php NOTICE appears, see above)
5. set the configdata field to the fixed value (type stdClass) 'Tzo4OiJzdGRDbGFzcyI6Mzp7czo1OiJ0aXRsZSI7czoyNDoiTXkgcHJldHRpZXN0IGJsb2NrIHRpdGxlIjtzOjY6ImZvcm1hdCI7czoxOiIxIjtzOjQ6InRleHQiO3M6MjA6Ik15IHByZXR0aWVzdCBjb250ZW50Ijt9Cg==' (without quotes)
6. check moodle page (block is visible as expected)
7. check moodle page with editmode turned on (block is visible as expected)
8. check moodle page with debugging messages turned on (no debug message appears)
base64-decoded values:
O:6:"object":3:{s:5:"title";s:24:"My prettiest block title";s:6:"format";s:1:"1";s:4:"text";s:20:"My prettiest content";}
O:8:"stdClass":3:{s:5:"title";s:24:"My prettiest block title";s:6:"format";s:1:"1";s:4:"text";s:20:"My prettiest content";}
Fix/Question:
I have converted all block_html->configdata entries of type object to type stdClass manually which restored the expected behaviour. I have read comments somewhere and in MDL-60281 so that i am quite confident that this is a legitimate fix. Might there be a better fix anyway? How is this gonna be fixed by moodle upgrade routines?
Implications:
This issue might also affect other blocks which store(d) their configdata as serialized values of type object. See for example MDL-60778 Flickr block notice block_tag_flickr::get_content(). Though i did not verify my findings for that issue.
Could there be other places where moodle hides serialized objects of type object aside from block->configdata?