From 51f734e4072e24b3ddfec899e399d72a867bd463 Mon Sep 17 00:00:00 2001 From: oliver Date: Sat, 21 Mar 2015 17:20:34 +0100 Subject: [PATCH] correct copying of Quests and Questtexts --- models/AchievementsModel.inc | 2 +- models/QuestgroupsModel.inc | 1 - models/QuestsModel.inc | 34 ++++++++++++++++++++++++++++------ 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/models/AchievementsModel.inc b/models/AchievementsModel.inc index a2d4f7c2..03eccea6 100644 --- a/models/AchievementsModel.inc +++ b/models/AchievementsModel.inc @@ -1343,7 +1343,7 @@ } // Copy Achievement conditions - // Do this after copying the Achievements itself to ensure Meta- + // Do this after copying the Achievements themselves to ensure Meta- // Achievements work correctly foreach($achievements as &$achievement) { diff --git a/models/QuestgroupsModel.inc b/models/QuestgroupsModel.inc index aa051bad..86d70e69 100644 --- a/models/QuestgroupsModel.inc +++ b/models/QuestgroupsModel.inc @@ -396,7 +396,6 @@ } // XPs of child Questgroups - //var_dump($this->Questgroupshierarchy); $questgroupHierarchy = $this->Questgroupshierarchy->getHierarchyForQuestgroup($questgroupId); if(!empty($questgroupHierarchy)) { diff --git a/models/QuestsModel.inc b/models/QuestsModel.inc index 8de1e60f..3bf551d1 100644 --- a/models/QuestsModel.inc +++ b/models/QuestsModel.inc @@ -710,8 +710,7 @@ 'FROM quests '. 'WHERE id = ?', 'iii', - $userId, - $questgroupIds[$quest['questgroup_id']], + $userId, $questgroupIds[$quest['questgroup_id']], $quest['id'] ); $questIds[$quest['id']] = $this->db->getInsertId(); @@ -731,10 +730,7 @@ } // Copy texts - $questtextIds = array_merge( - $questtextIds, - $this->Questtexts->copyQuesttexts($userId, $quest['id'], $questIds[$quest['id']], $seminaryMediaIds) - ); + $questtextIds = $questtextIds + $this->Questtexts->copyQuesttexts($userId, $quest['id'], $questIds[$quest['id']], $seminaryMediaIds); // Copy content $questtype = $this->Questtypes->getQuesttypeById($quest['questtype_id']); @@ -751,6 +747,32 @@ } } + // Copy flow + // Do this after copying the Quests themselves to ensure all Quests + // have their target IDs. + foreach($quests as &$quest) + { + $previousQuests = $this->db->query( + 'SELECT previous_quest_id '. + 'FROM quests_previousquests '. + 'WHERE quest_id = ?', + 'i', + $quest['id'] + ); + foreach($previousQuests as &$previousQuest) + { + $this->db->query( + 'INSERT INTO quests_previousquests '. + '(quest_id, previous_quest_id) '. + 'VALUES '. + '(?, ?)', + 'ii', + $questIds[$quest['id']], + $questIds[$previousQuest['previous_quest_id']] + ); + } + } + return array( 'quests' => $questIds,