mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-21 08:52:21 +00:00
Issue system: adapted to work with multiple apps per fehler
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user