mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 05:58:34 +01:00
MDL-61268 blocks: Fix corrupt configdata in block instances.
Old configuration data in the block instances is base64 encoded with the deprecated object class instead of stdClass.
This commit is contained in:
parent
856e07e4e7
commit
e78849e837
@ -30,9 +30,13 @@ defined('MOODLE_INTERNAL') || die();
|
|||||||
class moodle1_block_html_handler extends moodle1_block_handler {
|
class moodle1_block_html_handler extends moodle1_block_handler {
|
||||||
private $fileman = null;
|
private $fileman = null;
|
||||||
protected function convert_configdata(array $olddata) {
|
protected function convert_configdata(array $olddata) {
|
||||||
|
global $CFG;
|
||||||
|
require_once($CFG->libdir . '/db/upgradelib.php');
|
||||||
$instanceid = $olddata['id'];
|
$instanceid = $olddata['id'];
|
||||||
$contextid = $this->converter->get_contextid(CONTEXT_BLOCK, $olddata['id']);
|
$contextid = $this->converter->get_contextid(CONTEXT_BLOCK, $olddata['id']);
|
||||||
$configdata = unserialize(base64_decode($olddata['configdata']));
|
$decodeddata = base64_decode($olddata['configdata']);
|
||||||
|
list($updated, $configdata) = upgrade_fix_serialized_objects($decodeddata);
|
||||||
|
$configdata = unserialize($configdata);
|
||||||
|
|
||||||
// get a fresh new file manager for this instance
|
// get a fresh new file manager for this instance
|
||||||
$this->fileman = $this->converter->get_file_manager($contextid, 'block_html');
|
$this->fileman = $this->converter->get_file_manager($contextid, 'block_html');
|
||||||
|
@ -1973,5 +1973,14 @@ function xmldb_main_upgrade($oldversion) {
|
|||||||
upgrade_main_savepoint(true, 2018020500.00);
|
upgrade_main_savepoint(true, 2018020500.00);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($oldversion < 2018022800.01) {
|
||||||
|
|
||||||
|
// Fix old block configurations that use the deprecated (and now removed) object class.
|
||||||
|
upgrade_fix_block_instance_configuration();
|
||||||
|
|
||||||
|
// Main savepoint reached.
|
||||||
|
upgrade_main_savepoint(true, 2018022800.01);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -502,3 +502,40 @@ function upgrade_block_positions() {
|
|||||||
WHERE pagetype IN ('my-index', 'user-profile') AND subpage NOT IN (SELECT $id FROM {my_pages})";
|
WHERE pagetype IN ('my-index', 'user-profile') AND subpage NOT IN (SELECT $id FROM {my_pages})";
|
||||||
$DB->execute($sql, ['']);
|
$DB->execute($sql, ['']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fix configdata in block instances that are using the old object class that has been removed (deprecated).
|
||||||
|
*/
|
||||||
|
function upgrade_fix_block_instance_configuration() {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
$sql = "SELECT *
|
||||||
|
FROM {block_instances}
|
||||||
|
WHERE configdata <> ''";
|
||||||
|
$blockinstances = $DB->get_recordset_sql($sql);
|
||||||
|
foreach ($blockinstances as $blockinstance) {
|
||||||
|
$configdata = base64_decode($blockinstance->configdata);
|
||||||
|
list($updated, $configdata) = upgrade_fix_serialized_objects($configdata);
|
||||||
|
if ($updated) {
|
||||||
|
$blockinstance->configdata = base64_encode($configdata);
|
||||||
|
$DB->update_record('block_instances', $blockinstance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$blockinstances->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides a way to check and update a serialized string that uses the deprecated object class.
|
||||||
|
*
|
||||||
|
* @param string $serializeddata Serialized string which may contain the now deprecated object.
|
||||||
|
* @return array Returns an array where the first variable is a bool with a status of whether the initial data was changed
|
||||||
|
* or not. The second variable is the said data.
|
||||||
|
*/
|
||||||
|
function upgrade_fix_serialized_objects($serializeddata) {
|
||||||
|
$updated = false;
|
||||||
|
if (strpos($serializeddata, ":6:\"object") !== false) {
|
||||||
|
$serializeddata = str_replace(":6:\"object", ":8:\"stdClass", $serializeddata);
|
||||||
|
$updated = true;
|
||||||
|
}
|
||||||
|
return [$updated, $serializeddata];
|
||||||
|
}
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
$version = 2018022800.00; // YYYYMMDD = weekly release date of this DEV branch.
|
$version = 2018022800.01; // YYYYMMDD = weekly release date of this DEV branch.
|
||||||
// RR = release increments - 00 in DEV branches.
|
// RR = release increments - 00 in DEV branches.
|
||||||
// .XX = incremental changes.
|
// .XX = incremental changes.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user