MDL-74434 block_tag_youtube: Update instances only if category is set

Modifies the existing upgrade step to only take into consideration
block instances that have a specific category set prior to determening
if a legacy category is being used and updating them. Instances that do
not have any category set should be ignored.
This commit is contained in:
Mihail Geshoski 2022-04-07 13:23:08 +08:00
parent ad6dc71c56
commit 32754bdf2a

View File

@ -101,6 +101,12 @@ function xmldb_block_tag_youtube_upgrade($oldversion) {
// If the block uses a legacy category name, update it to use the current category ID instead.
foreach ($blockinstances as $blockinstance) {
$blockconfig = unserialize(base64_decode($blockinstance->configdata));
// Skip if the block does not have a specific category set.
if (!isset($blockconfig->category)) {
continue;
}
$blockcategoryconfig = $blockconfig->category;
// The block is using a legacy category name as a category config.
if (array_key_exists($blockcategoryconfig, $categorynamemap)) {