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 Doctrine\DBAL\Schema\Schema; |
11
|
|
|
|
12
|
|
|
final class Version20251008180700 extends AbstractMigrationChamilo |
13
|
|
|
{ |
14
|
|
|
public function getDescription(): string |
15
|
|
|
{ |
16
|
|
|
return 'ExtraField: deduplicate organisationemail/azure_id (USER), fix display_text, and add unique index on (variable, item_type).'; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function up(Schema $schema): void |
20
|
|
|
{ |
21
|
|
|
// Normalize labels |
22
|
|
|
// USER (item_type = 1) |
23
|
|
|
$this->addSql("UPDATE extra_field SET display_text = 'LinkedIn profile URL' WHERE item_type = 1 AND variable = 'linkedin_url'"); |
24
|
|
|
$this->addSql("UPDATE extra_field SET display_text = 'Tags' WHERE item_type = 1 AND variable = 'tags'"); |
25
|
|
|
$this->addSql("UPDATE extra_field SET display_text = 'Legal agreement accepted' WHERE item_type = 1 AND variable = 'legal_accept'"); |
26
|
|
|
$this->addSql("UPDATE extra_field SET display_text = 'GDPR' WHERE item_type = 1 AND variable = 'gdpr'"); |
27
|
|
|
|
28
|
|
|
// COURSE (item_type = 2) |
29
|
|
|
$this->addSql("UPDATE extra_field SET display_text = 'Video URL' WHERE item_type = 2 AND variable = 'video_url'"); |
30
|
|
|
|
31
|
|
|
// Enforce expected labels for Azure-related fields and deduplicate |
32
|
|
|
// A: organisationemail (USER): enforce correct label and keep a single row |
33
|
|
|
$this->addSql("UPDATE extra_field SET display_text = 'Organisation e-mail' WHERE item_type = 1 AND variable = 'organisationemail'"); |
34
|
|
|
$this->addSql(" |
35
|
|
|
DELETE FROM extra_field |
36
|
|
|
WHERE item_type = 1 |
37
|
|
|
AND variable = 'organisationemail' |
38
|
|
|
AND id NOT IN ( |
39
|
|
|
SELECT id FROM ( |
40
|
|
|
SELECT MIN(id) AS id |
41
|
|
|
FROM extra_field |
42
|
|
|
WHERE item_type = 1 AND variable = 'organisationemail' |
43
|
|
|
) t |
44
|
|
|
) |
45
|
|
|
"); |
46
|
|
|
|
47
|
|
|
// B: azure_id (USER): enforce correct label and keep a single row |
48
|
|
|
$this->addSql("UPDATE extra_field SET display_text = 'Azure ID (mailNickname)' WHERE item_type = 1 AND variable = 'azure_id'"); |
49
|
|
|
$this->addSql(" |
50
|
|
|
DELETE FROM extra_field |
51
|
|
|
WHERE item_type = 1 |
52
|
|
|
AND variable = 'azure_id' |
53
|
|
|
AND id NOT IN ( |
54
|
|
|
SELECT id FROM ( |
55
|
|
|
SELECT MIN(id) AS id |
56
|
|
|
FROM extra_field |
57
|
|
|
WHERE item_type = 1 AND variable = 'azure_id' |
58
|
|
|
) t |
59
|
|
|
) |
60
|
|
|
"); |
61
|
|
|
|
62
|
|
|
// Unique index to prevent future duplicates |
63
|
|
|
$this->addSql('CREATE UNIQUE INDEX uniq_extra_field_variable_itemtype ON extra_field (variable, item_type)'); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function down(Schema $schema): void |
67
|
|
|
{ |
68
|
|
|
// Drop unique index |
69
|
|
|
$this->addSql('DROP INDEX uniq_extra_field_variable_itemtype ON extra_field'); |
70
|
|
|
|
71
|
|
|
// Revert labels (optional). If you prefer not to revert, you can omit these lines. |
72
|
|
|
$this->addSql("UPDATE extra_field SET display_text = 'LinkedInUrl' WHERE item_type = 1 AND variable = 'linkedin_url'"); |
73
|
|
|
$this->addSql("UPDATE extra_field SET display_text = 'tags' WHERE item_type = 1 AND variable = 'tags'"); |
74
|
|
|
$this->addSql("UPDATE extra_field SET display_text = 'Legal' WHERE item_type = 1 AND variable = 'legal_accept'"); |
75
|
|
|
$this->addSql("UPDATE extra_field SET display_text = 'GDPR compliance' WHERE item_type = 1 AND variable = 'gdpr'"); |
76
|
|
|
$this->addSql("UPDATE extra_field SET display_text = 'VideoUrl' WHERE item_type = 2 AND variable = 'video_url'"); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|