Skip to content

Commit 71e903f

Browse files
Internal: Add migration for default Chamilo color theme and URL relation
1 parent b36c0c0 commit 71e903f

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

src/CoreBundle/Migrations/Schema/V200/Version20250709170000.php

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,35 +27,57 @@ public function up(Schema $schema): void
2727
);
2828

2929
if ($themeId) {
30-
// a Chamilo style is already there, do nothing
30+
$this->write("Default Chamilo CSS theme already exists. Skipping insert.");
3131
} else {
32+
// Insert color theme
3233
$this->connection->executeStatement(
3334
'INSERT INTO color_theme (title, variables, slug, created_at, updated_at)
34-
VALUES (?, ?, ?, NOW(), NOW())',
35+
VALUES (?, ?, ?, NOW(), NOW())',
3536
[
3637
"Chamilo",
3738
$json,
3839
$name
3940
]
4041
);
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
4154
$this->connection->executeStatement(
4255
'INSERT INTO access_url_rel_color_theme (url_id, color_theme_id, active, created_at, updated_at)
43-
VALUES (?, ?, ?, NOW(), NOW())',
56+
VALUES (?, ?, ?, NOW(), NOW())',
4457
[
4558
1,
46-
1,
59+
$themeId,
4760
1
4861
]
4962
);
63+
64+
$this->write("Added default Chamilo CSS theme and related access URL relation.");
5065
}
51-
$this->write("Added default Chamilo CSS theme in the color_theme table.");
5266
}
5367

5468
public function down(Schema $schema): void
5569
{
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+
5677
$this->addSql("
5778
DELETE FROM color_theme WHERE slug = 'chamilo'
5879
");
59-
$this->write("Removed default Chamilo CSS theme in the color_theme table.");
80+
81+
$this->write("Removed default Chamilo CSS theme and related access URL relation.");
6082
}
6183
}

0 commit comments

Comments
 (0)