Passed
Pull Request — master (#5614)
by Angel Fernando Quiroz
16:10 queued 07:37
created

Version20231110194300::getDefaultThemeNames()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 31
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 29
nc 1
nop 0
dl 0
loc 31
rs 9.456
c 1
b 0
f 0
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\Finder\Finder;
12
13
final class Version20231110194300 extends AbstractMigrationChamilo
14
{
15
    public function getDescription(): string
16
    {
17
        return 'Copy custom theme folder to assets and update webpack.config';
18
    }
19
20
    private function getDefaultThemeNames(): array
21
    {
22
        return [
23
            'academica',
24
            'chamilo',
25
            'chamilo_red',
26
            'cosmic_campus',
27
            'holi',
28
            'readable',
29
            'sober_brown',
30
            'baby_orange',
31
            'chamilo_electric_blue',
32
            'chamilo_sport_red',
33
            'delicious_bordeaux',
34
            'journal',
35
            'royal_purple',
36
            'spacelab',
37
            'beach',
38
            'chamilo_green',
39
            'cool_blue',
40
            'empire_green',
41
            'kiddy',
42
            'silver_line',
43
            'steel_grey',
44
            'blue_lagoon',
45
            'chamilo_orange',
46
            'corporate',
47
            'fruity_orange',
48
            'medical',
49
            'simplex',
50
            'tasty_olive',
51
        ];
52
    }
53
54
    public function up(Schema $schema): void
55
    {
56
        $kernel = $this->container->get('kernel');
0 ignored issues
show
Bug introduced by
The method get() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

56
        /** @scrutinizer ignore-call */ 
57
        $kernel = $this->container->get('kernel');

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.

Loading history...
57
        $rootPath = $kernel->getProjectDir();
58
59
        $defaulThemesFolders = $this->getDefaultThemeNames();
60
61
        $sourceDir = $rootPath.'/app/Resources/public/css/themes';
62
63
        if (!is_dir($sourceDir)) {
64
            return;
65
        }
66
67
        $filesystem = $this->container->get('oneup_flysystem.themes_filesystem');
68
69
        $finder = new Finder();
70
        $finder->directories()->in($sourceDir)->depth('== 0');
71
72
        foreach ($finder as $folder) {
73
            $themeFolderName = $folder->getRelativePathname();
74
75
            if (\in_array($themeFolderName, $defaulThemesFolders, true)) {
76
                continue;
77
            }
78
79
            if ($filesystem->directoryExists($themeFolderName)) {
80
                continue;
81
            }
82
83
            $filesystem->createDirectory($themeFolderName);
84
85
            $directory = (new Finder())->in($folder->getRealPath());
86
87
            foreach ($directory as $file) {
88
                if (!$file->isFile()) {
89
                    continue;
90
                }
91
92
                $newFileRelativePathname = $themeFolderName.DIRECTORY_SEPARATOR.$file->getRelativePathname();
93
                $fileContents = $file->getContents();
94
                $filesystem->write($newFileRelativePathname, $fileContents);
95
            }
96
        }
97
    }
98
}
99