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\Migrations\AbstractMigrationChamilo; |
10
|
|
|
use Chamilo\CourseBundle\Entity\CLink; |
11
|
|
|
use Chamilo\CourseBundle\Repository\CLinkRepository; |
12
|
|
|
use Chamilo\CourseBundle\Repository\CShortcutRepository; |
13
|
|
|
use Doctrine\DBAL\Schema\Schema; |
14
|
|
|
use Exception; |
15
|
|
|
|
16
|
|
|
class Version20240202122300 extends AbstractMigrationChamilo |
17
|
|
|
{ |
18
|
|
|
public function getDescription(): string |
19
|
|
|
{ |
20
|
|
|
return 'Create shortcuts for c_link entries with on_homepage = 1'; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function up(Schema $schema): void |
24
|
|
|
{ |
25
|
|
|
$admin = $this->getAdmin(); |
26
|
|
|
|
27
|
|
|
$linkRepo = $this->container->get(CLinkRepository::class); |
|
|
|
|
28
|
|
|
$shortcutRepo = $this->container->get(CShortcutRepository::class); |
29
|
|
|
|
30
|
|
|
$sql = 'SELECT * FROM c_link WHERE on_homepage = 1'; |
31
|
|
|
$stmt = $this->connection->prepare($sql); |
32
|
|
|
$result = $stmt->executeQuery(); |
33
|
|
|
|
34
|
|
|
while ($row = $result->fetchAssociative()) { |
35
|
|
|
$linkId = $row['iid']; |
36
|
|
|
|
37
|
|
|
/** @var CLink $link */ |
38
|
|
|
$link = $linkRepo->find($linkId); |
39
|
|
|
|
40
|
|
|
if (!$link) { |
41
|
|
|
error_log("Link with ID $linkId not found"); |
42
|
|
|
|
43
|
|
|
continue; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
if (null === $link->getFirstResourceLink()) { |
47
|
|
|
error_log("Link with ID $linkId does not have a resource_node"); |
48
|
|
|
|
49
|
|
|
continue; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$course = $link->getFirstResourceLink()->getCourse(); |
53
|
|
|
$session = $link->getFirstResourceLink()->getSession(); |
54
|
|
|
|
55
|
|
|
$shortcut = $shortcutRepo->getShortcutFromResource($link); |
56
|
|
|
if (null === $shortcut) { |
57
|
|
|
try { |
58
|
|
|
$shortcutRepo->addShortCut($link, $admin, $course, $session); |
59
|
|
|
error_log("Shortcut created for link ID $linkId"); |
60
|
|
|
} catch (Exception $e) { |
61
|
|
|
error_log("Failed to create shortcut for link ID $linkId: ".$e->getMessage()); |
62
|
|
|
} |
63
|
|
|
} else { |
64
|
|
|
error_log("Shortcut already exists for link ID $linkId"); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
$this->entityManager->flush(); |
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function down(Schema $schema): void {} |
72
|
|
|
} |
73
|
|
|
|
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.