Passed
Pull Request — master (#6466)
by
unknown
08:30 queued 21s
created

Version20250709170000::getDescription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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 Doctrine\DBAL\Schema\Schema;
11
12
final class Version20250709170000 extends AbstractMigrationChamilo
13
{
14
    public function getDescription(): string
15
    {
16
        return 'Add default Chamilo CSS theme';
17
    }
18
19
    public function up(Schema $schema): void
20
    {
21
        // Check if template already exists
22
        $name = 'chamilo';
23
        $json = '{"--color-primary-base":"46 117 163","--color-primary-gradient":"-1 86 130","--color-primary-button-text":"46 117 163","--color-primary-button-alternative-text":"255 255 255","--color-secondary-base":"243 126 47","--color-secondary-gradient":"193 81 -31","--color-secondary-button-text":"255 255 255","--color-tertiary-base":"51 51 51","--color-tertiary-gradient":"103 103 103","--color-tertiary-button-text":"51 51 51","--color-success-base":"119 170 12","--color-success-gradient":"80 128 -43","--color-success-button-text":"255 255 255","--color-info-base":"13 123 253","--color-info-gradient":"-33 83 211","--color-info-button-text":"255 255 255","--color-warning-base":"245 206 1","--color-warning-gradient":"189 151 -65","--color-warning-button-text":"0 0 0","--color-danger-base":"223 59 59","--color-danger-gradient":"180 -13 20","--color-danger-button-text":"255 255 255","--color-form-base":"46 117 163"}';
24
        $themeId = $this->connection->fetchOne(
25
            'SELECT id FROM color_theme WHERE slug = ?',
26
            [$name]
27
        );
28
29
        if ($themeId) {
30
            $this->write("Default Chamilo CSS theme already exists. Skipping insert.");
31
        } else {
32
            // Insert color theme
33
            $this->connection->executeStatement(
34
                'INSERT INTO color_theme (title, variables, slug, created_at, updated_at)
35
                 VALUES (?, ?, ?, NOW(), NOW())',
36
                [
37
                    "Chamilo",
38
                    $json,
39
                    $name
40
                ]
41
            );
42
43
            // Get the new ID
44
            $themeId = $this->connection->fetchOne(
45
                'SELECT id FROM color_theme WHERE slug = ?',
46
                [$name]
47
            );
48
49
            if (!$themeId) {
50
                throw new \RuntimeException("Could not retrieve the ID of the newly inserted color theme.");
51
            }
52
53
            // Insert relation into access_url_rel_color_theme
54
            $this->connection->executeStatement(
55
                'INSERT INTO access_url_rel_color_theme (url_id, color_theme_id, active, created_at, updated_at)
56
                 VALUES (?, ?, ?, NOW(), NOW())',
57
                [
58
                    1,
59
                    $themeId,
60
                    1
61
                ]
62
            );
63
64
            $this->write("Added default Chamilo CSS theme and related access URL relation.");
65
        }
66
    }
67
68
    public function down(Schema $schema): void
69
    {
70
        $this->addSql("
71
            DELETE FROM access_url_rel_color_theme
72
            WHERE color_theme_id IN (
73
                SELECT id FROM color_theme WHERE slug = 'chamilo'
74
            )
75
        ");
76
77
        $this->addSql("
78
            DELETE FROM color_theme WHERE slug = 'chamilo'
79
        ");
80
81
        $this->write("Removed default Chamilo CSS theme and related access URL relation.");
82
    }
83
}
84