|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* For licensing terms, see /license.txt */ |
|
4
|
|
|
|
|
5
|
|
|
declare(strict_types=1); |
|
6
|
|
|
|
|
7
|
|
|
namespace Chamilo\CoreBundle\Migrations\Schema\V200; |
|
8
|
|
|
|
|
9
|
|
|
use Chamilo\CoreBundle\Entity\PortfolioAttachment; |
|
10
|
|
|
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo; |
|
11
|
|
|
use Chamilo\CoreBundle\Repository\Node\PortfolioCommentRepository; |
|
12
|
|
|
use Chamilo\CoreBundle\Repository\Node\PortfolioRepository; |
|
13
|
|
|
use Chamilo\CoreBundle\Repository\PortfolioAttachmentRepository; |
|
14
|
|
|
use Doctrine\DBAL\Schema\Schema; |
|
15
|
|
|
|
|
16
|
|
|
class Version20250927180004 extends AbstractMigrationChamilo |
|
17
|
|
|
{ |
|
18
|
|
|
public function getDescription(): string |
|
19
|
|
|
{ |
|
20
|
|
|
return 'Migrate portfolio attachments'; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function up(Schema $schema): void |
|
24
|
|
|
{ |
|
25
|
|
|
/** @var PortfolioAttachmentRepository $attachmentRepo */ |
|
26
|
|
|
$attachmentRepo = $this->container->get(PortfolioAttachmentRepository::class); |
|
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
/** @var PortfolioRepository $itemRepo */ |
|
29
|
|
|
$itemRepo = $this->container->get(PortfolioRepository::class); |
|
30
|
|
|
|
|
31
|
|
|
/** @var PortfolioCommentRepository $itemRepo */ |
|
32
|
|
|
$commentRepo = $this->container->get(PortfolioCommentRepository::class); |
|
33
|
|
|
|
|
34
|
|
|
$attachmentRows = $this->connection |
|
35
|
|
|
->executeQuery('SELECT * FROM portfolio_attachment') |
|
36
|
|
|
->fetchAllAssociative() |
|
37
|
|
|
; |
|
38
|
|
|
|
|
39
|
|
|
foreach ($attachmentRows as $attachmentRow) { |
|
40
|
|
|
$userId = 0; |
|
41
|
|
|
$resource = null; |
|
42
|
|
|
$resourceRepo = null; |
|
43
|
|
|
|
|
44
|
|
|
if (PortfolioAttachment::TYPE_ITEM === (int) $attachmentRow['origin_type']) { |
|
45
|
|
|
$resourceRepo = $itemRepo; |
|
46
|
|
|
$resource = $itemRepo->find($attachmentRow['origin_id']); |
|
47
|
|
|
|
|
48
|
|
|
$itemRow = $this->connection |
|
49
|
|
|
->executeQuery("SELECT user_id FROM portfolio WHERE id = {$attachmentRow['origin_id']}") |
|
50
|
|
|
->fetchAssociative() |
|
51
|
|
|
; |
|
52
|
|
|
|
|
53
|
|
|
$userId = $itemRow['user_id'] ?? 0; |
|
54
|
|
|
} elseif (PortfolioAttachment::TYPE_COMMENT === (int) $attachmentRow['origin_type']) { |
|
55
|
|
|
$resourceRepo = $commentRepo; |
|
56
|
|
|
$resource = $commentRepo->find($attachmentRow['origin_id']); |
|
57
|
|
|
|
|
58
|
|
|
$commentRow = $this->connection |
|
59
|
|
|
->executeQuery("SELECT author_id FROM portfolio_comment WHERE id = {$attachmentRow['origin_id']}") |
|
60
|
|
|
->fetchAssociative() |
|
61
|
|
|
; |
|
62
|
|
|
|
|
63
|
|
|
$userId = $commentRow['author_id'] ?? 0; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
if (!$resource) { |
|
67
|
|
|
continue; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
$folderId = ((string) $userId)[0]; |
|
71
|
|
|
$path = $attachmentRow['path']; |
|
72
|
|
|
|
|
73
|
|
|
$filePath = $this->getUpdateRootPath()."/app/upload/users/$folderId/$userId/portfolio_attachments/$path"; |
|
74
|
|
|
|
|
75
|
|
|
$this->write('MIGRATIONS :: $filePath -- '.$filePath.' ...'); |
|
76
|
|
|
|
|
77
|
|
|
if (!file_exists($filePath)) { |
|
78
|
|
|
continue; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
$this->addLegacyFileToResource( |
|
82
|
|
|
$filePath, |
|
83
|
|
|
$resourceRepo, |
|
84
|
|
|
$resource, |
|
85
|
|
|
$attachmentRow['origin_id'], |
|
86
|
|
|
$attachmentRow['filename'], |
|
87
|
|
|
$attachmentRow['comment'] |
|
88
|
|
|
); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
$this->entityManager->flush(); |
|
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|
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.