Skip to content

Commit 093bc64

Browse files
Merge pull request #6466 from christianbeeznest/christian/colors
Internal: Add default color theme on install/migrate - refs #3793 #6458
2 parents 66db814 + 71e903f commit 093bc64

File tree

2 files changed

+165
-0
lines changed

2 files changed

+165
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/* For licensing terms, see /license.txt */
6+
7+
namespace Chamilo\CoreBundle\DataFixtures;
8+
9+
use Chamilo\CoreBundle\Entity\AccessUrlRelColorTheme;
10+
use Chamilo\CoreBundle\Entity\ColorTheme;
11+
use Chamilo\CoreBundle\Helpers\AccessUrlHelper;
12+
use Doctrine\Bundle\FixturesBundle\Fixture;
13+
use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface;
14+
use Doctrine\Persistence\ObjectManager;
15+
16+
class ColorThemeFixtures extends Fixture implements FixtureGroupInterface
17+
{
18+
public function __construct(
19+
private readonly AccessUrlHelper $accessUrlHelper
20+
) {}
21+
22+
public static function getGroups(): array
23+
{
24+
return ['color_theme'];
25+
}
26+
27+
public function load(ObjectManager $manager): void
28+
{
29+
$existing = $manager->getRepository(ColorTheme::class)
30+
->findOneBy(['slug' => 'chamilo']);
31+
32+
if ($existing) {
33+
echo "Chamilo color theme already exists. Skipping fixture.\n";
34+
return;
35+
}
36+
37+
$theme = (new ColorTheme())
38+
->setTitle('Chamilo')
39+
->setSlug('chamilo')
40+
->setVariables([
41+
'--color-primary-base' => '46 117 163',
42+
'--color-primary-gradient' => '-1 86 130',
43+
'--color-primary-button-text' => '46 117 163',
44+
'--color-primary-button-alternative-text' => '255 255 255',
45+
'--color-secondary-base' => '243 126 47',
46+
'--color-secondary-gradient' => '193 81 -31',
47+
'--color-secondary-button-text' => '255 255 255',
48+
'--color-tertiary-base' => '51 51 51',
49+
'--color-tertiary-gradient' => '103 103 103',
50+
'--color-tertiary-button-text' => '51 51 51',
51+
'--color-success-base' => '119 170 12',
52+
'--color-success-gradient' => '80 128 -43',
53+
'--color-success-button-text' => '255 255 255',
54+
'--color-info-base' => '13 123 253',
55+
'--color-info-gradient' => '-33 83 211',
56+
'--color-info-button-text' => '255 255 255',
57+
'--color-warning-base' => '245 206 1',
58+
'--color-warning-gradient' => '189 151 -65',
59+
'--color-warning-button-text' => '0 0 0',
60+
'--color-danger-base' => '223 59 59',
61+
'--color-danger-gradient' => '180 -13 20',
62+
'--color-danger-button-text' => '255 255 255',
63+
'--color-form-base' => '46 117 163',
64+
])
65+
;
66+
67+
$accessUrl = $this->accessUrlHelper->getCurrent();
68+
69+
$accessUrlRel = (new AccessUrlRelColorTheme())
70+
->setUrl($accessUrl)
71+
->setColorTheme($theme)
72+
->setActive(true);
73+
74+
$theme->addUrl($accessUrlRel);
75+
76+
$manager->persist($theme);
77+
$manager->persist($accessUrlRel);
78+
$manager->flush();
79+
80+
echo "Chamilo color theme fixture loaded successfully.\n";
81+
}
82+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
}

0 commit comments

Comments
 (0)