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\Migrations\AbstractMigrationChamilo; |
10
|
|
|
use Chamilo\CourseBundle\Repository\CLpCategoryRepository; |
11
|
|
|
use Chamilo\CourseBundle\Repository\CLpRepository; |
12
|
|
|
use Chamilo\CourseBundle\Repository\CShortcutRepository; |
13
|
|
|
use Doctrine\DBAL\Schema\Schema; |
14
|
|
|
|
15
|
|
|
class Version20240327172830 extends AbstractMigrationChamilo |
16
|
|
|
{ |
17
|
|
|
public function getDescription(): string |
18
|
|
|
{ |
19
|
|
|
return 'Create shortcuts for c_lp and c_lp_category published on course home'; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function up(Schema $schema): void |
23
|
|
|
{ |
24
|
|
|
// File generated in the Version20180928172830 migration |
25
|
|
|
$toolLinksContent = $this->readFile('tool_links'); |
26
|
|
|
|
27
|
|
|
if (empty($toolLinksContent)) { |
28
|
|
|
$this->write('tool_links file not found. Exiting.'); |
29
|
|
|
|
30
|
|
|
return; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
$toolLinks = unserialize($toolLinksContent); |
34
|
|
|
|
35
|
|
|
$lpRepo = $this->container->get(CLpRepository::class); |
|
|
|
|
36
|
|
|
$lpCategoryRepo = $this->container->get(CLpCategoryRepository::class); |
37
|
|
|
$shortcutRepo = $this->container->get(CShortcutRepository::class); |
38
|
|
|
|
39
|
|
|
foreach ($toolLinks as $toolLink) { |
40
|
|
|
$url = parse_url($toolLink['link']); |
41
|
|
|
$query = []; |
42
|
|
|
parse_str($url['query'] ?? '', $query); |
43
|
|
|
|
44
|
|
|
$admin = $this->getAdmin(); |
45
|
|
|
$course = $this->findCourse($toolLink['c_id']); |
46
|
|
|
$session = $this->findSession($toolLink['session_id']); |
47
|
|
|
$resource = null; |
48
|
|
|
|
49
|
|
|
if (str_contains($url['path'], 'lp_controller.php') && isset($query['action'])) { |
50
|
|
|
if (isset($query['lp_id']) && 'view' === $query['action']) { |
51
|
|
|
$resource = $lpRepo->find($query['lp_id']); |
52
|
|
|
} elseif (isset($query['id']) && 'view_category' === $query['action']) { |
53
|
|
|
$resource = $lpCategoryRepo->find($query['id']); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
if ($resource) { |
58
|
|
|
$shortcut = $shortcutRepo->getShortcutFromResource($resource); |
59
|
|
|
|
60
|
|
|
if ($shortcut) { |
61
|
|
|
continue; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$shortcutRepo->addShortCut($resource, $admin, $course, $session); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
$this->entityManager->flush(); |
|
|
|
|
69
|
|
|
|
70
|
|
|
$this->removeFile('tool_links'); |
71
|
|
|
} |
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.