issues: changed logic to read producable issues from config file

This commit is contained in:
Alexei Karpenko
2026-01-14 14:13:23 +01:00
parent a259db2e7b
commit b168ebb5f6
12 changed files with 851 additions and 233 deletions
@@ -9,33 +9,41 @@ class PlausicheckProducerLib
const EXTENSIONS_FOLDER = 'extensions';
const PLAUSI_ISSUES_FOLDER = 'issues/plausichecks';
const EXECUTE_PLAUSI_CHECK_METHOD_NAME = 'executePlausiCheck';
const CONFIG_FEHLER_FILENAME = 'fehler.php';
const CONFIG_FEHLER_NAME = 'fehler';
const FEHLER_KURZBZ_NAME = 'fehler_kurzbz';
const PRODUCER_LIB_NAME = 'producerLibName';
const EXTENSION_NAME = 'extensionName';
private $_ci; // ci instance
private $_extensionName; // name of extension
private $_konfiguration = []; // configuration parameters
private $_fehlerKurzbz = []; // fehler to produce
private $_fehlerLibMappings = []; // mappings of fehler and libraries for producing them
private $_isForResolutionCheck = false; // mappings of fehler and libraries for producing them
private $_apps = []; // apps of fehler to produce
public function __construct($params = null)
{
// set extension name if called from extension
if (isset($params['extensionName'])) $this->_extensionName = $params['extensionName'];
if (isset($params['fehlerLibMappings'])) $this->_fehlerLibMappings = $params['fehlerLibMappings'];
if (isset($params['isForResolutionCheck'])) $this->_isForResolutionCheck = $params['isForResolutionCheck'];
// set application
$app = isset($params['app']) ? $params['app'] : null;
// set application(s))
if (isset($params['apps']))
{
if (is_string($params['apps'])) $params['apps'] = [$params['apps']];
if (is_array($params['apps'])) $this->_apps = $params['apps'];
}
$this->_ci =& get_instance(); // get ci instance
// load libraries
$this->_ci->load->library('IssuesLib');
$this->_ci->load->library('ExtensionsLib');
// load models
$this->_ci->load->model('system/Fehler_model', 'FehlerModel');
$this->_ci->load->model('system/Fehlerkonfiguration_model', 'FehlerkonfigurationModel');
// get all configuration parameters for the application
$fehlerkonfigurationRes = $this->_ci->FehlerkonfigurationModel->getKonfiguration($app);
$this->_ci->load->config('fehler');
// get all configuration parameters for the application(s))
$fehlerkonfigurationRes = $this->_ci->FehlerkonfigurationModel->getKonfiguration($this->_apps);
if (hasData($fehlerkonfigurationRes))
{
@@ -46,10 +54,86 @@ class PlausicheckProducerLib
$this->_konfiguration[$fk->fehler_kurzbz][$fk->konfigurationstyp_kurzbz] = $fk->konfiguration;
}
}
// get all fehler to be produced (by kurzbz array or app)
if (isset($params['fehlerKurzbz']) && !isEmptyArray($params['fehlerKurzbz']))
{
$this->_fehlerKurzbz = $params['fehlerKurzbz'];
}
else
{
$this->_ci->FehlerModel->addSelect('fehler_kurzbz');
if (!isEmptyArray($this->_apps)) $this->_ci->FehlerModel->db->where_in('app', $this->_apps);
$fehlerRes = $this->_ci->FehlerModel->load();
if (hasData($fehlerRes))
{
$this->_fehlerKurzbz = array_column(getData($fehlerRes), 'fehler_kurzbz');
}
}
// get producer file paths for the fehler
// Load Fehler Entries of Core
$configArray = $this->_ci->config->item(self::CONFIG_FEHLER_NAME);
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];
}
// load fehler entries of extensions
$extensions = $this->_ci->extensionslib->getInstalledExtensions();
if (hasData($extensions))
{
$extensionArray = array();
$extensionsData = getData($extensions);
foreach ($extensionsData as $ext)
{
$configFilename = APPPATH.'config/'.ExtensionsLib::EXTENSIONS_DIR_NAME.'/'.$ext->name.'/'.self::CONFIG_FEHLER_FILENAME;
if (file_exists($configFilename))
{
$config = array(); // default value
include($configFilename);
if (isset($config[self::CONFIG_FEHLER_NAME]) && is_array($config[self::CONFIG_FEHLER_NAME]))
{
foreach ($config[self::CONFIG_FEHLER_NAME] as $extensionEntry)
{
if (
!isset($extensionEntry[self::FEHLER_KURZBZ_NAME])
|| !isset($extensionEntry[self::PRODUCER_LIB_NAME])
|| !in_array($extensionEntry[self::FEHLER_KURZBZ_NAME], $this->_fehlerKurzbz)
) {
continue;
}
$fehler_kurzbz = $extensionEntry[self::FEHLER_KURZBZ_NAME];
$this->_fehlerLibMappings[$fehler_kurzbz][self::PRODUCER_LIB_NAME] = $extensionEntry[self::PRODUCER_LIB_NAME];
$this->_fehlerLibMappings[$fehler_kurzbz][self::EXTENSION_NAME] = $ext->name;
}
}
}
}
}
}
/**
* Produces multiple plausicheck issues at once and saved them to db.
* Produces multiple plausicheck issues at once, and saves them in the database.
* @param array $params passed to each plausicheck
* @return result object with occured error and info
*/
@@ -58,11 +142,17 @@ class PlausicheckProducerLib
$result = new StdClass();
$result->errors = [];
$result->infos = [];
$mappingFehlerKurbz = array_keys($this->_fehlerLibMappings);
foreach ($this->_fehlerLibMappings as $fehler_kurzbz => $libName)
// check if all issues to produce could be found in database
$notFoundFehlerKurzbz = array_diff($this->_fehlerKurzbz, $mappingFehlerKurbz);
if (!isEmptyArray($notFoundFehlerKurzbz))
$result->errors[] = error('Fehler to produce not defined in config: '.implode(', ', $notFoundFehlerKurzbz));
foreach ($mappingFehlerKurbz as $fehler_kurzbz)
{
$plausicheckRes = $this->producePlausicheckIssue(
$libName,
$fehler_kurzbz,
$params
);
@@ -96,14 +186,22 @@ class PlausicheckProducerLib
/**
* Executes plausicheck using a given library, returns the result.
* @param $libName string name of library producing the issue
* @param $fehler_kurzbz string unique short name of fehler, for which issue is produced
* @param $params parameters passed to issue production method
*/
public function producePlausicheckIssue($libName, $fehler_kurzbz, $params)
public function producePlausicheckIssue($fehler_kurzbz, $params)
{
if (!isset($this->_fehlerLibMappings[$fehler_kurzbz])) return error("Mapping for Fehler " . $fehler_kurzbz . " was not found");
$mapping = $this->_fehlerLibMappings[$fehler_kurzbz];
if (!isset($mapping[self::PRODUCER_LIB_NAME]) || isEmptyString($mapping[self::PRODUCER_LIB_NAME]))
return error("No producer lib name set for Fehler " . $fehler_kurzbz);
$libName = $mapping[self::PRODUCER_LIB_NAME];
// if called from extension (extension name set), path includes extension names
$libRootPath = isset($this->_extensionName) ? self::EXTENSIONS_FOLDER . '/' . $this->_extensionName . '/' : '';
$libRootPath = isset($mapping[self::EXTENSION_NAME]) ? self::EXTENSIONS_FOLDER . '/' . $mapping[self::EXTENSION_NAME] . '/' : '';
// path for loading issue library
$issuesLibPath = $libRootPath . self::PLAUSI_ISSUES_FOLDER . '/';
@@ -121,7 +219,7 @@ class PlausicheckProducerLib
// load library connected to fehlercode
$this->_ci->load->library(
$issuesLibPath . $libName,
['configurationParams' => $config, 'isForResolutionCheck' => $this->_isForResolutionCheck]
['configurationParams' => $config]
);
$lowercaseLibName = mb_strtolower($libName);