Skip to content
This repository was archived by the owner on Jul 13, 2021. It is now read-only.

Commit 6ceaa73

Browse files
Elorfinptsavdar
authored andcommitted
[ExoBundle] fixes quiz migration (#2022)
* [ExoBundle] fixes quiz types migration * [ExoBundle] fixes answer data migration
1 parent e533d38 commit 6ceaa73

File tree

3 files changed

+103
-13
lines changed

3 files changed

+103
-13
lines changed

plugin/exo/Installation/AdditionalInstaller.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use UJM\ExoBundle\Installation\Updater\Updater060200;
99
use UJM\ExoBundle\Installation\Updater\Updater070000;
1010
use UJM\ExoBundle\Installation\Updater\Updater090000;
11+
use UJM\ExoBundle\Installation\Updater\Updater090002;
1112

1213
class AdditionalInstaller extends BaseInstaller
1314
{
@@ -63,5 +64,13 @@ public function postUpdate($currentVersion, $targetVersion)
6364
$updater->setLogger($this->logger);
6465
$updater->postUpdate();
6566
}
67+
68+
if (version_compare($currentVersion, '9.0.2', '<')) {
69+
$updater = new Updater090002(
70+
$this->container->get('doctrine.dbal.default_connection')
71+
);
72+
$updater->setLogger($this->logger);
73+
$updater->postUpdate();
74+
}
6675
}
6776
}

plugin/exo/Installation/Updater/Updater090000.php

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,16 @@ private function updateAnswerData()
192192
$newData = array_map(function ($association) use ($propNames, $labels, $proposals) {
193193
$associationData = explode(',', $association);
194194

195-
$data = new \stdClass();
195+
$data = null;
196196

197-
// Convert ids into uuids
198-
$data->{$propNames[0]} = $this->getAnswerPartUuid($associationData[0], $proposals);
199-
$data->{$propNames[1]} = $this->getAnswerPartUuid($associationData[1], $labels);
197+
// The new system only allows complete association in answers
198+
if (!empty($associationData) && 2 === count($associationData)) {
199+
$data = new \stdClass();
200+
201+
// Convert ids into uuids
202+
$data->{$propNames[0]} = $this->getAnswerPartUuid($associationData[0], $proposals);
203+
$data->{$propNames[1]} = $this->getAnswerPartUuid($associationData[1], $labels);
204+
}
200205

201206
return $data;
202207
}, $answerData);
@@ -216,10 +221,14 @@ private function updateAnswerData()
216221
$pairData = explode(',', $pair);
217222

218223
// Convert ids into uuids
219-
return [
220-
$this->getAnswerPartUuid($pairData[0], $proposals),
221-
$this->getAnswerPartUuid($pairData[1], $labels),
222-
];
224+
if (!empty($pairData) && 2 === count($pairData)) {
225+
return [
226+
$this->getAnswerPartUuid($pairData[0], $proposals),
227+
$this->getAnswerPartUuid($pairData[1], $labels),
228+
];
229+
} else {
230+
return null;
231+
}
223232
}, $answerData);
224233

225234
break;
@@ -288,10 +297,14 @@ private function updateAnswerData()
288297
$newData = array_map(function ($coords) {
289298
$coordsData = explode(',', $coords);
290299

291-
return [
292-
$coordsData[0],
293-
$coordsData[1],
294-
];
300+
if (!empty($coordsData) && 2 === count($coordsData)) {
301+
return [
302+
$coordsData[0],
303+
$coordsData[1],
304+
];
305+
} else {
306+
return null;
307+
}
295308
}, $answerData);
296309
break;
297310

@@ -303,9 +316,19 @@ private function updateAnswerData()
303316
$sth = $this->connection->prepare('
304317
UPDATE ujm_response SET `response` = :data WHERE id = :id
305318
');
319+
320+
$insertData = null;
321+
if (!empty($newData)) {
322+
$insertData = json_encode(
323+
array_filter($newData, function ($data) {
324+
return !empty($data);
325+
})
326+
);
327+
}
328+
306329
$sth->execute([
307330
'id' => $answer['answerId'],
308-
'data' => !empty($newData) ? json_encode($newData) : null,
331+
'data' => $insertData,
309332
]);
310333
}
311334

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
namespace UJM\ExoBundle\Installation\Updater;
4+
5+
use Claroline\BundleRecorder\Log\LoggableTrait;
6+
use Doctrine\DBAL\Connection;
7+
8+
class Updater090002
9+
{
10+
use LoggableTrait;
11+
12+
/**
13+
* @var Connection
14+
*/
15+
private $connection;
16+
17+
/**
18+
* Updater090002 constructor.
19+
*
20+
* @param Connection $connection
21+
*/
22+
public function __construct(Connection $connection)
23+
{
24+
$this->connection = $connection;
25+
}
26+
27+
public function postUpdate()
28+
{
29+
$this->fixQuizTypes();
30+
}
31+
32+
private function fixQuizTypes()
33+
{
34+
$this->connection
35+
->prepare('
36+
UPDATE ujm_exercise SET `type` = "summative" WHERE `type` = "1";
37+
')
38+
->execute();
39+
40+
$this->connection
41+
->prepare('
42+
UPDATE ujm_exercise SET `type` = "summative" WHERE `type` = "sommatif";
43+
')
44+
->execute();
45+
46+
$this->connection
47+
->prepare('
48+
UPDATE ujm_exercise SET `type` = "evaluative" WHERE `type` = "2";
49+
')
50+
->execute();
51+
52+
$this->connection
53+
->prepare('
54+
UPDATE ujm_exercise SET `type` = "formative" WHERE `type` = "3";
55+
')
56+
->execute();
57+
}
58+
}

0 commit comments

Comments
 (0)