fix: Bericht create() backwards-kompatibel gegen fehlende Migrations-Spalten
All checks were successful
Deploy bericht / deploy (push) Successful in 1s
All checks were successful
Deploy bericht / deploy (push) Successful in 1s
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) <noreply@anthropic.com> [deploy]
This commit is contained in:
parent
c8f7d7d527
commit
d043dfaf46
1 changed files with 35 additions and 21 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue