From d775541f753fda342ce78b8de87fb85dc0ab34c2 Mon Sep 17 00:00:00 2001 From: Luca Date: Mon, 5 Dec 2022 17:44:20 +0100 Subject: [PATCH] Introduzione options per connessione al db --- config.example.php | 4 +++ include/init/requirements.php | 65 ++++++++++++++++++++++++++++++----- src/Database.php | 4 ++- 3 files changed, 63 insertions(+), 10 deletions(-) diff --git a/config.example.php b/config.example.php index 3f982f57d..38138417a 100755 --- a/config.example.php +++ b/config.example.php @@ -23,6 +23,10 @@ $db_username = '|username|'; $db_password = '|password|'; $db_name = '|database|'; //$port = '|port|'; +$db_options = [ + //'sort_buffer_size' => '4M', +]; + // Percorso della cartella di backup $backup_dir = __DIR__.'/backup/'; diff --git a/include/init/requirements.php b/include/init/requirements.php index 477cf0901..30644efbe 100755 --- a/include/init/requirements.php +++ b/include/init/requirements.php @@ -182,29 +182,76 @@ if ($database->isInstalled()){ $db = [ 'mysql_version' => [ - 'type' => 'mysql', + 'type' => 'version', 'description' => '5.7.x - 8.0.x', 'minimum' => '5.7.0', 'maximum' => '8.0.99', ], ]; + + foreach (App::getConfig()['db_options'] as $n => $v){ + + switch ($n){ + case 'sort_buffer_size': + $db[$n] = [ + 'type' => 'value', + 'description' => '>4M', + ]; + break; + } + + } + } foreach ($db as $name => $values) { - $description = $values['description']; - $description = tr('Valore consigliato: _VALUE_ (Valore attuale: _MYSQL_VERSION_)', [ - '_VALUE_' => $description, - '_MYSQL_VERSION_' => $database->getMySQLVersion(), - ]); - $status = ((version_compare($database->getMySQLVersion(), $values['minimum'], ">=") && version_compare($database->getMySQLVersion(), $values['maximum'], "<=")) ? 1 : 0); + $description = $values['description']; + + if ($values['type'] == 'version') { + + $type = tr('Versione'); + $description = tr('Valore consigliato: _VALUE_ (Valore attuale: _MYSQL_VERSION_)', [ + '_VALUE_' => $description, + '_MYSQL_VERSION_' => $database->getMySQLVersion(), + ]); + + $status = ((version_compare($database->getMySQLVersion(), $values['minimum'], ">=") && version_compare($database->getMySQLVersion(), $values['maximum'], "<=")) ? 1 : 0); + + } else{ + $type = tr('Impostazione'); + + $inc = str_replace(['k', 'M'], ['000', '000000'], App::getConfig()['db_options'][$name]); + $real = str_replace(['k', 'M'], ['000', '000000'], $description); + + if (string_starts_with($real, '>')) { + $status = $inc >= substr($real, 1); + } elseif (string_starts_with($real, '<')) { + $status = $inc <= substr($real, 1); + } else { + $status = ($real == $inc); + } + + if (is_bool($description)) { + $description = !empty($description) ? 'On' : 'Off'; + } else { + $description = str_replace(['>', '<'], '', $description); + } + + + $description = tr('Valore consigliato: _VALUE_ (Valore attuale: _INI_)', [ + '_VALUE_' => $description, + '_INI_' => App::getConfig()['db_options'][$name], + ]); + + } $mysql[] = [ 'name' => $name, 'description' => $description, 'status' => $status, - 'type' => tr('Versione'), + 'type' => $type, ]; } @@ -232,7 +279,7 @@ foreach ($dirs_to_check as $name => $description) { // File di servizio $files_to_check = [ - 'manifest.json' => tr('Necessario per aggiunta a schermata home da terminale'), + 'manifest.json' => tr('Necessario per l\'aggiunta a schermata home da terminale'), 'database_5_7.json' => tr('Necessario per il controllo integrità con database MySQL 5.7.x'), 'database.json' => tr('Necessario per il controllo integrità con database MySQL 8.0.x'), 'checksum.json' => tr('Necessario per il controllo integrità dei files del gestionale'), diff --git a/src/Database.php b/src/Database.php index 1a0a57ee2..f691bf53a 100755 --- a/src/Database.php +++ b/src/Database.php @@ -80,9 +80,11 @@ class Database extends Util\Singleton 'database' => $database_name, 'username' => $username, 'password' => $password, - 'charset' => 'utf8', + 'charset' => 'utf8mb4', + 'collation' => 'utf8mb4_general_ci', 'prefix' => '', 'port' => $port, + 'options' => App::getConfig()['db_options'], ]); $this->is_connected = !empty($this->getPDO());