Add /files/create.sql to allow for automated testing

This commit is contained in:
2024-01-05 17:10:16 +01:00
parent 21e0220716
commit c15952d063
3 changed files with 27 additions and 1 deletions

View File

26
www/files/create.sql.php Normal file
View File

@ -0,0 +1,26 @@
<?php
if ($_SERVER['PHP_AUTH_USER'] !== 'elwig' || $_SERVER['PHP_AUTH_PW'] !== 'ganzGeheim123!') {
header('Status: 401');
header('WWW-Authenticate: Basic realm="Elwig"');
exit("401 Unauthorized :(\n");
}
$token = "[REDACTED]";
$repo = "winzer/elwig-misc.git";
$url = "https://token:$token@git.necronda.net/$repo";
$schema_version = $_GET['v'];
shell_exec("cd .repos; git clone $url; cd elwig-misc; git checkout main; git pull");
if ($schema_version) {
$commit = shell_exec("cd .repos/elwig-misc; git log -p sql/v01/99.schema_version.sql | grep '+PRAGMA schema_version = ${schema_version}00;' -B 14 | head -n 1 | grep -oE '[^ ]+$'");
if (!$commit) {
header('Status: 404');
exit("404 Specified schema version not found :(\n");
}
shell_exec("cd .repos/elwig-misc; git checkout $commit");
}
header('Content-Type: application/sql');
system("cd .repos/elwig-misc; cat \$(ls sql/*.*.sql sql/v01/*.*.sql | grep -vE -- '-fix|wb_gem' | awk -F'/' '{ print \$NF,\$0 }' | sort -t'/' -k1 -n | cut -f2- -d' ')");

View File

@ -23,7 +23,7 @@ if ($info[1] === 'elwig' || $info[1] === 'winziprint') {
$files = [];
foreach (scandir('.') as $file) {
if ($file === '.' || $file === '..' || str_ends_with($file, ".php")) continue;
if (str_starts_with($file, ".") || str_ends_with($file, ".php")) continue;
$files[$file] = [filesize($file), filemtime($file), filectime($file)];
}