|
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\Portfolio; |
|
10
|
|
|
use Chamilo\CoreBundle\Entity\ResourceLink; |
|
11
|
|
|
use Chamilo\CoreBundle\Entity\User; |
|
12
|
|
|
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo; |
|
13
|
|
|
use Chamilo\CoreBundle\Repository\Node\PortfolioRepository; |
|
14
|
|
|
use Chamilo\CoreBundle\Repository\Node\UserRepository; |
|
15
|
|
|
use Chamilo\CoreBundle\Repository\ResourceRepository; |
|
16
|
|
|
use DateTime; |
|
17
|
|
|
use Doctrine\DBAL\Schema\Schema; |
|
18
|
|
|
use Exception; |
|
19
|
|
|
|
|
20
|
|
|
class Version20250927180001 extends AbstractMigrationChamilo |
|
21
|
|
|
{ |
|
22
|
|
|
public function getDescription(): string |
|
23
|
|
|
{ |
|
24
|
|
|
return 'Migrate portfolio items to resource nodes'; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @throws Exception |
|
29
|
|
|
*/ |
|
30
|
|
|
public function up(Schema $schema): void |
|
31
|
|
|
{ |
|
32
|
|
|
/** @var ResourceRepository $portfolioRepo */ |
|
33
|
|
|
$portfolioRepo = $this->container->get(PortfolioRepository::class); |
|
|
|
|
|
|
34
|
|
|
$userRepo = $this->container->get(UserRepository::class); |
|
35
|
|
|
|
|
36
|
|
|
$portfolioRows = $this->connection |
|
37
|
|
|
->executeQuery("SELECT * FROM portfolio ORDER BY id ASC") |
|
38
|
|
|
->fetchAllAssociative(); |
|
39
|
|
|
|
|
40
|
|
|
foreach ($portfolioRows as $portfolioRow) { |
|
41
|
|
|
$portfolioId = $portfolioRow['id']; |
|
42
|
|
|
$creatorId = $portfolioRow['user_id']; |
|
43
|
|
|
$courseId = $portfolioRow['c_id']; |
|
44
|
|
|
$sessionId = $portfolioRow['session_id']; |
|
45
|
|
|
$creationDate = new DateTime($portfolioRow['creation_date']); |
|
46
|
|
|
$updateDate = new DateTime($portfolioRow['update_date']); |
|
47
|
|
|
|
|
48
|
|
|
/** @var Portfolio $portfolio */ |
|
49
|
|
|
$portfolio = $portfolioRepo->find($portfolioId); |
|
50
|
|
|
$creator = $userRepo->find($creatorId); |
|
51
|
|
|
$course = $courseId ? $this->findCourse($courseId) : null; |
|
52
|
|
|
$session = $sessionId ? $this->findSession($sessionId) : null; |
|
53
|
|
|
|
|
54
|
|
|
$portfolio->setParent($creator); |
|
55
|
|
|
|
|
56
|
|
|
$resourceNode = $portfolioRepo->addResourceNode( |
|
57
|
|
|
$portfolio, |
|
58
|
|
|
$creator, |
|
59
|
|
|
$creator |
|
60
|
|
|
); |
|
61
|
|
|
|
|
62
|
|
|
$this->entityManager->persist($resourceNode); |
|
|
|
|
|
|
63
|
|
|
$this->entityManager->flush(); |
|
64
|
|
|
|
|
65
|
|
|
$resourceNode |
|
66
|
|
|
->setCreatedAt($creationDate) |
|
67
|
|
|
->setUpdatedAt($updateDate); |
|
68
|
|
|
|
|
69
|
|
|
$this->entityManager->flush(); |
|
70
|
|
|
|
|
71
|
|
|
if ($course) { |
|
72
|
|
|
$resourceVisibility = match ($portfolio->getVisibility()) { |
|
73
|
|
|
Portfolio::VISIBILITY_HIDDEN => ResourceLink::VISIBILITY_DRAFT, |
|
74
|
|
|
Portfolio::VISIBILITY_VISIBLE => ResourceLink::VISIBILITY_PUBLISHED, |
|
75
|
|
|
default => ResourceLink::VISIBILITY_PENDING, |
|
76
|
|
|
}; |
|
77
|
|
|
|
|
78
|
|
|
$courseLink = $portfolio->addCourseLink( |
|
79
|
|
|
$course, |
|
80
|
|
|
$session, |
|
81
|
|
|
null, |
|
82
|
|
|
$resourceVisibility, |
|
83
|
|
|
$creationDate, |
|
84
|
|
|
$updateDate |
|
85
|
|
|
); |
|
86
|
|
|
|
|
87
|
|
|
$this->entityManager->persist($courseLink); |
|
88
|
|
|
$this->entityManager->flush(); |
|
89
|
|
|
|
|
90
|
|
|
|
|
91
|
|
|
$itemsProperty = $this->connection |
|
92
|
|
|
->executeQuery( |
|
93
|
|
|
"SELECT * FROM c_item_property |
|
94
|
|
|
WHERE tool = 'portfolio' AND ref = $portfolioId" |
|
95
|
|
|
) |
|
96
|
|
|
->fetchAllAssociative(); |
|
97
|
|
|
|
|
98
|
|
|
foreach ($itemsProperty as $itemProperty) { |
|
99
|
|
|
if (empty($itemProperty['to_user_id'])) { |
|
100
|
|
|
continue; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** @var User|null $toUser */ |
|
104
|
|
|
$toUser = $userRepo->find($itemProperty['to_user_id']); |
|
105
|
|
|
|
|
106
|
|
|
if (!$toUser) { |
|
107
|
|
|
continue; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
$insertDate = new DateTime($itemProperty['insert_date']); |
|
111
|
|
|
$lastEditDate = new DateTime($itemProperty['lastedit_date']); |
|
112
|
|
|
|
|
113
|
|
|
$userLink = $portfolio->addUserLink( |
|
114
|
|
|
$toUser, |
|
115
|
|
|
$course, |
|
116
|
|
|
$session, |
|
117
|
|
|
null, |
|
118
|
|
|
$insertDate, |
|
119
|
|
|
$lastEditDate |
|
120
|
|
|
); |
|
121
|
|
|
|
|
122
|
|
|
$this->entityManager->persist($userLink); |
|
123
|
|
|
$this->entityManager->flush(); |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
|
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.