From d043dfaf46151554e02a0afe1ef22de14b671005 Mon Sep 17 00:00:00 2001 From: Eduard Wisch Date: Thu, 9 Apr 2026 09:19:17 +0200 Subject: [PATCH] fix: Bericht create() backwards-kompatibel gegen fehlende Migrations-Spalten MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Nach dem Deploy sind die neuen Spalten version/fk_bericht_parent (Phase 5.3) erst da wenn das Modul einmal reaktiviert wurde. Bis dahin knallte der INSERT mit 'Unknown column version' und man konnte keine neuen Berichte anlegen. Fix: create() prüft via SHOW COLUMNS welche optionalen Spalten (page_format, page_orientation, is_template, template_label, version, fk_bericht_parent) tatsächlich existieren und nimmt nur die vorhandenen in das INSERT-Statement auf. Damit laufen auch Systeme, bei denen die Migration noch nicht durchgelaufen ist, ohne Fehler weiter. Nach der Reaktivierung werden automatisch alle Spalten befüllt. Co-Authored-By: Claude Opus 4.6 (1M context) [deploy] --- class/bericht.class.php | 56 +++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/class/bericht.class.php b/class/bericht.class.php index 0147f60..da37c99 100644 --- a/class/bericht.class.php +++ b/class/bericht.class.php @@ -59,27 +59,41 @@ class Bericht extends CommonObject $this->ref = 'BR'.date('ymd-His', $this->datec); } - $sql = "INSERT INTO ".$this->db->prefix()."bericht (" - ."entity, ref, titel, element_type, fk_element, auftragsnummer, template_odt, page_format, page_orientation, is_template, template_label, version, fk_bericht_parent, status, fk_user_creat, datec, note" - .") VALUES (" - .((int) $this->entity)."," - ."'".$this->db->escape($this->ref)."'," - .($this->titel ? "'".$this->db->escape($this->titel)."'" : "NULL")."," - ."'".$this->db->escape($this->element_type)."'," - .((int) $this->fk_element)."," - .($this->auftragsnummer ? "'".$this->db->escape($this->auftragsnummer)."'" : "NULL")."," - .($this->template_odt ? "'".$this->db->escape($this->template_odt)."'" : "NULL")."," - ."'".$this->db->escape($this->page_format)."'," - ."'".$this->db->escape($this->page_orientation)."'," - .((int) ($this->is_template ? 1 : 0))."," - .($this->template_label ? "'".$this->db->escape($this->template_label)."'" : "NULL")."," - .((int) ($this->version ?: 1))."," - .($this->fk_bericht_parent ? (int) $this->fk_bericht_parent : "NULL")."," - .((int) $this->status)."," - .((int) $this->fk_user_creat)."," - ."'".$this->db->idate($this->datec)."'," - .($this->note ? "'".$this->db->escape($this->note)."'" : "NULL") - .")"; + // Prüfen welche optionalen Spalten existieren (Migrationen können unvollständig sein) + $cols = array( + 'entity' => (int) $this->entity, + 'ref' => "'".$this->db->escape($this->ref)."'", + 'titel' => ($this->titel ? "'".$this->db->escape($this->titel)."'" : "NULL"), + 'element_type' => "'".$this->db->escape($this->element_type)."'", + 'fk_element' => (int) $this->fk_element, + 'auftragsnummer' => ($this->auftragsnummer ? "'".$this->db->escape($this->auftragsnummer)."'" : "NULL"), + 'template_odt' => ($this->template_odt ? "'".$this->db->escape($this->template_odt)."'" : "NULL"), + 'status' => (int) $this->status, + 'fk_user_creat' => (int) $this->fk_user_creat, + 'datec' => "'".$this->db->idate($this->datec)."'", + 'note' => ($this->note ? "'".$this->db->escape($this->note)."'" : "NULL"), + ); + // Optionale Spalten — nur wenn in der DB vorhanden + $optional = array( + 'page_format' => "'".$this->db->escape($this->page_format)."'", + 'page_orientation' => "'".$this->db->escape($this->page_orientation)."'", + 'is_template' => (int) ($this->is_template ? 1 : 0), + 'template_label' => ($this->template_label ? "'".$this->db->escape($this->template_label)."'" : "NULL"), + 'version' => (int) ($this->version ?: 1), + 'fk_bericht_parent' => ($this->fk_bericht_parent ? (int) $this->fk_bericht_parent : "NULL"), + ); + $existing = array(); + $cres = $this->db->query("SHOW COLUMNS FROM ".$this->db->prefix()."bericht"); + if ($cres) { + while ($cr = $this->db->fetch_object($cres)) { + $existing[$cr->Field] = true; + } + } + foreach ($optional as $k => $v) { + if (isset($existing[$k])) $cols[$k] = $v; + } + + $sql = "INSERT INTO ".$this->db->prefix()."bericht (".implode(',', array_keys($cols)).") VALUES (".implode(',', array_values($cols)).")"; $this->db->begin(); $res = $this->db->query($sql);