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
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
12
|
|
|
use Symfony\Component\Finder\Finder; |
13
|
|
|
|
14
|
|
|
final class Version20231110194300 extends AbstractMigrationChamilo |
15
|
|
|
{ |
16
|
|
|
public function getDescription(): string |
17
|
|
|
{ |
18
|
|
|
return 'Copy custom theme folder to assets and update webpack.config'; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
private function getDefaultThemeNames(): array |
22
|
|
|
{ |
23
|
|
|
return [ |
24
|
|
|
'academica', |
25
|
|
|
'chamilo', |
26
|
|
|
'chamilo_red', |
27
|
|
|
'cosmic_campus', |
28
|
|
|
'holi', |
29
|
|
|
'readable', |
30
|
|
|
'sober_brown', |
31
|
|
|
'baby_orange', |
32
|
|
|
'chamilo_electric_blue', |
33
|
|
|
'chamilo_sport_red', |
34
|
|
|
'delicious_bordeaux', |
35
|
|
|
'journal', |
36
|
|
|
'royal_purple', |
37
|
|
|
'spacelab', |
38
|
|
|
'beach', |
39
|
|
|
'chamilo_green', |
40
|
|
|
'cool_blue', |
41
|
|
|
'empire_green', |
42
|
|
|
'kiddy', |
43
|
|
|
'silver_line', |
44
|
|
|
'steel_grey', |
45
|
|
|
'blue_lagoon', |
46
|
|
|
'chamilo_orange', |
47
|
|
|
'corporate', |
48
|
|
|
'fruity_orange', |
49
|
|
|
'medical', |
50
|
|
|
'simplex', |
51
|
|
|
'tasty_olive', |
52
|
|
|
]; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function up(Schema $schema): void |
56
|
|
|
{ |
57
|
|
|
$kernel = $this->container->get('kernel'); |
|
|
|
|
58
|
|
|
$rootPath = $kernel->getProjectDir(); |
59
|
|
|
|
60
|
|
|
$defaulThemesFolders = $this->getDefaultThemeNames(); |
61
|
|
|
|
62
|
|
|
$sourceDir = $rootPath.'/app/Resources/public/css/themes'; |
63
|
|
|
$destinationDir = $rootPath.'/assets/css/themes/'; |
64
|
|
|
$chamiloDefaultCssPath = $destinationDir.'chamilo/default.css'; |
65
|
|
|
|
66
|
|
|
if (!is_dir($sourceDir)) { |
67
|
|
|
return; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$finder = new Finder(); |
71
|
|
|
$finder->directories()->in($sourceDir)->depth('== 0'); |
72
|
|
|
$newThemes = []; |
73
|
|
|
foreach ($finder as $folder) { |
74
|
|
|
$folderName = $folder->getRelativePathname(); |
75
|
|
|
|
76
|
|
|
if (!\in_array($folderName, $defaulThemesFolders, true)) { |
77
|
|
|
$sourcePath = $folder->getRealPath(); |
78
|
|
|
$destinationPath = $destinationDir.$folderName; |
79
|
|
|
|
80
|
|
|
if (!file_exists($destinationPath)) { |
81
|
|
|
$this->copyDirectory($sourcePath, $destinationPath); |
82
|
|
|
$newThemes[] = $folderName; |
83
|
|
|
|
84
|
|
|
if (file_exists($chamiloDefaultCssPath)) { |
85
|
|
|
$newThemeDefaultCssPath = $destinationPath.'/default.css'; |
86
|
|
|
copy($chamiloDefaultCssPath, $newThemeDefaultCssPath); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
$this->updateWebpackConfig($rootPath, $newThemes); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
private function copyDirectory($src, $dst): void |
96
|
|
|
{ |
97
|
|
|
$dir = opendir($src); |
98
|
|
|
@mkdir($dst); |
|
|
|
|
99
|
|
|
while (false !== ($file = readdir($dir))) { |
100
|
|
|
if (('.' !== $file) && ('..' !== $file)) { |
101
|
|
|
if (is_dir($src.'/'.$file)) { |
102
|
|
|
$this->copyDirectory($src.'/'.$file, $dst.'/'.$file); |
103
|
|
|
} else { |
104
|
|
|
copy($src.'/'.$file, $dst.'/'.$file); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
closedir($dir); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
private function updateWebpackConfig(string $rootPath, array $newThemes): void |
112
|
|
|
{ |
113
|
|
|
$webpackConfigPath = $rootPath.'/webpack.config.js'; |
114
|
|
|
|
115
|
|
|
if (!file_exists($webpackConfigPath)) { |
116
|
|
|
return; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
$content = file_get_contents($webpackConfigPath); |
120
|
|
|
$pattern = '/(const themes = \\[\\s*")([^"\\]]+)("\\s*\\])/'; |
121
|
|
|
$replacement = function ($matches) use ($newThemes) { |
122
|
|
|
$existingThemes = explode('", "', trim($matches[2], '"')); |
123
|
|
|
$allThemes = array_unique(array_merge($existingThemes, $newThemes)); |
124
|
|
|
$newThemesString = implode('", "', $allThemes); |
125
|
|
|
|
126
|
|
|
return $matches[1].$newThemesString.$matches[3]; |
127
|
|
|
}; |
128
|
|
|
|
129
|
|
|
$newContent = preg_replace_callback($pattern, $replacement, $content); |
130
|
|
|
|
131
|
|
|
file_put_contents($webpackConfigPath, $newContent); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.