mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-24 23:25:48 -07:00
Update demo_mode.php
This commit is contained in:
parent
e1c2c3cac1
commit
3f80aee925
1 changed files with 22 additions and 7 deletions
|
@ -23,14 +23,29 @@ if (!IN_DEMO_MODE || !is_file($dump_path) || !is_readable($dump_path)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql_dump = file_get_contents($dump_path);
|
$sql_dump = file($dump_path);
|
||||||
|
|
||||||
// Delete database
|
// Drop tables
|
||||||
if (!DB()->query("DROP DATABASE " . SELECTED_DB)) {
|
DB()->query('SET foreign_key_checks = 0');
|
||||||
return;
|
if ($result = DB()->query('SHOW TABLES')) {
|
||||||
|
while ($row = DB()->sql_fetchrow($result)) {
|
||||||
|
DB()->query('DROP TABLE IF EXISTS ' . current($row));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
DB()->query('SET foreign_key_checks = 1');
|
||||||
|
|
||||||
// Create database
|
// Insert sql dump
|
||||||
if (!DB()->query("CREATE DATABASE " . SELECTED_DB)) {
|
$temp_line = '';
|
||||||
return;
|
foreach ($sql_dump as $line) {
|
||||||
|
if (str_starts_with($line, '--') || $line == '') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$temp_line .= $line;
|
||||||
|
if (str_ends_with(trim($line), ';')) {
|
||||||
|
if (!DB()->query($temp_line)) {
|
||||||
|
$cron_runtime_log = 'Error performing query: ' . $temp_line;
|
||||||
|
}
|
||||||
|
$temp_line = '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue