|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* For licensing terms, see /license.txt */ |
|
6
|
|
|
|
|
7
|
|
|
namespace Chamilo\CoreBundle\Migrations\Schema\V200; |
|
8
|
|
|
|
|
9
|
|
|
use Chamilo\CoreBundle\Entity\Course; |
|
10
|
|
|
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo; |
|
11
|
|
|
use Chamilo\CourseBundle\Entity\CThematic; |
|
12
|
|
|
use Chamilo\CourseBundle\Entity\CThematicAdvance; |
|
13
|
|
|
use Chamilo\CourseBundle\Entity\CThematicPlan; |
|
14
|
|
|
use Doctrine\DBAL\Schema\Schema; |
|
15
|
|
|
|
|
16
|
|
|
final class Version20201216105331 extends AbstractMigrationChamilo |
|
17
|
|
|
{ |
|
18
|
|
|
public function getDescription(): string |
|
19
|
|
|
{ |
|
20
|
|
|
return 'Migrate c_thematic, c_thematic_advance, c_thematic_plan'; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function up(Schema $schema): void |
|
24
|
|
|
{ |
|
25
|
|
|
$em = $this->getEntityManager(); |
|
26
|
|
|
|
|
27
|
|
|
$connection = $em->getConnection(); |
|
28
|
|
|
|
|
29
|
|
|
$thematicRepo = $em->getRepository(CThematic::class); |
|
30
|
|
|
$courseRepo = $em->getRepository(Course::class); |
|
31
|
|
|
|
|
32
|
|
|
$admin = $this->getAdmin(); |
|
33
|
|
|
|
|
34
|
|
|
$q = $em->createQuery('SELECT c FROM Chamilo\CoreBundle\Entity\Course c'); |
|
35
|
|
|
|
|
36
|
|
|
/** @var Course $course */ |
|
37
|
|
|
foreach ($q->toIterable() as $course) { |
|
38
|
|
|
$courseId = $course->getId(); |
|
39
|
|
|
|
|
40
|
|
|
// c_thematic. |
|
41
|
|
|
$sql = "SELECT * FROM c_thematic WHERE c_id = {$courseId} and active = 1 |
|
42
|
|
|
ORDER BY iid"; |
|
43
|
|
|
$result = $connection->executeQuery($sql); |
|
44
|
|
|
$items = $result->fetchAllAssociative(); |
|
45
|
|
|
foreach ($items as $itemData) { |
|
46
|
|
|
$id = $itemData['iid']; |
|
47
|
|
|
|
|
48
|
|
|
/** @var CThematic $resource */ |
|
49
|
|
|
$resource = $thematicRepo->find($id); |
|
50
|
|
|
if ($resource->hasResourceNode()) { |
|
51
|
|
|
continue; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
$course = $courseRepo->find($courseId); |
|
55
|
|
|
|
|
56
|
|
|
$result = $this->fixItemProperty( |
|
57
|
|
|
'thematic', |
|
58
|
|
|
$thematicRepo, |
|
59
|
|
|
$course, |
|
60
|
|
|
$admin, |
|
61
|
|
|
$resource, |
|
62
|
|
|
$course |
|
63
|
|
|
); |
|
64
|
|
|
|
|
65
|
|
|
if (false === $result) { |
|
66
|
|
|
continue; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
$em->persist($resource); |
|
70
|
|
|
$em->flush(); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$em->flush(); |
|
74
|
|
|
$em->clear(); |
|
75
|
|
|
|
|
76
|
|
|
// c_thematic_advance. |
|
77
|
|
|
/*$sql = "SELECT * FROM c_thematic_advance WHERE c_id = $courseId |
|
78
|
|
|
ORDER BY iid"; |
|
79
|
|
|
$result = $connection->executeQuery($sql); |
|
80
|
|
|
$items = $result->fetchAllAssociative(); |
|
81
|
|
|
foreach ($items as $itemData) { |
|
82
|
|
|
$id = $itemData['iid']; |
|
83
|
|
|
// @var CThematicAdvance $resource |
|
84
|
|
|
$resource = $thematicAdvanceRepo->find($id); |
|
85
|
|
|
if ($resource->hasResourceNode()) { |
|
86
|
|
|
continue; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
$course = $courseRepo->find($courseId); |
|
90
|
|
|
$result = $this->fixItemProperty( |
|
91
|
|
|
'thematic_advance', |
|
92
|
|
|
$thematicAdvanceRepo, |
|
93
|
|
|
$course, |
|
94
|
|
|
$admin, |
|
95
|
|
|
$resource, |
|
96
|
|
|
$course |
|
97
|
|
|
); |
|
98
|
|
|
|
|
99
|
|
|
if (false === $result) { |
|
100
|
|
|
continue; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
$em->persist($resource); |
|
104
|
|
|
$em->flush(); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
$em->flush(); |
|
108
|
|
|
$em->clear();*/ |
|
109
|
|
|
|
|
110
|
|
|
// c_thematic_plan. |
|
111
|
|
|
/*$sql = "SELECT * FROM c_thematic_plan WHERE c_id = $courseId |
|
112
|
|
|
ORDER BY iid"; |
|
113
|
|
|
$result = $connection->executeQuery($sql); |
|
114
|
|
|
$items = $result->fetchAllAssociative(); |
|
115
|
|
|
foreach ($items as $itemData) { |
|
116
|
|
|
$id = $itemData['iid']; |
|
117
|
|
|
// @var CThematicPlan $resource |
|
118
|
|
|
$resource = $thematicPlanRepo->find($id); |
|
119
|
|
|
if ($resource->hasResourceNode()) { |
|
120
|
|
|
continue; |
|
121
|
|
|
} |
|
122
|
|
|
$result = $this->fixItemProperty( |
|
123
|
|
|
'thematic_plan', |
|
124
|
|
|
$thematicPlanRepo, |
|
125
|
|
|
$course, |
|
126
|
|
|
$admin, |
|
127
|
|
|
$resource, |
|
128
|
|
|
$course |
|
129
|
|
|
); |
|
130
|
|
|
|
|
131
|
|
|
if (false === $result) { |
|
132
|
|
|
continue; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
$em->persist($resource); |
|
136
|
|
|
$em->flush(); |
|
137
|
|
|
} |
|
138
|
|
|
$em->flush(); |
|
139
|
|
|
$em->clear();*/ |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|