From 4e0381b4ec2336a36a5399455feaaece87deeeff Mon Sep 17 00:00:00 2001 From: Daniel Neto Date: Sun, 28 Jul 2024 08:30:49 -0300 Subject: [PATCH] Update --- install/mysqlRestore.php | 47 ++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/install/mysqlRestore.php b/install/mysqlRestore.php index 0d4c86e67dad..77843b4ddc79 100644 --- a/install/mysqlRestore.php +++ b/install/mysqlRestore.php @@ -62,7 +62,12 @@ function executeFile($filename) { // Read in entire file $lines = file($filename); - // Executar todas as linhas para criar as tabelas sem bloqueio + // Lista para armazenar comandos de criação de tabela + $createTableCommands = []; + // Lista para armazenar todos os outros comandos SQL + $otherCommands = []; + + // Separar os comandos de criação de tabela dos outros comandos foreach ($lines as $line) { // Skip it if it's a comment if (substr($line, 0, 2) == '--' || trim($line) == '') @@ -72,20 +77,28 @@ function executeFile($filename) { $templine .= $line; // If it has a semicolon at the end, it's the end of the query if (substr(trim($line), -1) == ';') { - // Perform the query - if (!$global['mysqli']->query($templine)) { - echo ('sqlDAL::executeFile ' . $filename . ' Error performing query \'' . $templine . '\': ' . $global['mysqli']->error . '

'); + if (stripos($templine, 'CREATE TABLE') !== false) { + $createTableCommands[] = $templine; + } else { + $otherCommands[] = $templine; } // Reset temp variable to empty $templine = ''; } } + // Executar comandos de criação de tabela sem bloqueio + foreach ($createTableCommands as $command) { + if (!$global['mysqli']->query($command)) { + echo ('sqlDAL::executeFile ' . $filename . ' Error performing query \'' . $command . '\': ' . $global['mysqli']->error . '

'); + } + } + // Identificar todas as tabelas no arquivo SQL $tables = []; - foreach ($lines as $line) { - if (stripos($line, 'CREATE TABLE') !== false) { - $tableName = preg_split('/[\s`]+/', $line)[2]; // Extrair o nome da tabela + foreach ($createTableCommands as $command) { + if (stripos($command, 'CREATE TABLE') !== false) { + $tableName = preg_split('/[\s`]+/', $command)[2]; // Extrair o nome da tabela $tables[] = $tableName; } } @@ -99,22 +112,10 @@ function executeFile($filename) { } } - // Executar todas as linhas novamente para inserir dados com tabelas bloqueadas - foreach ($lines as $line) { - // Skip it if it's a comment - if (substr($line, 0, 2) == '--' || trim($line) == '') - continue; - - // Add this line to the current segment - $templine .= $line; - // If it has a semicolon at the end, it's the end of the query - if (substr(trim($line), -1) == ';') { - // Perform the query - if (!$global['mysqli']->query($templine)) { - echo ('sqlDAL::executeFile ' . $filename . ' Error performing query \'' . $templine . '\': ' . $global['mysqli']->error . '

'); - } - // Reset temp variable to empty - $templine = ''; + // Executar todos os outros comandos com tabelas bloqueadas + foreach ($otherCommands as $command) { + if (!$global['mysqli']->query($command)) { + echo ('sqlDAL::executeFile ' . $filename . ' Error performing query \'' . $command . '\': ' . $global['mysqli']->error . '

'); } }