Spaces:
No application file
No application file
File size: 3,643 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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
<?php
namespace Mautic\InstallBundle\Configurator\Step;
use Mautic\CoreBundle\Configurator\Configurator;
use Mautic\CoreBundle\Configurator\Step\StepInterface;
use Mautic\InstallBundle\Configurator\Form\DoctrineStepType;
/**
* @author Fabien Potencier <fabien@symfony.com>
*/
class DoctrineStep implements StepInterface
{
/**
* Database driver.
*/
public $driver = 'pdo_mysql';
/**
* Database host.
*/
public $host = 'localhost';
/**
* Database host. Read Only Replica.
*/
public ?string $host_ro = null;
/**
* Database table prefix.
* Required in step.
*
* @var string
*/
public $table_prefix;
/**
* Database connection port.
*/
public $port = 3306;
/**
* Database name.
*/
public $name;
/**
* Database user.
*/
public $user;
/**
* Database user's password.
*
* @var string
*/
public $password;
/**
* Backup tables if they exist; otherwise drop them.
* Required in step.
*
* @var bool
*/
public $backup_tables = true;
/**
* Prefix for backup tables.
* Required in step.
*
* @var string
*/
public $backup_prefix = 'bak_';
public ?string $server_version;
public function __construct(Configurator $configurator)
{
$parameters = $configurator->getParameters();
foreach ($parameters as $key => $value) {
if (str_starts_with($key, 'db_')) {
$parameters[substr($key, 3)] = $value;
$key = substr($key, 3);
$this->$key = $value;
}
}
}
public function getFormType(): string
{
return DoctrineStepType::class;
}
public function checkRequirements(): array
{
$messages = [];
if (!class_exists('\PDO')) {
$messages[] = 'mautic.install.pdo.mandatory';
} else {
if (!in_array('mysql', \PDO::getAvailableDrivers(), true)) {
$messages[] = 'mautic.install.pdo.drivers';
}
}
return $messages;
}
public function checkOptionalSettings(): array
{
return [];
}
/**
* @return mixed[]
*/
public function update(StepInterface $data): array
{
$parameters = [];
foreach ($data as $key => $value) {
$parameters['db_'.$key] = $value;
}
return $parameters;
}
public function getTemplate(): string
{
return '@MauticInstall/Install/doctrine.html.twig';
}
/**
* Return the key values of the available driver array.
* Required in step.
*
* @see \Mautic\InstallBundle\Configurator\Form\DoctrineStepType::buildForm()
*/
public static function getDriverKeys(): array
{
return array_keys(static::getDrivers());
}
/**
* Fetches the available database drivers for the environment.
*/
public static function getDrivers(): array
{
$mauticSupported = [
'pdo_mysql' => 'MySQL PDO (Recommended)',
];
$supported = [];
// Add PDO drivers if supported
if (class_exists('\PDO')) {
$pdoDrivers = \PDO::getAvailableDrivers();
foreach ($pdoDrivers as $driver) {
if (array_key_exists('pdo_'.$driver, $mauticSupported)) {
$supported['pdo_'.$driver] = $mauticSupported['pdo_'.$driver];
}
}
}
return $supported;
}
}
|