|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* For licensing terms, see /license.txt */ |
|
4
|
|
|
|
|
5
|
|
|
namespace Chamilo\CoreBundle\Migrations\Schema\V200; |
|
6
|
|
|
|
|
7
|
|
|
use Chamilo\CoreBundle\Entity\Course; |
|
8
|
|
|
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo; |
|
9
|
|
|
use Chamilo\CourseBundle\Repository\CLpRepository; |
|
10
|
|
|
use Chamilo\Kernel; |
|
11
|
|
|
use Doctrine\DBAL\Connection; |
|
12
|
|
|
use Doctrine\DBAL\Schema\Schema; |
|
13
|
|
|
|
|
14
|
|
|
class Version20210221082033 extends AbstractMigrationChamilo |
|
15
|
|
|
{ |
|
16
|
|
|
public function getDescription(): string |
|
17
|
|
|
{ |
|
18
|
|
|
return 'Migrate c_lp images'; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function up(Schema $schema): void |
|
22
|
|
|
{ |
|
23
|
|
|
$container = $this->getContainer(); |
|
24
|
|
|
/** @var Kernel $kernel */ |
|
25
|
|
|
$kernel = $container->get('kernel'); |
|
26
|
|
|
$rootPath = $kernel->getProjectDir(); |
|
27
|
|
|
$doctrine = $container->get('doctrine'); |
|
28
|
|
|
|
|
29
|
|
|
$em = $doctrine->getManager(); |
|
30
|
|
|
/** @var Connection $connection */ |
|
31
|
|
|
$connection = $em->getConnection(); |
|
32
|
|
|
$lpRepo = $container->get(CLpRepository::class); |
|
33
|
|
|
|
|
34
|
|
|
$q = $em->createQuery('SELECT c FROM Chamilo\CoreBundle\Entity\Course c'); |
|
35
|
|
|
/** @var Course $course */ |
|
36
|
|
|
foreach ($q->toIterable() as $course) { |
|
37
|
|
|
$courseId = $course->getId(); |
|
38
|
|
|
$sql = "SELECT * FROM c_lp WHERE c_id = $courseId |
|
39
|
|
|
ORDER BY iid"; |
|
40
|
|
|
$result = $connection->executeQuery($sql); |
|
41
|
|
|
$items = $result->fetchAllAssociative(); |
|
42
|
|
|
foreach ($items as $itemData) { |
|
43
|
|
|
$id = $itemData['iid']; |
|
44
|
|
|
$lp = $lpRepo->find($id); |
|
45
|
|
|
if ($lp && !empty($lp->getPreviewImage())) { |
|
46
|
|
|
$path = $lp->getPreviewImage(); |
|
47
|
|
|
$filePath = $rootPath.'/app/courses/'.$course->getDirectory().'/upload/learning_path/images/'.$path; |
|
48
|
|
|
if (file_exists($rootPath)) { |
|
49
|
|
|
$this->addLegacyFileToResource($filePath, $lpRepo, $lp, $lp->getIid(), $path); |
|
50
|
|
|
$em->persist($lp); |
|
51
|
|
|
$em->flush(); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
$em->flush(); |
|
57
|
|
|
$em->clear(); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|