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 '