mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-24 02:12:17 +00:00
issues: changed logic to read producable issues from config file
This commit is contained in:
@@ -9,28 +9,106 @@ class PlausicheckResolverLib
|
||||
const EXTENSIONS_FOLDER = 'extensions';
|
||||
const ISSUE_RESOLVERS_FOLDER = 'issues/resolvers';
|
||||
const CHECK_ISSUE_RESOLVED_METHOD_NAME = 'checkIfIssueIsResolved';
|
||||
const CONFIG_FEHLER_FILENAME = 'fehler.php';
|
||||
const CONFIG_FEHLER_NAME = 'fehler';
|
||||
const FEHLERCODE_NAME = 'fehlercode';
|
||||
const FEHLER_KURZBZ_NAME = 'fehler_kurzbz';
|
||||
const RESOLVER_LIB_NAME = 'resolverLibName';
|
||||
const PRODUCER_IS_RESOLVER_NAME = 'producerIsResolver';
|
||||
const EXTENSION_NAME = 'extensionName';
|
||||
|
||||
|
||||
private $_ci; // ci instance
|
||||
private $_extensionName; // name of extension
|
||||
private $_fehlercodes = []; // name of extension
|
||||
private $_codeLibMappings = []; // mappings for issues which explicitly defined resolver
|
||||
private $_codeProducerLibMappings = []; // mappings for issues which are resolved with the same check as they are produced
|
||||
private $_defaultIssueParams = ['issue_id' => 'issue_id', 'issue_person_id' => 'person_id', 'issue_oe_kurzbz' => 'oe_kurzbz'];
|
||||
|
||||
public function __construct($params = null)
|
||||
{
|
||||
// set extension name if called from extension
|
||||
if (isset($params['extensionName'])) $this->_extensionName = $params['extensionName'];
|
||||
if (isset($params['codeLibMappings'])) $this->_codeLibMappings = $params['codeLibMappings'];
|
||||
if (isset($params['codeProducerLibMappings'])) $this->_codeProducerLibMappings = $params['codeProducerLibMappings'];
|
||||
// get all fehler to be produced (by kurzbz array or app)
|
||||
if (isset($params['fehlercodes']) && !isEmptyArray($params['fehlercodes']))
|
||||
{
|
||||
$this->_fehlercodes = $params['fehlercodes'];
|
||||
}
|
||||
|
||||
$this->_ci =& get_instance(); // get ci instance
|
||||
|
||||
$this->_ci->load->library('IssuesLib');
|
||||
$this->_ci->load->library('issues/PlausicheckProducerLib', ['extensionName' => $this->_extensionName, 'isForResolutionCheck' => true]);
|
||||
$this->_ci->load->library('ExtensionsLib');
|
||||
|
||||
$this->_ci->load->config('fehler');
|
||||
|
||||
// Load Fehler Entries of Core
|
||||
$configArray = $this->_ci->config->item(self::CONFIG_FEHLER_NAME);
|
||||
|
||||
$fehlerKurzbzArr = [];
|
||||
|
||||
foreach ($configArray as $coreEntry)
|
||||
{
|
||||
if (!isset($coreEntry[self::FEHLERCODE_NAME])
|
||||
|| !in_array($coreEntry[self::FEHLERCODE_NAME], $this->_fehlercodes)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isset($coreEntry[self::FEHLER_KURZBZ_NAME])) $fehlerKurzbzArr[] = $coreEntry[self::FEHLER_KURZBZ_NAME];
|
||||
|
||||
$this->_codeLibMappings[$coreEntry[self::FEHLERCODE_NAME]][self::RESOLVER_LIB_NAME] = $coreEntry[self::RESOLVER_LIB_NAME] ?? null;
|
||||
$this->_codeLibMappings[$coreEntry[self::FEHLERCODE_NAME]][self::PRODUCER_IS_RESOLVER_NAME]
|
||||
= $coreEntry[self::PRODUCER_IS_RESOLVER_NAME] ?? false;
|
||||
}
|
||||
|
||||
// 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::FEHLERCODE_NAME])
|
||||
|| !in_array($extensionEntry[self::FEHLERCODE_NAME], $this->_fehlercodes)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$fehlercode = $extensionEntry[self::FEHLERCODE_NAME];
|
||||
if (isset($extensionEntry[self::FEHLER_KURZBZ_NAME])) $fehlerKurzbzArr[] = $extensionEntry[self::FEHLER_KURZBZ_NAME];
|
||||
|
||||
$this->_codeLibMappings[$fehlercode][self::RESOLVER_LIB_NAME]
|
||||
= $extensionEntry[self::RESOLVER_LIB_NAME] ?? null;
|
||||
$this->_codeLibMappings[$fehlercode][self::EXTENSION_NAME] = $ext->name;
|
||||
$this->_codeLibMappings[$fehlercode][self::PRODUCER_IS_RESOLVER_NAME]
|
||||
= $extensionEntry[self::PRODUCER_IS_RESOLVER_NAME] ?? false;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->_ci->load->library('issues/PlausicheckProducerLib', ['fehlerKurzbz' => $fehlerKurzbzArr]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reseolves multiple plausicheck issues at once.
|
||||
* @param array $codeLibMappings contains fehler type to check and library responsible for check (fehlercode => libName)
|
||||
* @param array $openIssues passed issues to resolve
|
||||
* @return result object with occured error and info
|
||||
*/
|
||||
@@ -40,12 +118,25 @@ class PlausicheckResolverLib
|
||||
$result->errors = [];
|
||||
$result->infos = [];
|
||||
|
||||
// check if all issues to resolve could be found in database
|
||||
$mappingFehlerCodes = array_keys($this->_codeLibMappings);
|
||||
$notFoundFehlerCodes = array_diff($this->_fehlercodes, $mappingFehlerCodes);
|
||||
|
||||
if (!isEmptyArray($notFoundFehlerCodes))
|
||||
$result->errors[] = error('Fehler to resolve not defined in config: '.implode(', ', $notFoundFehlerCodes));
|
||||
|
||||
foreach ($openIssues as $issue)
|
||||
{
|
||||
$params = [];
|
||||
foreach ($this->_defaultIssueParams as $index => $propertyName)
|
||||
{
|
||||
$params[$index] = $issue->{$propertyName};
|
||||
}
|
||||
|
||||
// add person id and oe kurzbz automatically as params, merge it with additional params
|
||||
// decode bewerbung_parameter into assoc array
|
||||
$params = array_merge(
|
||||
array('issue_id' => $issue->issue_id, 'issue_person_id' => $issue->person_id, 'issue_oe_kurzbz' => $issue->oe_kurzbz),
|
||||
$params,
|
||||
isset($issue->behebung_parameter) ? json_decode($issue->behebung_parameter, true) : array()
|
||||
);
|
||||
|
||||
@@ -54,69 +145,72 @@ class PlausicheckResolverLib
|
||||
// ignore if Fehlercode is not in libmappings (shouldn't be checked)
|
||||
if (isset($this->_codeLibMappings[$issue->fehlercode]))
|
||||
{
|
||||
$libName = $this->_codeLibMappings[$issue->fehlercode];
|
||||
$codeLibMapping = $this->_codeLibMappings[$issue->fehlercode];
|
||||
$libName = $codeLibMapping[self::RESOLVER_LIB_NAME];
|
||||
$extensionName = $codeLibMapping[self::EXTENSION_NAME] ?? null;
|
||||
$producerIsResolver = $codeLibMapping[self::PRODUCER_IS_RESOLVER_NAME] ?? false;
|
||||
|
||||
// if called from extension (extension name set), path includes extension names
|
||||
$libRootPath = isset($this->_extensionName) ? self::EXTENSIONS_FOLDER . '/' . $this->_extensionName . '/' : '';
|
||||
|
||||
// path for loading issue library
|
||||
$issuesLibPath = $libRootPath . self::ISSUE_RESOLVERS_FOLDER . '/';
|
||||
|
||||
// file path of library for check if file exists
|
||||
$issuesLibFilePath = DOC_ROOT . self::CI_PATH
|
||||
. '/' . $libRootPath . self::CI_LIBRARY_FOLDER . '/' . self::ISSUE_RESOLVERS_FOLDER . '/' . $libName . '.php';
|
||||
|
||||
// check if library file exists
|
||||
if (!file_exists($issuesLibFilePath))
|
||||
if ($producerIsResolver)
|
||||
{
|
||||
// log error and continue with next issue if not
|
||||
$result->errors[] = "Issue library file " . $issuesLibFilePath . " does not exist";
|
||||
continue;
|
||||
}
|
||||
// execute same check as used for issue production
|
||||
$issueResolvedRes = $this->_ci->plausicheckproducerlib->producePlausicheckIssue(
|
||||
$issue->fehler_kurzbz,
|
||||
$params
|
||||
);
|
||||
|
||||
// load library connected to fehlercode
|
||||
$this->_ci->load->library($issuesLibPath . $libName);
|
||||
|
||||
$lowercaseLibName = mb_strtolower($libName);
|
||||
|
||||
// check if method is defined in library class
|
||||
if (!is_callable(array($this->_ci->{$lowercaseLibName}, self::CHECK_ISSUE_RESOLVED_METHOD_NAME)))
|
||||
{
|
||||
// log error and continue with next issue if not
|
||||
$result->errors[] = "Method " . self::CHECK_ISSUE_RESOLVED_METHOD_NAME . " is not defined in library $lowercaseLibName";
|
||||
continue;
|
||||
}
|
||||
|
||||
// call the function for checking for issue resolution
|
||||
$issueResolvedRes = $this->_ci->{$lowercaseLibName}->{self::CHECK_ISSUE_RESOLVED_METHOD_NAME}($params);
|
||||
|
||||
if (isError($issueResolvedRes))
|
||||
{
|
||||
$result->errors[] = getError($issueResolvedRes);
|
||||
if (isError($issueResolvedRes))
|
||||
{
|
||||
$result->errors[] = getError($issueResolvedRes);
|
||||
}
|
||||
else
|
||||
{
|
||||
$issueResolved = !hasData($issueResolvedRes);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$issueResolved = getData($issueResolvedRes) === true;
|
||||
}
|
||||
}
|
||||
elseif (isset($this->_codeProducerLibMappings[$issue->fehlercode])) // check if it is an issue without explicit resolver, "self-resolving"
|
||||
{
|
||||
$libName = $this->_codeProducerLibMappings[$issue->fehlercode];
|
||||
// if called from extension (extension name set), path includes extension names
|
||||
$libRootPath = isset($extensionName) ? self::EXTENSIONS_FOLDER . '/' . $extensionName . '/' : '';
|
||||
|
||||
// execute same check as used for issue production
|
||||
$issueResolvedRes = $this->_ci->plausicheckproducerlib->producePlausicheckIssue(
|
||||
$libName,
|
||||
$issue->fehler_kurzbz,
|
||||
$params
|
||||
);
|
||||
// path for loading issue library
|
||||
$issuesLibPath = $libRootPath . self::ISSUE_RESOLVERS_FOLDER . '/';
|
||||
|
||||
if (isError($issueResolvedRes))
|
||||
{
|
||||
$result->errors[] = getError($issueResolvedRes);
|
||||
}
|
||||
else
|
||||
{
|
||||
$issueResolved = !hasData($issueResolvedRes);
|
||||
// file path of library for check if file exists
|
||||
$issuesLibFilePath = DOC_ROOT . self::CI_PATH
|
||||
. '/' . $libRootPath . self::CI_LIBRARY_FOLDER . '/' . self::ISSUE_RESOLVERS_FOLDER . '/' . $libName . '.php';
|
||||
|
||||
// check if library file exists
|
||||
if (!file_exists($issuesLibFilePath))
|
||||
{
|
||||
// log error and continue with next issue if not
|
||||
$result->errors[] = "Issue library file " . $issuesLibFilePath . " does not exist";
|
||||
continue;
|
||||
}
|
||||
|
||||
// load library connected to fehlercode
|
||||
$this->_ci->load->library($issuesLibPath . $libName);
|
||||
|
||||
$lowercaseLibName = mb_strtolower($libName);
|
||||
|
||||
// check if method is defined in library class
|
||||
if (!is_callable(array($this->_ci->{$lowercaseLibName}, self::CHECK_ISSUE_RESOLVED_METHOD_NAME)))
|
||||
{
|
||||
// log error and continue with next issue if not
|
||||
$result->errors[] = "Method " . self::CHECK_ISSUE_RESOLVED_METHOD_NAME . " is not defined in library $lowercaseLibName";
|
||||
continue;
|
||||
}
|
||||
|
||||
// call the function for checking for issue resolution
|
||||
$issueResolvedRes = $this->_ci->{$lowercaseLibName}->{self::CHECK_ISSUE_RESOLVED_METHOD_NAME}($params);
|
||||
|
||||
if (isError($issueResolvedRes))
|
||||
{
|
||||
$result->errors[] = getError($issueResolvedRes);
|
||||
}
|
||||
else
|
||||
{
|
||||
$issueResolved = getData($issueResolvedRes) === true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user