Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Neto committed Jul 28, 2024
1 parent 647cbc8 commit 842f291
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions install/mysqlRestore.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//streamer config
$global['createDatabase'] = 1;
$doNotIncludeConfig = 1;
require_once __DIR__.'/../videos/configuration.php';
require_once __DIR__ . '/../videos/configuration.php';

if (php_sapi_name() !== 'cli') {
return die('Command Line only');
Expand All @@ -15,7 +15,7 @@
echo "Searching [{$globPattern}]" . PHP_EOL;
$glob = glob($globPattern);
foreach ($glob as $key => $file) {
echo "($key) {$file} ".humanFileSize(filesize($file)) . PHP_EOL;
echo "($key) {$file} " . humanFileSize(filesize($file)) . PHP_EOL;
}

// Check for command line argument
Expand Down Expand Up @@ -56,13 +56,13 @@
echo "Execute filename {$filename}" . PHP_EOL;
executeFile($filename);

function executeFile($filename) {
function executeFile($filename)
{
global $global;
$templine = '';
// Read in entire file
$lines = file($filename);

$global['mysqli']->query('UNLOCK TABLES;');
// Loop through each line
foreach ($lines as $line) {
// Skip it if it's a comment
Expand All @@ -74,11 +74,21 @@ function executeFile($filename) {
// If it has a semicolon at the end, it's the end of the query
if (substr(trim($line), -1, 1) == ';') {
// Perform the query
if (!$global['mysqli']->query($templine)) {
echo ('sqlDAL::executeFile ' . $filename . ' Error performing query \'<strong>' . $templine . '\': ' . $global['mysqli']->error . '<br /><br />');
if (stripos($templine, 'LOCK TABLES') !== false || stripos($templine, 'UNLOCK TABLES') !== false) {
// Directly execute lock/unlock table commands
if (!$global['mysqli']->query($templine)) {
echo ('sqlDAL::executeFile ' . $filename . ' Error performing query \'<strong>' . $templine . '\': ' . $global['mysqli']->error . '<br /><br />');
}
} else {
// Perform the query
if (!$global['mysqli']->query($templine)) {
echo ('sqlDAL::executeFile ' . $filename . ' Error performing query \'<strong>' . $templine . '\': ' . $global['mysqli']->error . '<br /><br />');
}
}
// Reset temp variable to empty
$templine = '';
}
}
// Ensure all tables are unlocked at the end
$global['mysqli']->query('UNLOCK TABLES;');
}

0 comments on commit 842f291

Please sign in to comment.