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\CoreBundle\Repository\Node\CourseRepository; |
12
|
|
|
use Chamilo\CourseBundle\Entity\CThematic; |
13
|
|
|
use Chamilo\CourseBundle\Entity\CThematicAdvance; |
14
|
|
|
use Chamilo\CourseBundle\Entity\CThematicPlan; |
15
|
|
|
use Chamilo\CourseBundle\Repository\CThematicRepository; |
16
|
|
|
use Doctrine\DBAL\Schema\Schema; |
17
|
|
|
|
18
|
|
|
final class Version20201216105331 extends AbstractMigrationChamilo |
19
|
|
|
{ |
20
|
|
|
public function getDescription(): string |
21
|
|
|
{ |
22
|
|
|
return 'Migrate c_thematic, c_thematic_advance, c_thematic_plan'; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function up(Schema $schema): void |
26
|
|
|
{ |
27
|
|
|
$em = $this->getEntityManager(); |
28
|
|
|
|
29
|
|
|
$connection = $em->getConnection(); |
30
|
|
|
|
31
|
|
|
$thematicRepo = $this->container->get(CThematicRepository::class); |
|
|
|
|
32
|
|
|
$courseRepo = $this->container->get(CourseRepository::class); |
33
|
|
|
|
34
|
|
|
$admin = $this->getAdmin(); |
35
|
|
|
|
36
|
|
|
$q = $em->createQuery('SELECT c FROM Chamilo\CoreBundle\Entity\Course c'); |
37
|
|
|
|
38
|
|
|
/** @var Course $course */ |
39
|
|
|
foreach ($q->toIterable() as $course) { |
40
|
|
|
$courseId = $course->getId(); |
41
|
|
|
|
42
|
|
|
// c_thematic. |
43
|
|
|
$sql = "SELECT * FROM c_thematic WHERE c_id = {$courseId} and active = 1 |
44
|
|
|
ORDER BY iid"; |
45
|
|
|
$result = $connection->executeQuery($sql); |
46
|
|
|
$items = $result->fetchAllAssociative(); |
47
|
|
|
foreach ($items as $itemData) { |
48
|
|
|
$id = $itemData['iid']; |
49
|
|
|
|
50
|
|
|
/** @var CThematic $resource */ |
51
|
|
|
$resource = $thematicRepo->find($id); |
52
|
|
|
if ($resource->hasResourceNode()) { |
53
|
|
|
continue; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$course = $courseRepo->find($courseId); |
57
|
|
|
|
58
|
|
|
$result = $this->fixItemProperty( |
59
|
|
|
'thematic', |
60
|
|
|
$thematicRepo, |
61
|
|
|
$course, |
62
|
|
|
$admin, |
63
|
|
|
$resource, |
64
|
|
|
$course |
65
|
|
|
); |
66
|
|
|
|
67
|
|
|
if (false === $result) { |
68
|
|
|
continue; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
$em->persist($resource); |
72
|
|
|
$em->flush(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
$em->flush(); |
76
|
|
|
$em->clear(); |
77
|
|
|
|
78
|
|
|
// c_thematic_advance. |
79
|
|
|
/*$sql = "SELECT * FROM c_thematic_advance WHERE c_id = $courseId |
80
|
|
|
ORDER BY iid"; |
81
|
|
|
$result = $connection->executeQuery($sql); |
82
|
|
|
$items = $result->fetchAllAssociative(); |
83
|
|
|
foreach ($items as $itemData) { |
84
|
|
|
$id = $itemData['iid']; |
85
|
|
|
// @var CThematicAdvance $resource |
86
|
|
|
$resource = $thematicAdvanceRepo->find($id); |
87
|
|
|
if ($resource->hasResourceNode()) { |
88
|
|
|
continue; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
$course = $courseRepo->find($courseId); |
92
|
|
|
$result = $this->fixItemProperty( |
93
|
|
|
'thematic_advance', |
94
|
|
|
$thematicAdvanceRepo, |
95
|
|
|
$course, |
96
|
|
|
$admin, |
97
|
|
|
$resource, |
98
|
|
|
$course |
99
|
|
|
); |
100
|
|
|
|
101
|
|
|
if (false === $result) { |
102
|
|
|
continue; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
$em->persist($resource); |
106
|
|
|
$em->flush(); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
$em->flush(); |
110
|
|
|
$em->clear();*/ |
111
|
|
|
|
112
|
|
|
// c_thematic_plan. |
113
|
|
|
/*$sql = "SELECT * FROM c_thematic_plan WHERE c_id = $courseId |
114
|
|
|
ORDER BY iid"; |
115
|
|
|
$result = $connection->executeQuery($sql); |
116
|
|
|
$items = $result->fetchAllAssociative(); |
117
|
|
|
foreach ($items as $itemData) { |
118
|
|
|
$id = $itemData['iid']; |
119
|
|
|
// @var CThematicPlan $resource |
120
|
|
|
$resource = $thematicPlanRepo->find($id); |
121
|
|
|
if ($resource->hasResourceNode()) { |
122
|
|
|
continue; |
123
|
|
|
} |
124
|
|
|
$result = $this->fixItemProperty( |
125
|
|
|
'thematic_plan', |
126
|
|
|
$thematicPlanRepo, |
127
|
|
|
$course, |
128
|
|
|
$admin, |
129
|
|
|
$resource, |
130
|
|
|
$course |
131
|
|
|
); |
132
|
|
|
|
133
|
|
|
if (false === $result) { |
134
|
|
|
continue; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
$em->persist($resource); |
138
|
|
|
$em->flush(); |
139
|
|
|
} |
140
|
|
|
$em->flush(); |
141
|
|
|
$em->clear();*/ |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.