File size: 1,449 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
<?php

declare(strict_types=1);

namespace Mautic\Migrations;

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

/**
 * Move config files that contain local config to a folder outside the application data.
 */
final class Versionzz20230929183000 extends AbstractMauticMigration
{
    public function preUp(Schema $schema): void
    {
        [$appConfigDir] = $this->getConfigDirs();

        $matches = glob($appConfigDir.'/*local.php');

        $this->skipIf(
            0 == count($matches),
            'There are no local config files to migrate. Skipping the migration.'
        );
    }

    public function up(Schema $schema): void
    {
        $pathsHelper = $this->container->get('mautic.helper.paths');

        $appConfigDir   = $pathsHelper->getRootPath().'/app/config';
        $localConfigDir = $pathsHelper->getVendorRootPath().'/config';

        $matches = glob($appConfigDir.'/*local.php');

        foreach ($matches as $file) {
            rename($file, $localConfigDir.'/'.pathinfo($file, PATHINFO_BASENAME));
        }
    }

    /**
     * @return string[]
     */
    public function getConfigDirs(): array
    {
        $pathsHelper = $this->container->get('mautic.helper.paths');

        $appConfigDir   = $pathsHelper->getRootPath().'/app/config';
        $localConfigDir = $pathsHelper->getVendorRootPath().'/config';

        return [$appConfigDir, $localConfigDir];
    }
}