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);
|
$this->ref = 'BR'.date('ymd-His', $this->datec);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = "INSERT INTO ".$this->db->prefix()."bericht ("
|
// Prüfen welche optionalen Spalten existieren (Migrationen können unvollständig sein)
|
||||||
."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"
|
$cols = array(
|
||||||
.") VALUES ("
|
'entity' => (int) $this->entity,
|
||||||
.((int) $this->entity).","
|
'ref' => "'".$this->db->escape($this->ref)."'",
|
||||||
."'".$this->db->escape($this->ref)."',"
|
'titel' => ($this->titel ? "'".$this->db->escape($this->titel)."'" : "NULL"),
|
||||||
.($this->titel ? "'".$this->db->escape($this->titel)."'" : "NULL").","
|
'element_type' => "'".$this->db->escape($this->element_type)."'",
|
||||||
."'".$this->db->escape($this->element_type)."',"
|
'fk_element' => (int) $this->fk_element,
|
||||||
.((int) $this->fk_element).","
|
'auftragsnummer' => ($this->auftragsnummer ? "'".$this->db->escape($this->auftragsnummer)."'" : "NULL"),
|
||||||
.($this->auftragsnummer ? "'".$this->db->escape($this->auftragsnummer)."'" : "NULL").","
|
'template_odt' => ($this->template_odt ? "'".$this->db->escape($this->template_odt)."'" : "NULL"),
|
||||||
.($this->template_odt ? "'".$this->db->escape($this->template_odt)."'" : "NULL").","
|
'status' => (int) $this->status,
|
||||||
."'".$this->db->escape($this->page_format)."',"
|
'fk_user_creat' => (int) $this->fk_user_creat,
|
||||||
."'".$this->db->escape($this->page_orientation)."',"
|
'datec' => "'".$this->db->idate($this->datec)."'",
|
||||||
.((int) ($this->is_template ? 1 : 0)).","
|
'note' => ($this->note ? "'".$this->db->escape($this->note)."'" : "NULL"),
|
||||||
.($this->template_label ? "'".$this->db->escape($this->template_label)."'" : "NULL").","
|
);
|
||||||
.((int) ($this->version ?: 1)).","
|
// Optionale Spalten — nur wenn in der DB vorhanden
|
||||||
.($this->fk_bericht_parent ? (int) $this->fk_bericht_parent : "NULL").","
|
$optional = array(
|
||||||
.((int) $this->status).","
|
'page_format' => "'".$this->db->escape($this->page_format)."'",
|
||||||
.((int) $this->fk_user_creat).","
|
'page_orientation' => "'".$this->db->escape($this->page_orientation)."'",
|
||||||
."'".$this->db->idate($this->datec)."',"
|
'is_template' => (int) ($this->is_template ? 1 : 0),
|
||||||
.($this->note ? "'".$this->db->escape($this->note)."'" : "NULL")
|
'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();
|
$this->db->begin();
|
||||||
$res = $this->db->query($sql);
|
$res = $this->db->query($sql);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue