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

declare(strict_types=1);

namespace Mautic\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\Exception\SkipMigration;
use Mautic\CoreBundle\Doctrine\AbstractMauticMigration;
use Mautic\PluginBundle\Helper\IntegrationHelper;
use Mautic\SmsBundle\Form\Type\ConfigType;

final class Version20221128145933 extends AbstractMauticMigration
{
    /**
     * @throws SkipMigration
     */
    public function preUp(Schema $schema): void
    {
        /** @var IntegrationHelper $integrationHelper */
        $integrationHelper = $this->container->get('mautic.helper.integration');
        $integration       = $integrationHelper->getIntegrationObject('Twilio');
        $settings          = $integration->getIntegrationSettings()->getFeatureSettings();
        if (empty($settings['disable_trackable_urls'])) {
            throw new SkipMigration('Schema includes this migration');
        }
    }

    public function up(Schema $schema): void
    {
        $confFile = \Mautic\CoreBundle\Loader\ParameterLoader::getLocalConfigFile(__DIR__.'/../');

        if (!file_exists($confFile)) {
            return;
        }

        require $confFile;

        $parameters[ConfigType::SMS_DISABLE_TRACKABLE_URLS] = 1;
        // Write updated config to local.php
        $result = file_put_contents($confFile, "<?php\n".'$parameters = '.var_export($parameters, true).';');

        if (false === $result) {
            throw new \Exception(sprintf("Couldn't update configuration file with enabled %s", ConfigType::SMS_DISABLE_TRACKABLE_URLS));
        }
    }
}