|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Chamilo\CoreBundle\Migrations\Schema\V200; |
|
6
|
|
|
|
|
7
|
|
|
use Chamilo\CoreBundle\Entity\Course; |
|
8
|
|
|
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo; |
|
9
|
|
|
use Chamilo\CoreBundle\Repository\Node\CourseRepository; |
|
10
|
|
|
use Chamilo\CoreBundle\Repository\SessionRepository; |
|
11
|
|
|
use Chamilo\CoreBundle\Repository\ToolRepository; |
|
12
|
|
|
use Chamilo\CourseBundle\Entity\CTool; |
|
13
|
|
|
use Chamilo\CourseBundle\Entity\CToolIntro; |
|
14
|
|
|
use Chamilo\CourseBundle\Repository\CToolIntroRepository; |
|
15
|
|
|
use Chamilo\CourseBundle\Repository\CToolRepository; |
|
16
|
|
|
use Doctrine\DBAL\Schema\Schema; |
|
17
|
|
|
|
|
18
|
|
|
final class Version20210930130343 extends AbstractMigrationChamilo |
|
19
|
|
|
{ |
|
20
|
|
|
public function getDescription(): string |
|
21
|
|
|
{ |
|
22
|
|
|
return 'CToolIntro'; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function up(Schema $schema): void |
|
26
|
|
|
{ |
|
27
|
|
|
$container = $this->getContainer(); |
|
28
|
|
|
$em = $this->getEntityManager(); |
|
29
|
|
|
$connection = $em->getConnection(); |
|
30
|
|
|
|
|
31
|
|
|
$batchSize = self::BATCH_SIZE; |
|
32
|
|
|
|
|
33
|
|
|
$introRepo = $container->get(CToolIntroRepository::class); |
|
34
|
|
|
$cToolRepo = $container->get(CToolRepository::class); |
|
35
|
|
|
$toolRepo = $container->get(ToolRepository::class); |
|
36
|
|
|
|
|
37
|
|
|
$sessionRepo = $container->get(SessionRepository::class); |
|
38
|
|
|
$courseRepo = $container->get(CourseRepository::class); |
|
39
|
|
|
|
|
40
|
|
|
$q = $em->createQuery('SELECT c FROM Chamilo\CoreBundle\Entity\Course c'); |
|
41
|
|
|
|
|
42
|
|
|
/** @var Course $course */ |
|
43
|
|
|
foreach ($q->toIterable() as $course) { |
|
44
|
|
|
$courseId = $course->getId(); |
|
45
|
|
|
$sql = "SELECT * FROM c_tool_intro WHERE c_id = {$courseId} |
|
46
|
|
|
ORDER BY iid"; |
|
47
|
|
|
$result = $connection->executeQuery($sql); |
|
48
|
|
|
$items = $result->fetchAllAssociative(); |
|
49
|
|
|
foreach ($items as $itemData) { |
|
50
|
|
|
$id = $itemData['iid']; |
|
51
|
|
|
$sessionId = (int) $itemData['session_id']; |
|
52
|
|
|
$toolName = $itemData['id']; |
|
53
|
|
|
|
|
54
|
|
|
/** @var CToolIntro $intro */ |
|
55
|
|
|
$intro = $introRepo->find($id); |
|
56
|
|
|
|
|
57
|
|
|
if ($intro->hasResourceNode()) { |
|
58
|
|
|
continue; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
$session = null; |
|
62
|
|
|
if (!empty($sessionId)) { |
|
63
|
|
|
$session = $sessionRepo->find($sessionId); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
$admin = $this->getAdmin(); |
|
67
|
|
|
|
|
68
|
|
|
$cTool = null; |
|
69
|
|
|
if ('course_homepage' === $toolName) { |
|
70
|
|
|
$tool = $toolRepo->findOneBy(['name' => $toolName]); |
|
71
|
|
|
|
|
72
|
|
|
if (null === $tool) { |
|
73
|
|
|
continue; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
$course = $courseRepo->find($courseId); |
|
77
|
|
|
|
|
78
|
|
|
$cTool = (new CTool()) |
|
79
|
|
|
->setName('course_homepage') |
|
80
|
|
|
->setCourse($course) |
|
81
|
|
|
->setSession($session) |
|
82
|
|
|
->setTool($tool) |
|
83
|
|
|
->setCreator($admin) |
|
84
|
|
|
->setParent($course) |
|
85
|
|
|
->addCourseLink($course, $session) |
|
86
|
|
|
; |
|
87
|
|
|
$em->persist($cTool); |
|
88
|
|
|
} else { |
|
89
|
|
|
$cTool = $cToolRepo->findCourseResourceByTitle($toolName, $course->getResourceNode(), $course, $session); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
if (null === $cTool) { |
|
93
|
|
|
continue; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
$intro |
|
97
|
|
|
->setParent($course) |
|
98
|
|
|
->setCourseTool($cTool) |
|
99
|
|
|
; |
|
100
|
|
|
$introRepo->addResourceNode($intro, $admin, $course); |
|
101
|
|
|
$intro->addCourseLink($course, $session); |
|
102
|
|
|
|
|
103
|
|
|
$em->persist($intro); |
|
104
|
|
|
$em->flush(); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
$em->flush(); |
|
108
|
|
|
$em->clear(); |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
public function down(Schema $schema): void |
|
113
|
|
|
{ |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|