File size: 1,783 Bytes
d2897cd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php

declare(strict_types=1);

namespace Mautic\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Mautic\CoreBundle\Configurator\Configurator;
use Mautic\CoreBundle\Doctrine\AbstractMauticMigration;

final class Version20230627140512 extends AbstractMauticMigration
{
    public function preUp(Schema $schema): void
    {
        $configurator = $this->getConfigurator();

        $this->skipIf(
            !$configurator->isFileWritable(),
            'The local.php file is not writable. Skipping the migration. Replace the usages of "%kernel.root_dir%" in your local.config file with "%kernel.project_dir%/app".'
        );

        $this->skipIf(
            !str_contains($configurator->render(), '%kernel.root_dir%'),
            'The deprecated %kernel.root_dir% is unused. Your local.php file is just fine. Skipping the migration.'
        );
    }

    public function up(Schema $schema): void
    {
        $configurator = $this->getConfigurator();

        $configurator->mergeParameters(
            array_map(
                function ($value) {
                    if (is_string($value) && str_contains($value, '%kernel.root_dir%/..')) {
                        return str_replace('%kernel.root_dir%/..', '%kernel.project_dir%', $value);
                    }
                    if (is_string($value) && str_contains($value, '%kernel.root_dir%')) {
                        return str_replace('%kernel.root_dir%', '%kernel.project_dir%/app', $value);
                    }

                    return $value;
                },
                $configurator->getParameters()
            )
        );

        $configurator->write();
    }

    private function getConfigurator(): Configurator
    {
        return $this->container->get(Configurator::class);
    }
}