Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-61268

Regression: Removal of class object versus serialized block->configdata of type object

XMLWordPrintable

    • MOODLE_33_STABLE, MOODLE_34_STABLE, MOODLE_35_STABLE
    • MOODLE_33_STABLE, MOODLE_34_STABLE
    • wip-MDL-61268-master
    • Hide

      This test requires access to the database - It should also be done before upgrading to the latest version.

      Upgrade test.

      1. Create a course.
      2. Add an HTML block to the course.
      3. Edit the block and add some content.
      4. Go to your database and look at the block_instances table.
      5. Find the record for the HTML block and edit it. Change the configdata to -

        Tzo2OiJvYmplY3QiOjM6e3M6NDoidGV4dCI7czozMjoiTm90aGluZyB0aGF0IGFueW9uZSBjYXJlcyBhYm91dC4iO3M6NToidGl0bGUiO3M6MTY6IlJlYWxseSBvbGQgYmxvY2siO3M6NjoiZm9ybWF0IjtzOjE6IjEiO30=
        

      6. If you refresh the course page then you should see a notice about block_html::specialization() etc.
      7. Update your instance to the latest version.
      8. Go back to the course and check that the notices no longer appear.

      Restore test.

      1. Restore the old19withblock.zip file into a new course.
      2. Check that there are no notices / errors with the restore and that there is an HTML block in the restored course.
      Show
      This test requires access to the database - It should also be done before upgrading to the latest version. Upgrade test. Create a course. Add an HTML block to the course. Edit the block and add some content. Go to your database and look at the block_instances table. Find the record for the HTML block and edit it. Change the configdata to - Tzo2OiJvYmplY3QiOjM6e3M6NDoidGV4dCI7czozMjoiTm90aGluZyB0aGF0IGFueW9uZSBjYXJlcyBhYm91dC4iO3M6NToidGl0bGUiO3M6MTY6IlJlYWxseSBvbGQgYmxvY2siO3M6NjoiZm9ybWF0IjtzOjE6IjEiO30= If you refresh the course page then you should see a notice about block_html::specialization() etc. Update your instance to the latest version. Go back to the course and check that the notices no longer appear. Restore test. Restore the old19withblock.zip file into a new course. Check that there are no notices / errors with the restore and that there is an HTML block in the restored course.

      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?

            abgreeve Adrian Greeve
            misc Dr. Michael Schneider
            Mihail Geshoski Mihail Geshoski
            Andrew Lyons Andrew Lyons
            David Monllaó David Monllaó
            Votes:
            2 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.