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\CoreBundle\Repository\Node\AccessUrlRepository; |
11
|
|
|
use Doctrine\DBAL\Schema\Schema; |
12
|
|
|
use Exception; |
13
|
|
|
|
14
|
|
|
final class Version20250403121200 extends AbstractMigrationChamilo |
15
|
|
|
{ |
16
|
|
|
public function getDescription(): string |
17
|
|
|
{ |
18
|
|
|
return 'Set the first AccessUrl as default for all existing records in ticket_priority, ticket_project, ticket_status, and ticket_ticket if access_url_id is null.'; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function up(Schema $schema): void |
22
|
|
|
{ |
23
|
|
|
$this->entityManager->beginTransaction(); |
|
|
|
|
24
|
|
|
|
25
|
|
|
try { |
26
|
|
|
/** @var AccessUrlRepository $accessUrlRepo */ |
27
|
|
|
$accessUrlRepo = $this->container->get(AccessUrlRepository::class); |
|
|
|
|
28
|
|
|
$firstAccessUrl = $accessUrlRepo->find($accessUrlRepo->getFirstId()); |
29
|
|
|
|
30
|
|
|
if (!$firstAccessUrl) { |
31
|
|
|
throw new Exception('No AccessUrl found for migration'); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
$accessUrlId = $firstAccessUrl->getId(); |
35
|
|
|
|
36
|
|
|
// Update ticket_priority |
37
|
|
|
$this->connection->executeStatement( |
38
|
|
|
'UPDATE ticket_priority SET access_url_id = :accessUrlId WHERE access_url_id IS NULL', |
39
|
|
|
['accessUrlId' => $accessUrlId] |
40
|
|
|
); |
41
|
|
|
|
42
|
|
|
// Update ticket_project |
43
|
|
|
$this->connection->executeStatement( |
44
|
|
|
'UPDATE ticket_project SET access_url_id = :accessUrlId WHERE access_url_id IS NULL', |
45
|
|
|
['accessUrlId' => $accessUrlId] |
46
|
|
|
); |
47
|
|
|
|
48
|
|
|
// Update ticket_status |
49
|
|
|
$this->connection->executeStatement( |
50
|
|
|
'UPDATE ticket_status SET access_url_id = :accessUrlId WHERE access_url_id IS NULL', |
51
|
|
|
['accessUrlId' => $accessUrlId] |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
// Update ticket_ticket |
55
|
|
|
$this->connection->executeStatement( |
56
|
|
|
'UPDATE ticket_ticket SET access_url_id = :accessUrlId WHERE access_url_id IS NULL', |
57
|
|
|
['accessUrlId' => $accessUrlId] |
58
|
|
|
); |
59
|
|
|
|
60
|
|
|
$this->entityManager->commit(); |
61
|
|
|
} catch (Exception $e) { |
62
|
|
|
$this->entityManager->rollBack(); |
63
|
|
|
error_log('[Migration] Failed to set default AccessUrl: ' . $e->getMessage()); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function down(Schema $schema): void |
68
|
|
|
{ |
69
|
|
|
$this->connection->executeStatement('UPDATE ticket_priority SET access_url_id = NULL'); |
70
|
|
|
$this->connection->executeStatement('UPDATE ticket_project SET access_url_id = NULL'); |
71
|
|
|
$this->connection->executeStatement('UPDATE ticket_status SET access_url_id = NULL'); |
72
|
|
|
$this->connection->executeStatement('UPDATE ticket_ticket SET access_url_id = NULL'); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
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.