From d6803a3947d84c8f355d33f9ec4c02891de3c404 Mon Sep 17 00:00:00 2001 From: Alexei Karpenko Date: Tue, 20 Jan 2026 18:56:43 +0100 Subject: [PATCH] Fehler update: enabled updating of fehler columns, added insertaum, insertvon, updateamum, insertvon --- application/libraries/FehlerUpdateLib.php | 51 +++++++++++++------ system/dbupdate_3.4.php | 3 +- ...hlermonitoring_issues_weitere_features.php | 16 ++++++ 3 files changed, 53 insertions(+), 17 deletions(-) create mode 100644 system/dbupdate_3.4/68834_fehlermonitoring_issues_weitere_features.php diff --git a/application/libraries/FehlerUpdateLib.php b/application/libraries/FehlerUpdateLib.php index df9d8266d..0e6f3914f 100644 --- a/application/libraries/FehlerUpdateLib.php +++ b/application/libraries/FehlerUpdateLib.php @@ -21,7 +21,7 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); class FehlerUpdateLib { // Who adds phrases into the database - //const INSERT_BY = 'FehlerUpdate'; + const UPSERT_BY = 'FehlerUpdate'; const CONFIG_DIRECTORY = 'config'; const CONFIG_FEHLER_NAME = 'fehler'; @@ -43,8 +43,8 @@ class FehlerUpdateLib const FEHLER_ATTRIBUTES = [ self::FEHLERCODE => ['required' => true], self::FEHLER_KURZBZ => ['required' => false], - self::FEHLERTEXT => ['required' => true], - self::FEHLERTYP_KURZBZ => ['required' => false], + self::FEHLERTEXT => ['required' => true, 'updateable' => false], + self::FEHLERTYP_KURZBZ => ['required' => false, 'updateable' => true], self::APP => ['required' => true, 'types' => [self::TYPE_STRING, self::TYPE_ARRAY]], self::FEHLERCODE_EXTERN => ['required' => false] ]; @@ -170,7 +170,7 @@ class FehlerUpdateLib elseif (hasData($createFehlerResult)) { // add fehler to db - $addFehlerResult = $this->_addFehler(getData($createFehlerResult)); + $addFehlerResult = $this->_updateFehler(getData($createFehlerResult)); if (isError($addFehlerResult)) { @@ -188,10 +188,9 @@ class FehlerUpdateLib /** * Add a new fehler to the database */ - private function _addFehler($fehler) + private function _updateFehler($fehler) { // Checks if the fehler already exists in the database - $this->_ci->FehlerModel->addSelect(self::FEHLERCODE.', '.self::FEHLER_KURZBZ); $this->_ci->FehlerModel->db->where(self::FEHLERCODE.' = ', $fehler[self::FEHLERCODE]); if ($fehler[self::FEHLER_KURZBZ] != null) $this->_ci->FehlerModel->db->or_where(self::FEHLER_KURZBZ.' = ', $fehler[self::FEHLER_KURZBZ]); $fehlerResult = $this->_ci->FehlerModel->load(); @@ -216,6 +215,31 @@ class FehlerUpdateLib ." already exists in database" ); + $updateArr = []; + + // update fehler, if needed + foreach (self::FEHLER_ATTRIBUTES as $attributeName => $attributeInfo) + { + // set attributes to be updated + if (isset($attributeInfo['updateable']) && $attributeInfo['updateable'] && $foundFehler->{$attributeName} != $fehler[$attributeName]) + { + $updateArr[$attributeName] = $fehler[$attributeName]; + } + } + + if (!isEmptyArray($updateArr)) + { + $updateRes = $this->_ci->FehlerModel->update( + [self::FEHLERCODE => $foundFehler->{self::FEHLERCODE}], + array_merge($updateArr, ['updateamum' => 'NOW()', 'updatevon' => self::UPSERT_BY]) + ); + if (isError($updateRes)) return $updateRes; + + $this->_ci->eprintflib->printMessage( + "Fehler ".$fehler[self::FEHLERCODE].(isset($fehler[self::FEHLER_KURZBZ]) ? " (".$fehler[self::FEHLER_KURZBZ].")" : "")." updated" + ); + } + return success($fehler[self::FEHLERCODE]); } @@ -242,12 +266,7 @@ class FehlerUpdateLib // Then add the fehler to the database $fehlerInsertResult = $this->_ci->FehlerModel->insert( - $fehler - // TODO: add insertamum? - //~ array( - //~ 'insertamum' => 'NOW()', - //~ 'insertvon' => self::INSERT_BY - //~ ) + array_merge($fehler, ['insertamum' => 'NOW()', 'insertvon' => self::UPSERT_BY]) ); // If an error occurred then return the error itself @@ -274,9 +293,9 @@ class FehlerUpdateLib private function _createFehlerFromEntry($configEntry) { $fehler = []; - foreach (self::FEHLER_ATTRIBUTES as $attributeName => $attributeConditions) + foreach (self::FEHLER_ATTRIBUTES as $attributeName => $attributeInfo) { - $required = isset($attributeConditions['required']) && $attributeConditions['required']; + $required = isset($attributeInfo['required']) && $attributeInfo['required']; if ($required && !isset($configEntry[$attributeName])) { return error('attribute'.$attributeName.' is missing'); @@ -284,9 +303,9 @@ class FehlerUpdateLib $attributeValue = $configEntry[$attributeName]; $validType = false; - if (isset($attributeConditions['types']) && is_array($attributeConditions['types'])) + if (isset($attributeInfo['types']) && is_array($attributeInfo['types'])) { - foreach ($attributeConditions['types'] as $type) + foreach ($attributeInfo['types'] as $type) { switch ($type) { diff --git a/system/dbupdate_3.4.php b/system/dbupdate_3.4.php index 7bd195064..d3e56a93c 100644 --- a/system/dbupdate_3.4.php +++ b/system/dbupdate_3.4.php @@ -87,6 +87,7 @@ require_once('dbupdate_3.4/47972_pruefungsverwaltung_ects_angabe.php'); require_once('dbupdate_3.4/67490_studstatus_suche_abort_controller_haengt.php'); require_once('dbupdate_3.4/69065_Projektarbeiten_Firmen_verwalten.php'); require_once('dbupdate_3.4/68744_StV_settings.php'); +require_once('dbupdate_3.4/68834_fehlermonitoring_issues_weitere_features.php'); // *** Pruefung und hinzufuegen der neuen Attribute und Tabellen echo '

Pruefe Tabellen und Attribute!

'; @@ -406,7 +407,7 @@ $tabellen=array( "system.tbl_benutzerrolle" => array("benutzerberechtigung_id","rolle_kurzbz","berechtigung_kurzbz","uid","funktion_kurzbz","oe_kurzbz","art","studiensemester_kurzbz","start","ende","negativ","updateamum", "updatevon","insertamum","insertvon","kostenstelle_id","anmerkung"), "system.tbl_berechtigung" => array("berechtigung_kurzbz","beschreibung"), "system.tbl_extensions" => array("extension_id","name","version","description","license","url","core_version","dependencies","enabled"), - "system.tbl_fehler" => array("fehlercode","fehler_kurzbz","fehlercode_extern","fehlertext","fehlertyp_kurzbz","app"), + "system.tbl_fehler" => array("fehlercode","fehler_kurzbz","fehlercode_extern","fehlertext","fehlertyp_kurzbz","app","insertamum","insertvon","updateamum","updatevon"), "system.tbl_fehlertyp" => array("fehlertyp_kurzbz","bezeichnung_mehrsprachig"), "system.tbl_fehler_konfiguration" => array("konfigurationstyp_kurzbz","fehlercode","konfiguration","insertamum","insertvon","updateamum","updatevon"), "system.tbl_fehler_konfigurationsdatentyp" => array("konfigurationsdatentyp"), diff --git a/system/dbupdate_3.4/68834_fehlermonitoring_issues_weitere_features.php b/system/dbupdate_3.4/68834_fehlermonitoring_issues_weitere_features.php new file mode 100644 index 000000000..7ef5324eb --- /dev/null +++ b/system/dbupdate_3.4/68834_fehlermonitoring_issues_weitere_features.php @@ -0,0 +1,16 @@ +db_query("SELECT insertamum FROM system.tbl_fehler LIMIT 1")) +{ + $qry = "ALTER TABLE system.tbl_fehler ADD COLUMN insertamum timestamp DEFAULT now(); + ALTER TABLE system.tbl_fehler ADD COLUMN insertvon varchar(32); + ALTER TABLE system.tbl_fehler ADD COLUMN updateamum timestamp DEFAULT now(); + ALTER TABLE system.tbl_fehler ADD COLUMN updatevon varchar(32);"; + + if(!$db->db_query($qry)) + echo 'system.tbl_fehler '.$db->db_last_error().'
'; + else + echo '
Spalten insertamum, insertvon, updateamum, updatevon in system.tbl_fehler hinzugefügt'; +} \ No newline at end of file