Passed
Pull Request — master (#5329)
by Angel Fernando Quiroz
09:42
created

Version20201216105331::getDescription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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
        $thematicRepo = $this->container->get(CThematicRepository::class);
0 ignored issues
show
Bug introduced by
The method get() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

27
        /** @scrutinizer ignore-call */ 
28
        $thematicRepo = $this->container->get(CThematicRepository::class);

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.

Loading history...
28
        $courseRepo = $this->container->get(CourseRepository::class);
29
30
        $admin = $this->getAdmin();
31
32
        $q = $this->entityManager->createQuery('SELECT c FROM Chamilo\CoreBundle\Entity\Course c');
0 ignored issues
show
Bug introduced by
The method createQuery() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

32
        /** @scrutinizer ignore-call */ 
33
        $q = $this->entityManager->createQuery('SELECT c FROM Chamilo\CoreBundle\Entity\Course c');

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.

Loading history...
33
34
        /** @var Course $course */
35
        foreach ($q->toIterable() as $course) {
36
            $courseId = $course->getId();
37
38
            // c_thematic.
39
            $sql = "SELECT * FROM c_thematic WHERE c_id = {$courseId} and active = 1
40
                    ORDER BY iid";
41
            $result = $this->connection->executeQuery($sql);
42
            $items = $result->fetchAllAssociative();
43
            foreach ($items as $itemData) {
44
                $id = $itemData['iid'];
45
46
                /** @var CThematic $resource */
47
                $resource = $thematicRepo->find($id);
48
                if ($resource->hasResourceNode()) {
49
                    continue;
50
                }
51
52
                $course = $courseRepo->find($courseId);
53
54
                $result = $this->fixItemProperty(
55
                    'thematic',
56
                    $thematicRepo,
57
                    $course,
58
                    $admin,
59
                    $resource,
60
                    $course
61
                );
62
63
                if (false === $result) {
64
                    continue;
65
                }
66
67
                $this->entityManager->persist($resource);
68
                $this->entityManager->flush();
69
            }
70
71
            $this->entityManager->flush();
72
            $this->entityManager->clear();
73
74
            // c_thematic_advance.
75
            /*$sql = "SELECT * FROM c_thematic_advance WHERE c_id = $courseId
76
                    ORDER BY iid";
77
            $result = $this->connection->executeQuery($sql);
78
            $items = $result->fetchAllAssociative();
79
            foreach ($items as $itemData) {
80
                $id = $itemData['iid'];
81
                // @var CThematicAdvance $resource
82
                $resource = $thematicAdvanceRepo->find($id);
83
                if ($resource->hasResourceNode()) {
84
                    continue;
85
                }
86
87
                $course = $courseRepo->find($courseId);
88
                $result = $this->fixItemProperty(
89
                    'thematic_advance',
90
                    $thematicAdvanceRepo,
91
                    $course,
92
                    $admin,
93
                    $resource,
94
                    $course
95
                );
96
97
                if (false === $result) {
98
                    continue;
99
                }
100
101
                $this->entityManager->persist($resource);
102
                $this->entityManager->flush();
103
            }
104
105
            $this->entityManager->flush();
106
            $this->entityManager->clear();*/
107
108
            // c_thematic_plan.
109
            /*$sql = "SELECT * FROM c_thematic_plan WHERE c_id = $courseId
110
                    ORDER BY iid";
111
            $result = $this->connection->executeQuery($sql);
112
            $items = $result->fetchAllAssociative();
113
            foreach ($items as $itemData) {
114
                $id = $itemData['iid'];
115
                // @var CThematicPlan $resource
116
                $resource = $thematicPlanRepo->find($id);
117
                if ($resource->hasResourceNode()) {
118
                    continue;
119
                }
120
                $result = $this->fixItemProperty(
121
                    'thematic_plan',
122
                    $thematicPlanRepo,
123
                    $course,
124
                    $admin,
125
                    $resource,
126
                    $course
127
                );
128
129
                if (false === $result) {
130
                    continue;
131
                }
132
133
                $this->entityManager->persist($resource);
134
                $this->entityManager->flush();
135
            }
136
            $this->entityManager->flush();
137
            $this->entityManager->clear();*/
138
        }
139
    }
140
}
141