Initial Kaffeekasse SaaS restart
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
$rootPath = dirname(__DIR__);
|
||||
$lockFile = $rootPath . '/storage/cron.lock';
|
||||
|
||||
if (is_file($lockFile) && (time() - filemtime($lockFile)) < 600) {
|
||||
fwrite(STDOUT, "Cron already running.\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
file_put_contents($lockFile, (string) time(), LOCK_EX);
|
||||
|
||||
try {
|
||||
$app = require $rootPath . '/app/bootstrap.php';
|
||||
|
||||
if (!$app['database']->isConfigured()) {
|
||||
throw new RuntimeException('Database config missing.');
|
||||
}
|
||||
|
||||
$pdo = $app['database']->pdo();
|
||||
|
||||
$pendingRfid = (int) $pdo->query(
|
||||
'SELECT COUNT(*) FROM rfid_events WHERE status = "received"'
|
||||
)->fetchColumn();
|
||||
|
||||
$summary = [
|
||||
'timestamp' => gmdate(DATE_ATOM),
|
||||
'pending_rfid_events' => $pendingRfid,
|
||||
'notes' => [
|
||||
'In diesem MVP dient Cron als technischer Haken fuer spaetere Reminder, Exporte und RFID-Regeln.',
|
||||
],
|
||||
];
|
||||
|
||||
fwrite(STDOUT, json_encode($summary, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . PHP_EOL);
|
||||
} catch (\Throwable $throwable) {
|
||||
fwrite(STDERR, $throwable->getMessage() . PHP_EOL);
|
||||
exit(1);
|
||||
} finally {
|
||||
if (is_file($lockFile)) {
|
||||
unlink($lockFile);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
$app = require dirname(__DIR__) . '/app/bootstrap.php';
|
||||
|
||||
$status = [
|
||||
'app_env' => $app['config']['env'],
|
||||
'database_configured' => $app['database']->isConfigured(),
|
||||
'installed' => is_file(dirname(__DIR__) . '/storage/installed.lock'),
|
||||
];
|
||||
|
||||
try {
|
||||
if ($status['database_configured']) {
|
||||
$count = $app['database']->pdo()->query('SELECT COUNT(*) FROM tenants')->fetchColumn();
|
||||
$status['database_reachable'] = true;
|
||||
$status['tenant_count'] = (int) $count;
|
||||
} else {
|
||||
$status['database_reachable'] = false;
|
||||
}
|
||||
} catch (\Throwable $throwable) {
|
||||
$status['database_reachable'] = false;
|
||||
$status['error'] = $throwable->getMessage();
|
||||
}
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($status, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . PHP_EOL;
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
$app = require dirname(__DIR__) . '/app/bootstrap.php';
|
||||
|
||||
if (!$app['database']->isConfigured()) {
|
||||
fwrite(STDERR, "Database config missing.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$schema = file_get_contents(dirname(__DIR__) . '/database/schema.sql');
|
||||
|
||||
if (!is_string($schema) || $schema === '') {
|
||||
fwrite(STDERR, "Schema missing.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$app['database']->pdo()->exec($schema);
|
||||
fwrite(STDOUT, "Schema applied successfully.\n");
|
||||
Reference in New Issue
Block a user