initial commit
This commit is contained in:
commit
1db373a03d
110 changed files with 67830 additions and 0 deletions
59
bin/import.php
Normal file
59
bin/import.php
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Spielt einen mysqldump in die konfigurierte Datenbank ein.
|
||||
*
|
||||
* php bin/import.php <pfad-zur-dumpdatei.sql>
|
||||
*
|
||||
* Der Dump wird statement-weise (zeilenbasiert) ausgeführt. Vorhandene
|
||||
* Tabellen werden dabei durch die DROP TABLE-Anweisungen im Dump ersetzt.
|
||||
*/
|
||||
|
||||
require dirname(__DIR__) . '/src/bootstrap.php';
|
||||
|
||||
if ($argc < 2) {
|
||||
fwrite(STDERR, "Aufruf: php bin/import.php <dump.sql>\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$file = $argv[1];
|
||||
|
||||
if (!is_file($file)) {
|
||||
fwrite(STDERR, "Datei nicht gefunden: $file\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$pdo = \App\Core\Database::get()->pdo();
|
||||
$pdo->exec('SET NAMES utf8mb4');
|
||||
|
||||
$handle = fopen($file, 'r');
|
||||
$buffer = '';
|
||||
$count = 0;
|
||||
|
||||
while (($line = fgets($handle)) !== false) {
|
||||
$line = rtrim($line);
|
||||
$trimmed = ltrim($line);
|
||||
|
||||
// Reine Kommentarzeilen überspringen
|
||||
if ($trimmed === '' || str_starts_with($trimmed, '--')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$buffer .= $line . "\n";
|
||||
|
||||
if (str_ends_with($trimmed, ';')) {
|
||||
$sql = trim($buffer);
|
||||
$buffer = '';
|
||||
|
||||
if ($sql !== '') {
|
||||
$pdo->exec($sql);
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fclose($handle);
|
||||
|
||||
echo "Import abgeschlossen: $count Anweisungen ausgeführt.\n";
|
||||
Loading…
Add table
Add a link
Reference in a new issue