|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Chamilo\CoreBundle\Migrations\Schema\V200; |
|
6
|
|
|
|
|
7
|
|
|
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo; |
|
8
|
|
|
use Doctrine\DBAL\Schema\Schema; |
|
9
|
|
|
|
|
10
|
|
|
final class Version20250306101000 extends AbstractMigrationChamilo |
|
11
|
|
|
{ |
|
12
|
|
|
public function getDescription(): string |
|
13
|
|
|
{ |
|
14
|
|
|
return 'Migrate data from the settings table to the new plugin table.'; |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
public function up(Schema $schema): void |
|
18
|
|
|
{ |
|
19
|
|
|
// Insert unique plugin data from settings to plugin |
|
20
|
|
|
$this->addSql(" |
|
21
|
|
|
INSERT INTO plugin (title, installed, active, version, access_url_id, configuration, source) |
|
22
|
|
|
SELECT |
|
23
|
|
|
subkey AS title, |
|
24
|
|
|
MAX(IF(variable = 'status', 1, 0)) AS installed, |
|
25
|
|
|
MAX(IF(selected_value = 'true', 1, 0)) AS active, |
|
26
|
|
|
'1.0.0' AS version, |
|
27
|
|
|
access_url AS access_url_id, |
|
28
|
|
|
'{}' AS configuration, |
|
29
|
|
|
'third_party' AS source |
|
30
|
|
|
FROM settings |
|
31
|
|
|
WHERE category = 'plugins' |
|
32
|
|
|
GROUP BY subkey; |
|
33
|
|
|
"); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function down(Schema $schema): void |
|
37
|
|
|
{ |
|
38
|
|
|
// Restore data back to settings if rolling back |
|
39
|
|
|
$this->addSql(" |
|
40
|
|
|
INSERT INTO settings (variable, subkey, type, category, selected_value, title, access_url) |
|
41
|
|
|
SELECT |
|
42
|
|
|
'status' AS variable, |
|
43
|
|
|
title AS subkey, |
|
44
|
|
|
'setting' AS type, |
|
45
|
|
|
'plugins' AS category, |
|
46
|
|
|
IF(active = 1, 'true', 'false') AS selected_value, |
|
47
|
|
|
title AS title, |
|
48
|
|
|
access_url_id AS access_url |
|
49
|
|
|
FROM plugin; |
|
50
|
|
|
"); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|