Commit 1149d87b authored by Cecilia Vela Gurovic's avatar Cecilia Vela Gurovic Committed by Robert Lyon
Browse files

Bug 1804243: timeline: upgrade 'plans' blocktype in versions

behatnotneeded

Change-Id: Ief0fe215ac5f376db4e09bbab7fa724e81bf1b36
parent cef83153
......@@ -1227,5 +1227,67 @@ function xmldb_core_upgrade($oldversion=0) {
}
}
if ($oldversion < 2019031904) {
log_debug('Updating plan blocktype in view version');
$versions = get_records_sql_array("SELECT * FROM {view_versioning} WHERE blockdata LIKE '%\"blocktype\":\"plans\"%'");
// to keep the currect artefacts of a plans block
$existing_artefacts = array();
if ($versions) {
require_once(get_config('docroot') . '/blocktype/lib.php');
safe_require('blocktype', 'plans');
$count = 0;
$limit = 1000;
$total = count($versions);
foreach ($versions as $version) {
if (!empty($version->blockdata)) {
$needsupdate = false;
$blockdata = json_decode($version->blockdata);
foreach ($blockdata->blocks as &$block) {
if ($block->blocktype == 'plans') {
$blockid = $block->originalblockid;
if (!isset($existing_artefacts[$blockid])) {
//in case there are no artefacts in the block
// or the blockinstance was deleted, we won't check again
$existing_artefacts[$blockid] = null;
try {
// get the artefacts use in the block
$bi = new BlockInstance($blockid);
if ($bi && $artefacts = PluginBlocktypePlans::get_current_artefacts($bi)) {
foreach ($artefacts as $key => $artefact) {
if (isset($bi->configdata['artefactid']) && $bi->configdata['artefactid'] == $artefact) {
unset($artefacts[$key]);
}
}
$existing_artefacts[$blockid] = $artefacts;
}
}
catch (BlockInstanceNotFoundException $e) {}
}
// if we actually have artefact ids, save them in the version
if ($existing_artefacts[$blockid]) {
$block->configdata->existing_artefacts = $existing_artefacts[$blockid];
$needsupdate = true;
}
}
}
$version->blockdata = json_encode($blockdata);
if ($needsupdate) {
update_record('view_versioning', $version);
}
}
$count++;
if (($count % $limit) == 0 || $count == $total) {
log_debug("$count/$total");
set_time_limit(30);
}
}
}
}
return $status;
}
......@@ -16,7 +16,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/wiki/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2019031903;
$config->version = 2019031904;
$config->series = '19.04';
$config->release = '19.04rc2testing';
$config->minupgradefrom = 2017031605;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment