From 10d52caa987b4f9aec452c2831b42c8abe22aafa Mon Sep 17 00:00:00 2001 From: Alexei Karpenko Date: Tue, 3 Feb 2026 15:39:11 +0100 Subject: [PATCH] Issue system: adapted to work with multiple apps per fehler --- .../system/issues/IssuesKonfiguration.php | 4 +- .../system/issues/IssuesZustaendigkeiten.php | 5 +- application/libraries/FehlerUpdateLib.php | 133 ++++++++++++------ application/libraries/IssuesLib.php | 49 ++++--- application/models/system/FehlerApp_model.php | 15 ++ application/models/system/Fehler_model.php | 37 +++++ .../system/Fehlerkonfiguration_model.php | 10 +- .../system/Fehlerkonfigurationstyp_model.php | 33 ----- application/models/system/Issue_model.php | 2 +- .../views/system/issues/issuesData.php | 5 +- .../system/issues/issuesKonfigurationData.php | 3 +- .../issues/issuesZustaendigkeitenData.php | 3 +- ...hlermonitoring_issues_weitere_features.php | 35 +++++ 13 files changed, 226 insertions(+), 108 deletions(-) create mode 100644 application/models/system/FehlerApp_model.php diff --git a/application/controllers/system/issues/IssuesKonfiguration.php b/application/controllers/system/issues/IssuesKonfiguration.php index a19a2a93b..abd314dbd 100644 --- a/application/controllers/system/issues/IssuesKonfiguration.php +++ b/application/controllers/system/issues/IssuesKonfiguration.php @@ -88,9 +88,11 @@ class IssuesKonfiguration extends Auth_Controller // get all Fehler, optionally filtered by app $params = array('fehlercode_extern' => null); + $this->FehlerModel->addDistinct(); $this->FehlerModel->addSelect('fehlercode, fehler_kurzbz, fehlertyp_kurzbz, fehlertext'); + $this->FehlerModel->addJoin('system.tbl_fehler_app', 'fehlercode'); $this->FehlerModel->addOrder('fehlercode'); - if (!isEmptyString($app)) $params['app'] = $app; + if (!isEmptyString($app)) $params['tbl_fehler_app.app'] = $app; $fehlerRes = $this->FehlerModel->loadWhere($params); if (isError($fehlerRes)) $this->terminateWithJsonError($this->p->t('fehlermonitoring', 'fehlerFehlerLaden')); diff --git a/application/controllers/system/issues/IssuesZustaendigkeiten.php b/application/controllers/system/issues/IssuesZustaendigkeiten.php index d7bf9836e..cf343084d 100644 --- a/application/controllers/system/issues/IssuesZustaendigkeiten.php +++ b/application/controllers/system/issues/IssuesZustaendigkeiten.php @@ -69,10 +69,7 @@ class IssuesZustaendigkeiten extends Auth_Controller { $app = $this->input->get('app'); - $this->FehlerModel->addSelect('fehlercode, fehler_kurzbz, fehlertext, fehlertyp_kurzbz, app'); - $this->FehlerModel->addOrder('fehlercode'); - - $fehlerRes = isset($app) ? $this->FehlerModel->loadWhere(array('app' => $app)) : $this->FehlerModel->load(); + $fehlerRes = $this->FehlerModel->getByApps($app); $this->outputJson($fehlerRes); } diff --git a/application/libraries/FehlerUpdateLib.php b/application/libraries/FehlerUpdateLib.php index 0e6f3914f..d8ae2ef68 100644 --- a/application/libraries/FehlerUpdateLib.php +++ b/application/libraries/FehlerUpdateLib.php @@ -50,6 +50,7 @@ class FehlerUpdateLib ]; private $_ci; // Code igniter instance + private $_updateHistory = []; /** * Loads parser library @@ -74,9 +75,7 @@ class FehlerUpdateLib /** - * - * @param - * @return object success or error + * Install all possible fehler, from core and extensions */ public function installAll() { @@ -121,7 +120,6 @@ class FehlerUpdateLib } - // ----------------------------------------------------------------------------------------------------------------- // Private methods @@ -190,22 +188,29 @@ class FehlerUpdateLib */ private function _updateFehler($fehler) { + $fehlerReferences = $fehler['references']; + $fehler = $fehler['fehler']; + // Checks if the fehler already exists in the database $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]); + if (isset($fehler[self::FEHLER_KURZBZ]) && !isEmptyString($fehler[self::FEHLER_KURZBZ])) + $this->_ci->FehlerModel->db->or_where(self::FEHLER_KURZBZ.' = ', $fehler[self::FEHLER_KURZBZ]); $fehlerResult = $this->_ci->FehlerModel->load(); // If an error occurred then return the error itself if (isError($fehlerResult)) return $fehlerResult; + $updateRes = null; + // if fehler has been found if (hasData($fehlerResult)) { $foundFehler = getData($fehlerResult)[0]; // check if fehlercode - fehler kurzbz combination is correct - if ($foundFehler->{self::FEHLERCODE} != $fehler[self::FEHLERCODE] || $foundFehler->{self::FEHLER_KURZBZ} != $fehler[self::FEHLER_KURZBZ]) - { + if ($foundFehler->{self::FEHLERCODE} != $fehler[self::FEHLERCODE] + || $foundFehler->{self::FEHLER_KURZBZ} != ($fehler[self::FEHLER_KURZBZ] ?? null) + ) { return error("Wrong fehlercode - fehler kurzbz combination: ".$fehler[self::FEHLERCODE].", ".$fehler[self::FEHLER_KURZBZ]); } @@ -224,6 +229,13 @@ class FehlerUpdateLib if (isset($attributeInfo['updateable']) && $attributeInfo['updateable'] && $foundFehler->{$attributeName} != $fehler[$attributeName]) { $updateArr[$attributeName] = $fehler[$attributeName]; + + if (isset($this->_updateHistory[$foundFehler->{self::FEHLERCODE}][$attributeName]) + && $this->_updateHistory[$foundFehler->{self::FEHLERCODE}][$attributeName] != $fehler[$attributeName] + ) { + return error("Conflicting update values for attribute ".$attributeName.", fehler ".$foundFehler->{self::FEHLERCODE}); + } + $this->_updateHistory[$foundFehler->{self::FEHLERCODE}][$attributeName] = $fehler[$attributeName]; } } @@ -239,50 +251,60 @@ class FehlerUpdateLib "Fehler ".$fehler[self::FEHLERCODE].(isset($fehler[self::FEHLER_KURZBZ]) ? " (".$fehler[self::FEHLER_KURZBZ].")" : "")." updated" ); } + } + else + { + // no fehler has been found - return success($fehler[self::FEHLERCODE]); + // then add the fehler to the database + $updateRes = $this->_ci->FehlerModel->insert( + array_merge($fehler, ['insertamum' => 'NOW()', 'insertvon' => self::UPSERT_BY]) + ); + + // If an error occurred then return the error itself + if (isError($updateRes)) return $updateRes; + + // Prints info about the new added fehler + $this->_ci->eprintflib->printMessage( + sprintf( + 'A new fehler has been added into the database: '. + 'fehlercode => %s | fehler_kurzbz => %s | fehlertyp => %s', + $fehler[self::FEHLERCODE], + $fehler[self::FEHLER_KURZBZ], + $fehler[self::FEHLERTYP_KURZBZ] + ) + ); } - // no fehler has been found - - // handle apps - if (isset($fehler[self::APP])) + // handle references + if (isset($fehlerReferences[self::APP])) { - $apps = $fehler[self::APP]; - if (is_string($apps)) $apps = [$apps]; + $this->_ci->load->model('system/FehlerApp_model', 'FehlerAppModel'); + $apps = $fehlerReferences[self::APP]; - foreach ($apps as $app) + // load all assigned apps + $this->_ci->FehlerAppModel->addSelect(self::APP); + $fehlerAppRes = $this->_ci->FehlerAppModel->loadWhere([self::FEHLERCODE => $fehler[self::FEHLERCODE]]); + + $fehlerApps = hasData($fehlerAppRes) ? array_column(getData($fehlerAppRes), self::APP) : []; + + $appsToInsert = array_diff($apps, $fehlerApps); + + foreach ($appsToInsert as $app) { // check if app exists in db - $this->_ci->AppModel->addSelect('1'); - $appRes = $this->_ci->AppModel->loadWhere(['app' => $app]); + $fehlerAppsInsertRes = $this->_ci->FehlerAppModel->insert( + [self::FEHLERCODE => $fehler[self::FEHLERCODE], self::APP => $app, 'insertamum' => 'NOW()', 'insertvon' => self::UPSERT_BY] + ); - if (!hasData($appRes)) return error("App ".$app." does not exist"); - // TODO add entry for each app + if (isError($fehlerAppsInsertRes)) return $fehlerAppsInsertRes; + + $this->_ci->eprintflib->printMessage( + "Added app ".$app." to fehler ".$fehler[self::FEHLERCODE] + ); } - - $fehler[self::APP] = $apps[0]; } - // Then add the fehler to the database - $fehlerInsertResult = $this->_ci->FehlerModel->insert( - array_merge($fehler, ['insertamum' => 'NOW()', 'insertvon' => self::UPSERT_BY]) - ); - - // If an error occurred then return the error itself - if (isError($fehlerInsertResult)) return $fehlerInsertResult; - - // Prints info about the new added fehler - $this->_ci->eprintflib->printMessage( - sprintf( - 'A new fehler has been added into the database: '. - 'fehlercode => %s | fehler_kurzbz => %s | fehlertyp => %s', - $fehler[self::FEHLERCODE], - $fehler[self::FEHLER_KURZBZ], - $fehler[self::FEHLERTYP_KURZBZ] - ) - ); - // If here then no blocking errors occurred return success(); } @@ -292,13 +314,14 @@ class FehlerUpdateLib */ private function _createFehlerFromEntry($configEntry) { - $fehler = []; + $fehler = ['fehler' => [], 'references' => []]; foreach (self::FEHLER_ATTRIBUTES as $attributeName => $attributeInfo) { $required = isset($attributeInfo['required']) && $attributeInfo['required']; - if ($required && !isset($configEntry[$attributeName])) + if (!isset($configEntry[$attributeName])) { - return error('attribute'.$attributeName.' is missing'); + if ($required) return error('attribute'.$attributeName.' is missing'); + continue; } $attributeValue = $configEntry[$attributeName]; @@ -330,7 +353,29 @@ class FehlerUpdateLib return error('attribute'.$attributeName.' has invalid type'); } - $fehler[$attributeName] = $configEntry[$attributeName]; + if ($attributeName == self::APP) + { + if (is_string($attributeValue)) $attributeValue = [$attributeValue]; + + foreach ($attributeValue as $app) + { + // check if app exists in db + $this->_ci->AppModel->addSelect('1'); + $appRes = $this->_ci->AppModel->loadWhere(['app' => $app]); + + if (!hasData($appRes)) return error("App ".$app." does not exist"); + } + } + + if (isset($attributeInfo['types']) && is_array($attributeInfo['types']) && in_array(self::TYPE_ARRAY, $attributeInfo['types'])) + { + $fehler['references'][$attributeName] = $attributeValue; + } + else + { + $fehler['fehler'][$attributeName] = $attributeValue; + } + } return success($fehler); } diff --git a/application/libraries/IssuesLib.php b/application/libraries/IssuesLib.php index a5369d7e2..c9cbf75d6 100644 --- a/application/libraries/IssuesLib.php +++ b/application/libraries/IssuesLib.php @@ -20,6 +20,10 @@ class IssuesLib const ERRORTYPE_CODE = 'error'; const WARNINGTYPE_CODE = 'warning'; + const STATUS_KURZBZ = 'status_kurzbz'; + const VERARBEITET_AMUM = 'verarbeitetamum'; + const VERARBEITET_VON = 'verarbeitetvon'; + public function __construct($params = null) { $this->_ci =& get_instance(); @@ -91,12 +95,16 @@ class IssuesLib return error("fehlercode_extern missing"); // get external fehlercode (unique for each app) - $this->_ci->FehlerModel->addSelect('fehlercode'); - $fehlerRes = $this->_ci->FehlerModel->loadWhere( - array( - 'fehlercode_extern' => $fehlercode_extern, - 'app' => $this->_app - ) + $fehlerRes = $this->_ci->FehlerModel->execReadOnlyQuery( + ' + SELECT + fehlercode + FROM + system.tbl_fehler fe + WHERE + fehlercode_extern = ? + AND EXISTS (SELECT 1 FROM system.tbl_fehler_app WHERE fehlercode = fe.fehlercode AND app = ?)', + [$fehlercode_extern, $this->_app] ); if (isError($fehlerRes)) @@ -105,8 +113,10 @@ class IssuesLib // check if there is a predefined custom error for the external issue if (hasData($fehlerRes)) { - $fehlerData = getData($fehlerRes)[0]; // if found, use the code + $fehlerData = getData($fehlerRes); + if (count($fehlerData) > 1) return error("Multiple fehlercode_extern ".$fehlercode_extern. " for app ".$this->_app); + $fehlerData = getData($fehlerRes)[0]; $fehlercode = $fehlerData->fehlercode; } else @@ -128,9 +138,9 @@ class IssuesLib public function setBehoben($issue_id, $user) { $data = array( - 'status_kurzbz' => self::STATUS_BEHOBEN, - 'verarbeitetvon' => $user, - 'verarbeitetamum' => date('Y-m-d H:i:s') + self::STATUS_KURZBZ => self::STATUS_BEHOBEN, + self::VERARBEITET_VON => $user, + self::VERARBEITET_AMUM => date('Y-m-d H:i:s') ); return $this->_changeIssueStatus($issue_id, $data, $user); @@ -145,8 +155,8 @@ class IssuesLib public function setInBearbeitung($issue_id, $user) { $data = array( - 'status_kurzbz' => self::STATUS_IN_BEARBEITUNG, - 'verarbeitetvon' => $user + self::STATUS_KURZBZ => self::STATUS_IN_BEARBEITUNG, + self::VERARBEITET_VON => $user ); return $this->_changeIssueStatus($issue_id, $data, $user); @@ -161,9 +171,9 @@ class IssuesLib public function setNeu($issue_id, $user) { $data = array( - 'status_kurzbz' => self::STATUS_NEU, - 'verarbeitetvon' => null, - 'verarbeitetamum' => null + self::STATUS_KURZBZ => self::STATUS_NEU, + self::VERARBEITET_VON => null, + self::VERARBEITET_AMUM => null ); return $this->_changeIssueStatus($issue_id, $data, $user); @@ -185,13 +195,18 @@ class IssuesLib return error("Issue Id must be set correctly."); // check if given status is same as existing - $this->_ci->IssueModel->addSelect('status_kurzbz'); + $this->_ci->IssueModel->addSelect(self::STATUS_KURZBZ.', '.self::VERARBEITET_AMUM); $currStatus = $this->_ci->IssueModel->load($issue_id); if (hasData($currStatus)) { - if (getData($currStatus)[0]->status_kurzbz == $data['status_kurzbz']) + $currStatusData = getData($currStatus)[0]; + // if same status set, and verarbeitet amum is not being newly set + if ($currStatusData->{self::STATUS_KURZBZ} == $data[self::STATUS_KURZBZ] + && !(isset($data[self::VERARBEITET_AMUM]) && !isset($currStatusData->{self::VERARBEITET_AMUM})) + ) { return success("Same status already set"); + } } else return error("Error when getting status"); diff --git a/application/models/system/FehlerApp_model.php b/application/models/system/FehlerApp_model.php new file mode 100644 index 000000000..d803894f1 --- /dev/null +++ b/application/models/system/FehlerApp_model.php @@ -0,0 +1,15 @@ +dbTable = 'system.tbl_fehler_app'; + $this->pk = array('fehlercode', 'app'); + $this->hasSequence = false; + } +} \ No newline at end of file diff --git a/application/models/system/Fehler_model.php b/application/models/system/Fehler_model.php index 2b0dc8802..cf0c45092 100644 --- a/application/models/system/Fehler_model.php +++ b/application/models/system/Fehler_model.php @@ -12,4 +12,41 @@ class Fehler_model extends DB_Model $this->pk = array('fehlercode'); $this->hasSequence = false; } + + /** + * Gets all fehler for particular apps. + * @param $apps string of one app or array with multiple + * @return object success or error + */ + public function getByApps($apps) + { + if (is_string($apps)) $apps = [$apps]; + + $params = []; + + $qry = " + SELECT + fehlercode, fehler_kurzbz, fehlercode_extern, fehlertext, fehlertyp_kurzbz + FROM + system.tbl_fehler fe"; + + if (!isEmptyArray($apps)) + { + $qry .= " + WHERE EXISTS ( + SELECT 1 + FROM + system.tbl_fehler_app + WHERE + fehlercode = fe.fehlercode + AND app IN ? + )"; + + $params[] = $apps; + } + + $qry .= " ORDER BY fehlercode;"; + + return $this->execReadOnlyQuery($qry, $params); + } } diff --git a/application/models/system/Fehlerkonfiguration_model.php b/application/models/system/Fehlerkonfiguration_model.php index 442c8212f..2186ef933 100644 --- a/application/models/system/Fehlerkonfiguration_model.php +++ b/application/models/system/Fehlerkonfiguration_model.php @@ -15,18 +15,20 @@ class Fehlerkonfiguration_model extends DB_Model /** * Retrieve all set configuration parameters, optionally filtered by app. - * @param string $app + * @param string $apps * @return object success or error */ public function getKonfiguration($apps = null) { + if (is_string($apps)) $apps = [$apps]; $fehlerkonfiguration = array(); - $apps = is_string($apps) ? [$apps] : $apps; - $this->addSelect('fehlercode, konfigurationstyp_kurzbz, konfiguration, fehler_kurzbz'); + $this->addDistinct(); + $this->addSelect('fehler.fehlercode, konftyp.konfigurationstyp_kurzbz, tbl_fehler_konfiguration.konfiguration, fehler.fehler_kurzbz'); $this->addJoin('system.tbl_fehler_konfigurationstyp konftyp', 'konfigurationstyp_kurzbz'); $this->addJoin('system.tbl_fehler fehler', 'fehlercode'); - if (is_array($apps) && !isEmptyArray($apps)) $this->db->where_in('fehler.app', $apps); + $this->addJoin('system.tbl_fehler_app fe_app', 'fehlercode'); + if (isset($apps) && !isEmptyArray($apps)) $this->db->where_in('fe_app.app', $apps); $fehlerkonfigurationRes = $this->load(); if (isError($fehlerkonfigurationRes)) return $fehlerkonfigurationRes; diff --git a/application/models/system/Fehlerkonfigurationstyp_model.php b/application/models/system/Fehlerkonfigurationstyp_model.php index dc1c7957f..07a0b88ee 100644 --- a/application/models/system/Fehlerkonfigurationstyp_model.php +++ b/application/models/system/Fehlerkonfigurationstyp_model.php @@ -11,37 +11,4 @@ class Fehlerkonfigurationstyp_model extends DB_Model $this->dbTable = 'system.tbl_fehler_konfigurationstyp'; $this->pk = array('konfigurationstyp_kurzbz'); } - - /** - * Retrieve all set configuration parameters, optionally filtered by app. - * @param string $app - * @return object success or error - */ - public function getKonfiguration($app = null) - { - $fehlerkonfiguration = array(); - - $this->addSelect('fehlercode, konfigurationstyp_kurzbz, konfiguration, fehler_kurzbz'); - $this->addJoin('system.tbl_fehler_konfigurationstyp konftyp', 'konfigurationstyp_kurzbz'); - $this->addJoin('system.tbl_fehler fehler', 'fehlercode'); - $fehlerkonfigurationRes = isset($app) ? $this->loadWhere(array('fehler.app' => $app)) : $this->load(); - - if (isError($fehlerkonfigurationRes)) return $fehlerkonfigurationRes; - - if (hasData($fehlerkonfigurationRes)) - { - $fehlerkonfigurationData = getData($fehlerkonfigurationRes); - foreach ($fehlerkonfigurationData as $fk) - { - $konf = json_decode($fk->konfiguration); - if (is_array($konf)) - { - $fk->konfiguration = $konf; - $fehlerkonfiguration[] = $fk; - } - } - } - - return success($fehlerkonfiguration); - } } diff --git a/application/models/system/Issue_model.php b/application/models/system/Issue_model.php index c1d31a5ee..0e3ee3fbc 100644 --- a/application/models/system/Issue_model.php +++ b/application/models/system/Issue_model.php @@ -182,7 +182,7 @@ class Issue_model extends DB_Model if (is_array($apps)) { - $qry .= ' AND app IN ?'; + $qry .= ' AND EXISTS (SELECT 1 FROM system.tbl_fehler_app WHERE fehlercode = fe.fehlercode AND app IN ?)'; $params[] = $apps; } } diff --git a/application/views/system/issues/issuesData.php b/application/views/system/issues/issuesData.php index edaee9058..d94fb2904 100644 --- a/application/views/system/issues/issuesData.php +++ b/application/views/system/issues/issuesData.php @@ -49,7 +49,8 @@ $query .= " inhalt AS \"Inhalt\", inhalt_extern AS \"Inhalt extern\", iss.person_id AS \"PersonId\", iss.oe_kurzbz AS \"OE\", ftyp.bezeichnung_mehrsprachig[".$this->db->escape($language_index)."] AS \"Fehlertyp\", stat.bezeichnung_mehrsprachig[".$this->db->escape($language_index)."] AS \"Fehlerstatus\", - verarbeitetvon AS \"Verarbeitet von\",verarbeitetamum AS \"Verarbeitet am\", fr.app AS \"Applikation\", + verarbeitetvon AS \"Verarbeitet von\",verarbeitetamum AS \"Verarbeitet am\", + (SELECT STRING_AGG(app, ', ') FROM system.tbl_fehler_app WHERE fehlercode = fr.fehlercode GROUP BY fehlercode) AS \"Applikation\", fr.fehlertyp_kurzbz AS \"Fehlertypcode\", iss.status_kurzbz AS \"Statuscode\", pers.vorname AS \"Vorname\", pers.nachname AS \"Nachname\", ( @@ -168,7 +169,7 @@ $query .= ") $query .= ") "; -if (!isEmptyString($APPS)) $query .= " AND fr.app IN ".$APPS; +if (!isEmptyString($APPS)) $query .= " AND EXISTS (SELECT 1 FROM system.tbl_fehler_app WHERE fehlercode = fr.fehlercode AND app IN ".$APPS.")"; $query .= " ORDER BY CASE diff --git a/application/views/system/issues/issuesKonfigurationData.php b/application/views/system/issues/issuesKonfigurationData.php index a83dc73ce..dbd41c6e9 100644 --- a/application/views/system/issues/issuesKonfigurationData.php +++ b/application/views/system/issues/issuesKonfigurationData.php @@ -2,7 +2,8 @@ // get assigned Konfiguration $query = "SELECT - konftyp.konfigurationstyp_kurzbz, fe.fehlercode, fe.fehler_kurzbz, konf.konfiguration, fe.app, + konftyp.konfigurationstyp_kurzbz, fe.fehlercode, fe.fehler_kurzbz, konf.konfiguration, + (SELECT STRING_AGG(app, ', ') FROM system.tbl_fehler_app WHERE fehlercode = fe.fehlercode GROUP BY fehlercode) AS app, konftyp.beschreibung AS konfigurationsbeschreibung, konftyp.konfigurationsdatentyp, fe.fehlertext FROM system.tbl_fehler_konfiguration konf diff --git a/application/views/system/issues/issuesZustaendigkeitenData.php b/application/views/system/issues/issuesZustaendigkeitenData.php index d4cedd192..bce52a5f9 100644 --- a/application/views/system/issues/issuesZustaendigkeitenData.php +++ b/application/views/system/issues/issuesZustaendigkeitenData.php @@ -1,7 +1,8 @@ db_query("SELECT insertamum FROM system.tbl_fehler LIMIT 1") echo 'system.tbl_fehler '.$db->db_last_error().'
'; else echo '
Spalten insertamum, insertvon, updateamum, updatevon in system.tbl_fehler hinzugefügt'; +} + +if (!$result = @$db->db_query('SELECT 1 FROM system.tbl_fehler_app LIMIT 1')) +{ + $qry = 'CREATE TABLE system.tbl_fehler_app + ( + fehlercode varchar(64), + app varchar(32) NOT NULL, + insertamum timestamp DEFAULT now(), + insertvon varchar(32) + ); + + COMMENT ON TABLE system.tbl_fehler_app IS \'Fehler app Zuordnungen\'; + COMMENT ON COLUMN system.tbl_fehler_app.fehlercode IS \'Fehler\'; + COMMENT ON COLUMN system.tbl_fehler_app.app IS \'dem Fehler zugeweisene App\'; + + ALTER TABLE system.tbl_fehler_app ADD CONSTRAINT pk_fehler_app PRIMARY KEY (fehlercode, app); + ALTER TABLE system.tbl_fehler_app ADD CONSTRAINT fk_fehler_app_app FOREIGN KEY (app) REFERENCES system.tbl_app(app) ON UPDATE CASCADE ON DELETE RESTRICT; + ALTER TABLE system.tbl_fehler_app ADD CONSTRAINT fk_fehler_app_fehlercode FOREIGN KEY (fehlercode) REFERENCES system.tbl_fehler(fehlercode) ON UPDATE CASCADE ON DELETE CASCADE; + + GRANT SELECT, UPDATE, INSERT, DELETE ON system.tbl_fehler_app TO web; + GRANT SELECT, UPDATE, INSERT, DELETE ON system.tbl_fehler_app TO vilesci; + + -- prefill values + INSERT INTO system.tbl_fehler_app(fehlercode, app, insertvon) + SELECT fehlercode, app, \'dbupdate\' FROM system.tbl_fehler; + + -- remove not null constraint from old table + ALTER TABLE system.tbl_fehler ALTER COLUMN app DROP NOT NULL; + '; + + if(!$db->db_query($qry)) + echo 'system.tbl_fehler_app: '.$db->db_last_error().'
'; + else + echo ' system.tbl_fehler_app: Tabelle hinzugefuegt
'; } \ No newline at end of file