|
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\CoreBundle\Repository\Node\UserRepository; |
|
13
|
|
|
use Chamilo\CoreBundle\Repository\SessionRepository; |
|
14
|
|
|
use Chamilo\CourseBundle\Entity\CSurvey; |
|
15
|
|
|
use Chamilo\CourseBundle\Repository\CGroupRepository; |
|
16
|
|
|
use Chamilo\CourseBundle\Repository\CSurveyRepository; |
|
17
|
|
|
use Chamilo\Kernel; |
|
18
|
|
|
use Doctrine\DBAL\Connection; |
|
19
|
|
|
use Doctrine\DBAL\Schema\Schema; |
|
20
|
|
|
|
|
21
|
|
|
final class Version20201218132719 extends AbstractMigrationChamilo |
|
22
|
|
|
{ |
|
23
|
|
|
public function getDescription(): string |
|
24
|
|
|
{ |
|
25
|
|
|
return 'Migrate c_survey'; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function up(Schema $schema): void |
|
29
|
|
|
{ |
|
30
|
|
|
$container = $this->getContainer(); |
|
31
|
|
|
$doctrine = $container->get('doctrine'); |
|
32
|
|
|
$em = $doctrine->getManager(); |
|
33
|
|
|
/** @var Connection $connection */ |
|
34
|
|
|
$connection = $em->getConnection(); |
|
35
|
|
|
|
|
36
|
|
|
$surveyRepo = $container->get(CSurveyRepository::class); |
|
37
|
|
|
$courseRepo = $container->get(CourseRepository::class); |
|
38
|
|
|
$sessionRepo = $container->get(SessionRepository::class); |
|
39
|
|
|
$groupRepo = $container->get(CGroupRepository::class); |
|
40
|
|
|
$userRepo = $container->get(UserRepository::class); |
|
41
|
|
|
/** @var Kernel $kernel */ |
|
42
|
|
|
$kernel = $container->get('kernel'); |
|
43
|
|
|
$rootPath = $kernel->getProjectDir(); |
|
44
|
|
|
|
|
45
|
|
|
$admin = $this->getAdmin(); |
|
46
|
|
|
|
|
47
|
|
|
$q = $em->createQuery('SELECT c FROM Chamilo\CoreBundle\Entity\Course c'); |
|
48
|
|
|
/** @var Course $course */ |
|
49
|
|
|
foreach ($q->toIterable() as $course) { |
|
50
|
|
|
$courseId = $course->getId(); |
|
51
|
|
|
$course = $courseRepo->find($courseId); |
|
52
|
|
|
|
|
53
|
|
|
$sql = "SELECT * FROM c_survey WHERE c_id = {$courseId} ORDER BY iid"; |
|
54
|
|
|
$result = $connection->executeQuery($sql); |
|
55
|
|
|
$items = $result->fetchAllAssociative(); |
|
56
|
|
|
foreach ($items as $itemData) { |
|
57
|
|
|
$id = $itemData['iid']; |
|
58
|
|
|
/** @var CSurvey $resource */ |
|
59
|
|
|
$resource = $surveyRepo->find($id); |
|
60
|
|
|
if ($resource->hasResourceNode()) { |
|
61
|
|
|
continue; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
$result = $this->fixItemProperty( |
|
65
|
|
|
'survey', |
|
66
|
|
|
$surveyRepo, |
|
67
|
|
|
$course, |
|
68
|
|
|
$admin, |
|
69
|
|
|
$resource, |
|
70
|
|
|
$course |
|
71
|
|
|
); |
|
72
|
|
|
|
|
73
|
|
|
if (false === $result) { |
|
74
|
|
|
continue; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
$em->persist($resource); |
|
78
|
|
|
$em->flush(); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
$em->flush(); |
|
82
|
|
|
$em->clear(); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|