Skip to content

Commit

Permalink
Internal: Migrate settings from mail.conf.php about smpt* to mail set…
Browse files Browse the repository at this point in the history
…tings - refs BT#21613
  • Loading branch information
AngelFQC committed May 6, 2024
1 parent 6098f3d commit 6c5a93d
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/CoreBundle/Migrations/AbstractMigrationChamilo.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,21 @@ public function getConfigurationValue($variable, $configuration = null)
return false;
}

public function getMailConfigurationValue(string $variable, array $configuration = []): mixed
{
global $platform_email;

if ($configuration) {
$platform_email = $configuration;
}

if (isset($platform_email[$variable])) {
return $platform_email[$variable];
}

return false;
}

/**
* Remove a setting completely.
*
Expand Down Expand Up @@ -332,4 +347,28 @@ public function findSession(int $id): ?Session

return $this->entityManager->find(Session::class, $id);
}

public function getMailConfigurationValueFromFile(string $variable): ?string
{
global $platform_email;

$rootPath = $this->container->get('kernel')->getProjectDir();
$oldConfigPath = $rootPath.'/app/config/mail.conf.php';

$configFileLoaded = \in_array($oldConfigPath, get_included_files(), true);

if (!$configFileLoaded) {
include_once $oldConfigPath;
}

$settingValue = $this->getConfigurationValue($variable, $platform_email);

if (\is_bool($settingValue)) {
$selectedValue = var_export($settingValue, true);
} else {
$selectedValue = (string) $settingValue;
}

return $selectedValue;
}
}
28 changes: 28 additions & 0 deletions src/CoreBundle/Migrations/Schema/V200/Version20240506164100.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Chamilo\CoreBundle\Migrations\Schema\V200;

use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
use Doctrine\DBAL\Schema\Schema;

class Version20240506164100 extends AbstractMigrationChamilo
{

/**
* @inheritDoc
*/
public function up(Schema $schema): void
{
$selectedMailValue = $this->getMailConfigurationValueFromFile('SMTP_UNIQUE_SENDER') ? 'true' : 'false';

$this->addSql("INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url, access_url_changeable, access_url_locked) VALUES ('smtp_unique_sender', null, null, 'mail', '$selectedMailValue', 'smtp_unique_sender', null, '', null, 1, 1, 1)");

$selectedMailValue = $this->getMailConfigurationValueFromFile('SMTP_FROM_EMAIL');

$this->addSql("INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url, access_url_changeable, access_url_locked) VALUES ('smtp_from_email', null, null, 'mail', '$selectedMailValue', 'smtp_from_email', null, '', null, 1, 1, 1)");

$selectedMailValue = $this->getMailConfigurationValueFromFile('SMTP_FROM_NAME');

$this->addSql("INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url, access_url_changeable, access_url_locked) VALUES ('smtp_from_name', null, null, 'mail', '$selectedMailValue', 'smtp_from_name', null, '', null, 1, 1, 1)");
}
}

0 comments on commit 6c5a93d

Please sign in to comment.