Add zeitraum_id to warteliste and update related queries; enhance impfWorkflow functions

This commit is contained in:
2026-03-20 19:48:56 +01:00
parent 8d40855402
commit 780da7913a
4 changed files with 123 additions and 17 deletions
+56
View File
@@ -26,6 +26,15 @@ if (!function_exists('impfTableHasColumn')) {
}
}
if (!function_exists('impfTableHasIndex')) {
function impfTableHasIndex(PDO $pdo, string $table, string $index): bool
{
$st = $pdo->prepare("SHOW INDEX FROM `" . $table . "` WHERE Key_name = :index_name");
$st->execute(['index_name' => $index]);
return (bool)$st->fetch(PDO::FETCH_ASSOC);
}
}
if (!function_exists('impfWeekdayName')) {
function impfWeekdayName(int $day): string
{
@@ -46,6 +55,13 @@ if (!function_exists('impfWeekdayName')) {
if (!function_exists('impfWorkflowEnsureTables')) {
function impfWorkflowEnsureTables(PDO $pdo): void
{
$pdo->exec("CREATE TABLE IF NOT EXISTS impf_workflow_meta (
meta_key VARCHAR(100) NOT NULL,
meta_value VARCHAR(255) NOT NULL DEFAULT '',
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (meta_key)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3");
$pdo->exec("CREATE TABLE IF NOT EXISTS impfstoff_workflow (
impfstoff_id INT NOT NULL,
dosen_pro_flasche INT NOT NULL,
@@ -93,13 +109,50 @@ if (!function_exists('impfWorkflowEnsureTables')) {
INDEX idx_impf_zeitraum_impfstoff_impfstoff (impfstoff_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3");
if (impfTableExists($pdo, 'warteliste') && !impfTableHasColumn($pdo, 'warteliste', 'zeitraum_id')) {
$pdo->exec("ALTER TABLE warteliste ADD COLUMN zeitraum_id INT NULL AFTER impfenzeitraum");
}
if (impfTableExists($pdo, 'warteliste') && !impfTableHasIndex($pdo, 'warteliste', 'idx_warteliste_zeitraum')) {
$pdo->exec("ALTER TABLE warteliste ADD INDEX idx_warteliste_zeitraum (zeitraum_id)");
}
impfWorkflowMigrateLegacyPlans($pdo);
}
}
if (!function_exists('impfWorkflowGetMeta')) {
function impfWorkflowGetMeta(PDO $pdo, string $key): ?string
{
$st = $pdo->prepare("SELECT meta_value
FROM impf_workflow_meta
WHERE meta_key = :meta_key
LIMIT 1");
$st->execute(['meta_key' => $key]);
$value = $st->fetchColumn();
return ($value === false) ? null : (string)$value;
}
}
if (!function_exists('impfWorkflowSetMeta')) {
function impfWorkflowSetMeta(PDO $pdo, string $key, string $value): void
{
$st = $pdo->prepare("INSERT INTO impf_workflow_meta (meta_key, meta_value)
VALUES (:meta_key, :meta_value)
ON DUPLICATE KEY UPDATE meta_value = VALUES(meta_value)");
$st->execute([
'meta_key' => $key,
'meta_value' => $value,
]);
}
}
if (!function_exists('impfWorkflowMigrateLegacyPlans')) {
function impfWorkflowMigrateLegacyPlans(PDO $pdo): void
{
if (impfWorkflowGetMeta($pdo, 'legacy_wochenplan_migrated') === '1') {
return;
}
if (!impfTableExists($pdo, 'impfstoff_wochenplan')) {
return;
}
@@ -108,6 +161,7 @@ if (!function_exists('impfWorkflowMigrateLegacyPlans')) {
FROM impfstoff_wochenplan");
$legacyRows = $stLegacy ? $stLegacy->fetchAll(PDO::FETCH_ASSOC) : [];
if (empty($legacyRows)) {
impfWorkflowSetMeta($pdo, 'legacy_wochenplan_migrated', '1');
return;
}
@@ -159,6 +213,8 @@ if (!function_exists('impfWorkflowMigrateLegacyPlans')) {
}
}
impfWorkflowSetMeta($pdo, 'legacy_wochenplan_migrated', '1');
if ($manageTransaction) {
$pdo->commit();
}