added options for testing

This commit is contained in:
tracer 2022-10-08 10:55:25 +02:00
parent 91ea53275e
commit 2965e9b7ce
1 changed files with 20 additions and 19 deletions

View File

@ -2,7 +2,7 @@
namespace App\Controller;
error_reporting(error_level: E_ALL);
//error_reporting(error_level: E_ALL);
use PDO;
@ -15,31 +15,32 @@ class DatabaseConnection
{
private PDO $dbConnection;
const TABLE_PREFIX = '';
const TABLE_DOMAINS = self::TABLE_PREFIX . "domains";
const TABLE_PREFIX = '';
const TABLE_DOMAINS = self::TABLE_PREFIX . "domains";
const TABLE_NAMESERVERS = self::TABLE_PREFIX . "nameservers";
const TABLE_PANELS = self::TABLE_PREFIX . "panels";
const TABLE_APIKEYS = self::TABLE_PREFIX . "apikeys";
const TABLE_DYNDNS = self::TABLE_PREFIX . "dyndns";
const TABLE_PANELS = self::TABLE_PREFIX . "panels";
const TABLE_APIKEYS = self::TABLE_PREFIX . "apikeys";
const TABLE_DYNDNS = self::TABLE_PREFIX . "dyndns";
public function __construct(private readonly ConfigController $configController)
{
$dbHost = $this->configController->getConfig(configKey: 'dbHost');
$dbPort = $this->configController->getConfig(configKey: 'dbPort');
$dbHost = $this->configController->getConfig(configKey: 'dbHost');
$dbPort = $this->configController->getConfig(configKey: 'dbPort');
$dbDatabase = $this->configController->getConfig(configKey: 'dbDatabase');
$dbUser = $this->configController->getConfig(configKey: 'dbUser');
$dbUser = $this->configController->getConfig(configKey: 'dbUser');
$dbPassword = $this->configController->getConfig(configKey: 'dbPassword');
$this->dbConnection = new PDO(
dsn: "mysql:host=$dbHost;port=$dbPort;charset=utf8mb4;dbname=$dbDatabase",
username: $dbUser,
password: $dbPassword
);
if (!$this->configController->getConfig(configKey: 'test')) {
// TODO create config => encryption key
try {
$this->dbConnection = new PDO(
dsn: "mysql:host=$dbHost;port=$dbPort;charset=utf8mb4;dbname=$dbDatabase",
username: $dbUser,
password: $dbPassword
);
$sql = "SHOW TABLES";
$statement = $this->dbConnection->prepare(query: $sql);
$statement->execute();
$result = $statement->fetch();
@ -47,7 +48,7 @@ class DatabaseConnection
// ALTER TABLE `domains` ADD `panel_id` INT NULL AFTER `id`;
echo 'Error: Cannot find tables.' . PHP_EOL;
if (confirm(message: 'Should I try to create them?')) {
$sql = "
$sql = "
CREATE TABLE `apikeys` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
@ -58,7 +59,7 @@ class DatabaseConnection
$statement = $this->dbConnection->prepare(query: $sql);
$statement->execute();
$sql = "
$sql = "
CREATE TABLE `domains` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
@ -68,7 +69,7 @@ class DatabaseConnection
$statement = $this->dbConnection->prepare(query: $sql);
$statement->execute();
$sql = "
$sql = "
CREATE TABLE `nameservers` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
@ -80,7 +81,7 @@ class DatabaseConnection
$statement = $this->dbConnection->prepare(query: $sql);
$statement->execute();
$sql = "
$sql = "
CREATE TABLE `panels` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
@ -133,7 +134,7 @@ class DatabaseConnection
*/
function generatePassword(int $length = 8): string
{
$chars = '23456789bcdfhkmnprstvzBCDFHJKLMNPRSTVZ';
$chars = '23456789bcdfhkmnprstvzBCDFHJKLMNPRSTVZ';
$shuffled = str_shuffle(string: $chars);
return mb_substr(string: $shuffled, start: 0, length: $length);
}