mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-06-01 20:29:29 +00:00
Fehler: added fehlerupdate for adding missing fehler from config files to database
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2024 fhcomplete.org
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
if (!defined("BASEPATH")) exit("No direct script access allowed");
|
||||
|
||||
class CLI_Manager extends CLI_Controller
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
// Load libraries
|
||||
$this->load->library('FehlerUpdateLib');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function installAll()
|
||||
{
|
||||
$this->fehlerupdatelib->installAll();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function installFromCore()
|
||||
{
|
||||
$this->fehlerupdatelib->installFromCore();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function installFrom($fehlerConfigDirectory)
|
||||
{
|
||||
$this->fehlerupdatelib->installFrom(urldecode($fehlerConfigDirectory));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
if (!defined("BASEPATH")) exit("No direct script access allowed");
|
||||
|
||||
class Manager extends Auth_Controller
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(
|
||||
array(
|
||||
'installAll' => 'admin:rw',
|
||||
'installFromCore' => 'admin:rw'
|
||||
)
|
||||
);
|
||||
|
||||
// Load libraries
|
||||
$this->load->library('FehlerUpdateLib');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function installAll()
|
||||
{
|
||||
$this->fehlerupdatelib->installAll();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function installFromCore()
|
||||
{
|
||||
$this->fehlerupdatelib->installFromCore();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function installFrom($fehlerConfigDirectory)
|
||||
{
|
||||
$this->fehlerupdatelib->installFrom($fehlerConfigDirectory);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,304 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2025 fhcomplete.org
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
if (! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
class FehlerUpdateLib
|
||||
{
|
||||
// Who adds phrases into the database
|
||||
//const INSERT_BY = 'FehlerUpdate';
|
||||
|
||||
const CONFIG_DIRECTORY = 'config';
|
||||
const CONFIG_FEHLER_NAME = 'fehler';
|
||||
const CONFIG_FEHLER_INDEX = 'fehler';
|
||||
|
||||
const TYPE_STRING = 'string';
|
||||
const TYPE_ARRAY = 'array';
|
||||
|
||||
//~ // Array elements names
|
||||
const FEHLERCODE = 'fehlercode';
|
||||
const FEHLER_KURZBZ = 'fehler_kurzbz';
|
||||
const FEHLERTEXT = 'fehlertext';
|
||||
const FEHLERTYP_KURZBZ = 'fehlertyp_kurzbz';
|
||||
const APP = 'app';
|
||||
|
||||
// structure of a fehler
|
||||
// type default: string
|
||||
const FEHLER_ATTRIBUTES = [
|
||||
self::FEHLERCODE => ['required' => true],
|
||||
self::FEHLER_KURZBZ => ['required' => true],
|
||||
self::FEHLERTEXT => ['required' => true],
|
||||
self::FEHLERTYP_KURZBZ => ['required' => false],
|
||||
self::APP => ['required' => true, 'types' => [self::TYPE_STRING, self::TYPE_ARRAY]]
|
||||
];
|
||||
|
||||
private $_ci; // Code igniter instance
|
||||
|
||||
/**
|
||||
* Loads parser library
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->_ci =& get_instance();
|
||||
|
||||
// Loads EPrintfLib
|
||||
$this->_ci->load->library('EPrintfLib');
|
||||
|
||||
// Loads the PhraseModel
|
||||
$this->_ci->load->model('system/Fehler_model', 'FehlerModel');
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
// Public methods
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param
|
||||
* @return object success or error
|
||||
*/
|
||||
public function installAll()
|
||||
{
|
||||
$this->installFromCore();
|
||||
|
||||
$this->_ci->load->library('ExtensionsLib');
|
||||
|
||||
// load fehler entries of extensions
|
||||
$extensions = $this->_ci->extensionslib->getInstalledExtensions();
|
||||
|
||||
if (hasData($extensions))
|
||||
{
|
||||
$extensionArray = array();
|
||||
|
||||
$extensionsData = getData($extensions);
|
||||
|
||||
foreach ($extensionsData as $ext)
|
||||
{
|
||||
$configFilePath = ExtensionsLib::EXTENSIONS_DIR_NAME.'/'.$ext->name.'/'.FehlerUpdateLib::CONFIG_FEHLER_NAME;
|
||||
$this->installFrom($configFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Install fehler from the core
|
||||
*/
|
||||
public function installFromCore()
|
||||
{
|
||||
$this->_installFehler();
|
||||
}
|
||||
|
||||
/**
|
||||
* Install fehler from the given path
|
||||
*/
|
||||
public function installFrom($fehlerConfigDirectory)
|
||||
{
|
||||
$this->_installFehler($fehlerConfigDirectory);
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
// Private methods
|
||||
|
||||
/**
|
||||
* Install fehler from the given directory
|
||||
*/
|
||||
private function _installFehler($fehlerConfigDirectory = null)
|
||||
{
|
||||
// check that fehler config file exists
|
||||
$fehlerConfigDirectory = isset($fehlerConfigDirectory) ? $fehlerConfigDirectory : self::CONFIG_FEHLER_NAME;
|
||||
|
||||
$configFilename = APPPATH.self::CONFIG_DIRECTORY.'/'.$fehlerConfigDirectory.'.php';
|
||||
|
||||
if (!file_exists($configFilename))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Load Fehler Entries
|
||||
$this->_ci->load->config($fehlerConfigDirectory);
|
||||
$configArray = $this->_ci->config->item(self::CONFIG_FEHLER_INDEX);
|
||||
|
||||
if (!isset($configArray) || !is_array($configArray)) // check if fehler config entries could be loaded
|
||||
{
|
||||
$this->_ci->eprintflib->printError(
|
||||
'Fehler config array could not be loaded, directory '.$fehlerConfigDirectory.' index '.self::CONFIG_FEHLER_INDEX
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->_ci->eprintflib->printInfo('------------------------------------------------------------------------------------------');
|
||||
$this->_ci->eprintflib->printInfo('Fehler installation started, directory '.$fehlerConfigDirectory);
|
||||
|
||||
foreach ($configArray as $idx => $configEntry)
|
||||
{
|
||||
// create fehler from config entry
|
||||
$createFehlerResult = $this->_createFehlerFromEntry($configEntry);
|
||||
|
||||
// write error if creation failed
|
||||
if (isError($createFehlerResult))
|
||||
{
|
||||
$this->_ci->eprintflib->printError(
|
||||
getError($createFehlerResult).', directory'.$fehlerConfigDirectory.', index '.$idx
|
||||
);
|
||||
}
|
||||
elseif (hasData($createFehlerResult))
|
||||
{
|
||||
// add fehler to db
|
||||
$addFehlerResult = $this->_addFehler(getData($createFehlerResult));
|
||||
|
||||
if (isError($addFehlerResult))
|
||||
{
|
||||
$this->_ci->eprintflib->printError(
|
||||
getError($addFehlerResult).', directory'.$fehlerConfigDirectory.', index '.$idx
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->_ci->eprintflib->printInfo('Fehler installation ended');
|
||||
$this->_ci->eprintflib->printInfo('------------------------------------------------------------------------------------------');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new fehler to the database
|
||||
*/
|
||||
private function _addFehler($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]);
|
||||
$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;
|
||||
|
||||
// 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])
|
||||
{
|
||||
return error("Wrong fehlercode - fehler kurzbz combination: ".$fehler[self::FEHLERCODE].", ".$fehler[self::FEHLER_KURZBZ]);
|
||||
}
|
||||
|
||||
$this->_ci->eprintflib->printMessage("Fehler ".$fehler[self::FEHLERCODE]." already exists in database");
|
||||
return success($fehler[self::FEHLERCODE]);
|
||||
}
|
||||
|
||||
// no fehler has been found
|
||||
|
||||
// hanlde apps
|
||||
if (isset($fehler[self::APP]))
|
||||
{
|
||||
$apps = $fehler[self::APP];
|
||||
if (is_string($apps)) $apps = [$apps];
|
||||
//unset($fehler[self::APP]);
|
||||
$fehler[self::APP] = $apps[0];
|
||||
|
||||
//~ foreach ($apps as $app)
|
||||
//~ {
|
||||
//~ // TODO add entry for each app
|
||||
//~ foreach ($_ as $_)
|
||||
//~ {
|
||||
|
||||
//~ }
|
||||
|
||||
//~ }
|
||||
}
|
||||
|
||||
// Then add the fehler to the database
|
||||
$fehlerInsertResult = $this->_ci->FehlerModel->insert(
|
||||
$fehler
|
||||
// TODO: add insertamum?
|
||||
//~ array(
|
||||
//~ 'insertamum' => 'NOW()',
|
||||
//~ 'insertvon' => self::INSERT_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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an array with fehler data from config entry
|
||||
*/
|
||||
private function _createFehlerFromEntry($configEntry)
|
||||
{
|
||||
$fehler = [];
|
||||
foreach (self::FEHLER_ATTRIBUTES as $attributeName => $attributeConditions)
|
||||
{
|
||||
$required = isset($attributeConditions['required']) && $attributeConditions['required'];
|
||||
if ($required && !isset($configEntry[$attributeName]))
|
||||
{
|
||||
return error('attribute'.$attributeName.' is missing');
|
||||
}
|
||||
|
||||
$attributeValue = $configEntry[$attributeName];
|
||||
$validType = false;
|
||||
if (isset($attributeConditions['types']) && is_array($attributeConditions['types']))
|
||||
{
|
||||
foreach ($attributeConditions['types'] as $type)
|
||||
{
|
||||
switch ($type)
|
||||
{
|
||||
case self::TYPE_STRING:
|
||||
if (is_string($attributeValue) || is_null($attributeValue)) $validType = true;
|
||||
break;
|
||||
case self::TYPE_ARRAY:
|
||||
if (is_array($attributeValue) && !($required && isEmptyArray($attributeValue))) $validType = true;
|
||||
break;
|
||||
//~ default:
|
||||
//~ if (is_string($configEntry[$attributeName]) || is_null($configEntry[$attributeName])) $validType = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$validType = is_string($attributeValue) || is_null($attributeValue);
|
||||
}
|
||||
|
||||
if (!$validType)
|
||||
{
|
||||
return error('attribute'.$attributeName.' has invalid type');
|
||||
}
|
||||
|
||||
$fehler[$attributeName] = $configEntry[$attributeName];
|
||||
}
|
||||
return success($fehler);
|
||||
}
|
||||
}
|
||||
@@ -231,7 +231,7 @@ class IssuesLib
|
||||
return error("Person_id or oe_kurzbz must be set.");
|
||||
|
||||
// get fehlertextVorlage and replace it with params
|
||||
$fehlerRes = $this->_ci->FehlerModel->load($fehlercode);
|
||||
$fehlerRes = $this->_ci->FehlerModel->loadWhere(['fehlercode' => $fehlercode]);
|
||||
|
||||
if (hasData($fehlerRes))
|
||||
{
|
||||
|
||||
@@ -76,16 +76,19 @@ class PlausicheckProducerLib
|
||||
// Load Fehler Entries of Core
|
||||
$configArray = $this->_ci->config->item(self::CONFIG_FEHLER_INDEX);
|
||||
|
||||
foreach ($configArray as $coreEntry)
|
||||
if (isset($configArray) && is_array($configArray))
|
||||
{
|
||||
if (!isset($coreEntry[self::FEHLER_KURZBZ_NAME])
|
||||
|| !isset($coreEntry[self::PRODUCER_LIB_NAME])
|
||||
|| !in_array($coreEntry[self::FEHLER_KURZBZ_NAME], $this->_fehlerKurzbz)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
foreach ($configArray as $coreEntry)
|
||||
{
|
||||
if (!isset($coreEntry[self::FEHLER_KURZBZ_NAME])
|
||||
|| !isset($coreEntry[self::PRODUCER_LIB_NAME])
|
||||
|| !in_array($coreEntry[self::FEHLER_KURZBZ_NAME], $this->_fehlerKurzbz)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->_fehlerLibMappings[$coreEntry[self::FEHLER_KURZBZ_NAME]][self::PRODUCER_LIB_NAME] = $coreEntry[self::PRODUCER_LIB_NAME];
|
||||
$this->_fehlerLibMappings[$coreEntry[self::FEHLER_KURZBZ_NAME]][self::PRODUCER_LIB_NAME] = $coreEntry[self::PRODUCER_LIB_NAME];
|
||||
}
|
||||
}
|
||||
|
||||
// load fehler entries of extensions
|
||||
|
||||
@@ -9,6 +9,7 @@ class Fehler_model extends DB_Model
|
||||
{
|
||||
parent::__construct();
|
||||
$this->dbTable = 'system.tbl_fehler';
|
||||
$this->pk = 'fehlercode';
|
||||
$this->pk = array('fehlercode');
|
||||
$this->hasSequence = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user