From 4981e3473ca855f4c5ef9a8f45b0b9adeeb80ead Mon Sep 17 00:00:00 2001 From: Daniel Neto Date: Sun, 28 Jul 2024 08:48:55 -0300 Subject: [PATCH] Updaate --- install/mysqlRestore.php | 43 ++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/install/mysqlRestore.php b/install/mysqlRestore.php index d29fa7df0a25..82ef6cc81e6d 100644 --- a/install/mysqlRestore.php +++ b/install/mysqlRestore.php @@ -90,24 +90,35 @@ function executeFile($filename) { } } + // Modificar comandos CREATE TABLE para CREATE TABLE IF NOT EXISTS + foreach ($createTableCommands as &$command) { + if (stripos($command, 'CREATE TABLE') !== false && stripos($command, 'IF NOT EXISTS') === false) { + $command = str_ireplace('CREATE TABLE', 'CREATE TABLE IF NOT EXISTS', $command); + } + } + // Executar DROP TABLE IF EXISTS separado de CREATE TABLE foreach ($tables as $table) { $dropTableCommand = 'DROP TABLE IF EXISTS `' . $table . '`;'; echo "Executing: $dropTableCommand\n"; // Imprimir o comando SQL try { if (!$global['mysqli']->query($dropTableCommand)) { - echo ('sqlDAL::executeFile ' . $filename . ' Error performing query \'' . $dropTableCommand . '\': ' . $global['mysqli']->error . '

'); + throw new Exception($global['mysqli']->error); } - } catch (\Throwable $th) { - echo 'Error: '.$th->getMessage().PHP_EOL; + } catch (Exception $e) { + echo ('sqlDAL::executeFile ' . $filename . ' Error performing query \'' . $dropTableCommand . '\': ' . $e->getMessage() . '

'); } } // Executar comandos de criação de tabela foreach ($createTableCommands as $command) { echo "Executing: $command\n"; // Imprimir o comando SQL - if (!$global['mysqli']->query($command)) { - echo ('sqlDAL::executeFile ' . $filename . ' Error performing query \'' . $command . '\': ' . $global['mysqli']->error . '

'); + try { + if (!$global['mysqli']->query($command)) { + throw new Exception($global['mysqli']->error); + } + } catch (Exception $e) { + echo ('sqlDAL::executeFile ' . $filename . ' Error performing query \'' . $command . '\': ' . $e->getMessage() . '

'); } } @@ -115,8 +126,12 @@ function executeFile($filename) { if (!empty($tables)) { $lockTables = 'LOCK TABLES ' . implode(' WRITE, ', $tables) . ' WRITE;'; echo "Executing: $lockTables\n"; // Imprimir o comando SQL - if (!$global['mysqli']->query($lockTables)) { - echo ('sqlDAL::executeFile ' . $filename . ' Error performing query \'' . $lockTables . '\': ' . $global['mysqli']->error . '

'); + try { + if (!$global['mysqli']->query($lockTables)) { + throw new Exception($global['mysqli']->error); + } + } catch (Exception $e) { + echo ('sqlDAL::executeFile ' . $filename . ' Error performing query \'' . $lockTables . '\': ' . $e->getMessage() . '

'); return; } } @@ -125,12 +140,20 @@ function executeFile($filename) { foreach ($commands as $command) { if (!in_array($command, $createTableCommands)) { echo "Executing: $command\n"; // Imprimir o comando SQL - if (!$global['mysqli']->query($command)) { - echo ('sqlDAL::executeFile ' . $filename . ' Error performing query \'' . $command . '\': ' . $global['mysqli']->error . '

'); + try { + if (!$global['mysqli']->query($command)) { + throw new Exception($global['mysqli']->error); + } + } catch (Exception $e) { + echo ('sqlDAL::executeFile ' . $filename . ' Error performing query \'' . $command . '\': ' . $e->getMessage() . '

'); } } } // Desbloquear as tabelas no final - $global['mysqli']->query('UNLOCK TABLES;'); + try { + $global['mysqli']->query('UNLOCK TABLES;'); + } catch (Exception $e) { + echo ('sqlDAL::executeFile ' . $filename . ' Error performing query \'UNLOCK TABLES\': ' . $e->getMessage() . '

'); + } }