Simplify EzServer menu and serve original Web Console
This commit is contained in:
1 parent
ee7e18490f
commit
d748f7cc69
16 files changed
+290
-245
No files matched your search
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
// Initialize the original PHP API database. The Swift database uses a separate schema.
|
||||
if (PHP_SAPI !== 'cli' || $argc !== 2) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
umask(0077);
|
||||
try {
|
||||
$db = new PDO('sqlite:' . $argv[1], null, null, [PDO::ATTR_TIMEOUT => 5]);
|
||||
$db->exec('BEGIN IMMEDIATE');
|
||||
$applicationId = (int) $db->query('PRAGMA application_id')->fetchColumn();
|
||||
$version = (int) $db->query('PRAGMA user_version')->fetchColumn();
|
||||
// "EZSV" in SQLite's application header.
|
||||
if ($applicationId === 1163547478 && $version === 1) {
|
||||
$db->exec('COMMIT');
|
||||
exit(0);
|
||||
}
|
||||
$objects = (int) $db->query("SELECT count(*) FROM sqlite_schema WHERE name NOT GLOB 'sqlite_*'")->fetchColumn();
|
||||
if ($applicationId !== 0 || $version !== 0 || $objects !== 0) {
|
||||
throw new RuntimeException('Expected a new database or an EzServer PHP database at schema version 1.');
|
||||
}
|
||||
$schema = file_get_contents(__DIR__ . '/patients.sqlite.sql');
|
||||
if ($schema === false) {
|
||||
throw new RuntimeException('Could not read the patient schema.');
|
||||
}
|
||||
$db->exec($schema);
|
||||
$db->exec('PRAGMA application_id = 1163547478');
|
||||
$db->exec('PRAGMA user_version = 1');
|
||||
$db->exec('COMMIT');
|
||||
} catch (Throwable $error) {
|
||||
// SQLite rolls back an open transaction when the connection closes.
|
||||
fwrite(STDERR, 'SQLite initialization failed: ' . $error->getMessage() . PHP_EOL);
|
||||
exit(1);
|
||||
}
|
||||
Reference in new issue
Block a user