Commit a57890d9 authored by Robert Lyon's avatar Robert Lyon

Bug 1851174: Don't use the call to plan class on upgrade

Before the new tables exist that plan class needs

behatnotneeded

Change-Id: I6acce6b7c2e97d9ef0b4bcf53096081c631038f1
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 42268822
......@@ -207,7 +207,10 @@ class ArtefactTypePlan extends ArtefactType {
parent::__construct($id, $data);
if ($this->id) {
if ($pdata = get_record('artefact_plans_plan', 'artefact', $this->id)) {
if (defined('INSTALLER') && !db_table_exists('artefact_plans_plan')) {
// Upgrading from older site and table does not yet exist
}
else if ($pdata = get_record('artefact_plans_plan', 'artefact', $this->id)) {
foreach($pdata as $name => $value) {
if (property_exists($this, $name)) {
$this->$name = $value;
......
......@@ -1254,10 +1254,40 @@ function xmldb_core_upgrade($oldversion=0) {
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]);
if ($bi) {
$artefacts = array();
$configdata = $bi->get('configdata');
foreach ($configdata['artefactids'] as $planid) {
// We need to do this without calling the plan class because the plan class has changed
$plan = get_record('artefact', 'id', $planid, null, null, null, null, 'id, title, description, owner');
if ($tags = get_column('tag', 'tag', 'resourcetype', 'artefact', 'resourceid', $planid)) {
$plan->tags = $tags;
}
$tasks = get_records_sql_array("SELECT a.id, apt.artefact AS task, apt.completed, apt.completiondate,
a.title, a.description, a.parent, a.owner
FROM {artefact} a
JOIN {artefact_plans_task} apt ON apt.artefact = a.id
WHERE a.parent = ?", array($planid));
foreach ($tasks as $t => $task) {
if ($tasktags = get_column('tag', 'tag', 'resourcetype', 'artefact', 'resourceid', $task->id)) {
$task->tags = $tasktags;
}
}
$artefacts[$planid]['tasks'] = array('count' => count($tasks),
'data' => $tasks,
'offset' => 0,
'limit' => 0,
'id' => $planid);
$artefacts[$planid]['title'] = $plan->title;
$artefacts[$planid]['description'] = $plan->description;
$artefacts[$planid]['tags'] = $plan->tags;
$artefacts[$planid]['owner'] = $plan->owner;
}
if (!empty($artefacts)) {
foreach ($artefacts as $key => $artefact) {
if (isset($bi->configdata['artefactid']) && $bi->configdata['artefactid'] == $artefact) {
unset($artefacts[$key]);
}
}
}
$existing_artefacts[$blockid] = $artefacts;
......
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