Issues: enabled extensions to produce own plausichecks, IssueResolver: moved directory names to constants, deleted unused IIssueExistsChecker

This commit is contained in:
KarpAlex
2023-02-23 19:27:45 +01:00
parent fd39312de6
commit 4f2ca62d05
8 changed files with 172 additions and 125 deletions
@@ -1,62 +1,18 @@
<?php
/**
* Job for producing Plausicheck issues
* Job for producing core Plausicheck issues
*/
class PlausiIssueProducer extends JOB_Controller
class PlausiIssueProducer extends PlausiIssueProducer_Controller
{
public function __construct()
{
parent::__construct();
$this->load->library('issues/PlausicheckProducerLib');
$this->load->library('IssuesLib');
}
$this->load->library('issues/PlausicheckDefinitionLib');
/**
* Runs issue production job.
* @param studiensemester_kurzbz string job is run for students of a certain semester.
* @param studiengang_kz int job is run for students of certain Studiengang.
*/
public function run($studiensemester_kurzbz = null, $studiengang_kz = null)
{
$fehlerKurzbz = $this->plausicheckproducerlib->getFehlerKurzbz();
$this->logInfo("Plausicheck issue producer job started");
// get the data returned by Plausicheck
foreach ($fehlerKurzbz as $fehler_kurzbz)
{
// execute the check
$this->logInfo("Checking " . $fehler_kurzbz . "...");
$plausicheckRes = $this->plausicheckproducerlib->producePlausicheckIssue($fehler_kurzbz, $studiensemester_kurzbz, $studiengang_kz);
if (isError($plausicheckRes)) $this->logError(getError($plausicheckRes));
if (hasData($plausicheckRes))
{
$plausicheckData = getData($plausicheckRes);
foreach ($plausicheckData as $plausiData)
{
// get the data needed for issue production
$person_id = isset($plausiData['person_id']) ? $plausiData['person_id'] : null;
$oe_kurzbz = isset($plausiData['oe_kurzbz']) ? $plausiData['oe_kurzbz'] : null;
$fehlertext_params = isset($plausiData['fehlertext_params']) ? $plausiData['fehlertext_params'] : null;
$resolution_params = isset($plausiData['resolution_params']) ? $plausiData['resolution_params'] : null;
// write the issue
$addIssueRes = $this->issueslib->addFhcIssue($fehler_kurzbz, $person_id, $oe_kurzbz, $fehlertext_params, $resolution_params);
// log if error, or log info if inserted new issue
if (isError($addIssueRes))
$this->logError(getError($addIssueRes));
elseif (hasData($addIssueRes) && is_integer(getData($addIssueRes)))
$this->logInfo("Plausicheck issue " . $fehler_kurzbz . " successfully produced, person_id: " . $person_id);
}
}
}
$this->logInfo("Plausicheck issue producer job stopped");
// set fehler which can be produced by the job
// structure: fehler_kurzbz => class (library) name for resolving
$this->_fehlerLibMappings = $this->plausicheckdefinitionlib->getFehlerLibMappings();
}
}
@@ -15,6 +15,7 @@ class Plausichecks extends Auth_Controller
// Load libraries
$this->load->library('issues/PlausicheckProducerLib');
$this->load->library('issues/PlausicheckDefinitionLib');
$this->load->library('WidgetLib');
// Load models
@@ -44,16 +45,20 @@ class Plausichecks extends Auth_Controller
// issues array for passing issue texts
$issueTexts = array();
// all fehler kurzbz which are going to be checked
$fehlerKurzbz = !isEmptyString($fehler_kurzbz) ? array($fehler_kurzbz) : $this->plausicheckproducerlib->getFehlerKurzbz();
$fehlerKurzbz = !isEmptyString($fehler_kurzbz) ? array($fehler_kurzbz) : $this->plausicheckdefinitionlib->getFehlerKurzbz();
$fehlerLibMappings = $this->plausicheckdefinitionlib->getFehlerLibMappings();
// set Studiengang to null if not passed
if (isEmptyString($studiengang_kz)) $studiengang_kz = null;
// get the data returned by Plausicheck
foreach ($fehlerKurzbz as $fehler_kurzbz)
{
// execute the check
$issueTexts[$fehler_kurzbz] = array();
$plausicheckRes = $this->plausicheckproducerlib->producePlausicheckIssue($fehler_kurzbz, $studiensemester_kurzbz, $studiengang_kz);
// get library name for producing issue
$libName = $fehlerLibMappings[$fehler_kurzbz];
// execute the check
$plausicheckRes = $this->plausicheckproducerlib->producePlausicheckIssue($libName, $studiensemester_kurzbz, $studiengang_kz);
if (isError($plausicheckRes)) $this->terminateWithJsonError(getError($plausicheckRes));
@@ -121,7 +126,7 @@ class Plausichecks extends Auth_Controller
if (isError($studiengaengeRes)) show_error(getError($studiengaengeRes));
$fehlerKurzbz = $this->plausicheckproducerlib->getFehlerKurzbz();
$fehlerKurzbz = $this->plausicheckdefinitionlib->getFehlerKurzbz();
return array(
'semester' => hasData($studiensemesterRes) ? getData($studiensemesterRes) : array(),
-21
View File
@@ -1,21 +0,0 @@
<?php
/**
* Interface defining method to implement for issue producer (from core and extensions)
*/
interface IIssueExistsChecker
{
/**
* Checks if an issue exists.
* @param array $params parameters needed for issue detection
* @return object with success(true) if issue exists, success(false) otherwise
*/
public function checkIfIssueExists($paramsForChecking);
/**
* Produces an issue.
* @param array $params parameters needed for issue detection
* @return object with success(true) if issue exists, success(false) otherwise
*/
//public function produceIssue($person_id, $oe_kurzbz, $paramsForProducing);
}
+12 -3
View File
@@ -6,6 +6,8 @@
abstract class IssueResolver_Controller extends JOB_Controller
{
const CI_PATH = 'application';
const CI_LIBRARY_FOLDER = 'libraries';
const EXTENSIONS_FOLDER = 'extensions';
const ISSUE_RESOLVERS_FOLDER = 'issues/resolvers';
const CHECK_ISSUE_RESOLVED_METHOD_NAME = 'checkIfIssueIsResolved';
@@ -60,10 +62,17 @@ abstract class IssueResolver_Controller extends JOB_Controller
isset($issue->behebung_parameter) ? json_decode($issue->behebung_parameter, true) : array()
);
// if called from extension (extension name set), path includes extension names, otherwise it is the core library folder
$libRootPath = isset($this->_extensionName) ? 'extensions/' . $this->_extensionName . '/' : '';
// TODO: what if extension/library folder changes?
// 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 . '/';
$issuesLibFilePath = DOC_ROOT . self::CI_PATH . '/' . $libRootPath . 'libraries/' . self::ISSUE_RESOLVERS_FOLDER . '/' . $libName . '.php';
// 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))
@@ -0,0 +1,66 @@
<?php
/**
* Job for producing Plausicheck issues
*/
abstract class PlausiIssueProducer_Controller extends JOB_Controller
{
protected $_fehlerLibMappings;
public function __construct()
{
parent::__construct();
$this->load->library('issues/PlausicheckProducerLib');
$this->load->library('IssuesLib');
}
/**
* Runs issue production job.
* @param studiensemester_kurzbz string job is run for students of a certain semester.
* @param studiengang_kz int job is run for students of certain Studiengang.
*/
public function run($studiensemester_kurzbz = null, $studiengang_kz = null)
{
$this->logInfo("Plausicheck issue producer job started");
// get the data returned by Plausicheck
foreach ($this->_fehlerLibMappings as $fehler_kurzbz => $libName)
{
// execute the check
$this->logInfo("Checking " . $fehler_kurzbz . "...");
$plausicheckRes = $this->plausicheckproducerlib->producePlausicheckIssue(
$libName,
$studiensemester_kurzbz,
$studiengang_kz
);
if (isError($plausicheckRes)) $this->logError(getError($plausicheckRes));
if (hasData($plausicheckRes))
{
$plausicheckData = getData($plausicheckRes);
foreach ($plausicheckData as $plausiData)
{
// get the data needed for issue production
$person_id = isset($plausiData['person_id']) ? $plausiData['person_id'] : null;
$oe_kurzbz = isset($plausiData['oe_kurzbz']) ? $plausiData['oe_kurzbz'] : null;
$fehlertext_params = isset($plausiData['fehlertext_params']) ? $plausiData['fehlertext_params'] : null;
$resolution_params = isset($plausiData['resolution_params']) ? $plausiData['resolution_params'] : null;
// write the issue
$addIssueRes = $this->issueslib->addFhcIssue($fehler_kurzbz, $person_id, $oe_kurzbz, $fehlertext_params, $resolution_params);
// log if error, or log info if inserted new issue
if (isError($addIssueRes))
$this->logError(getError($addIssueRes));
elseif (hasData($addIssueRes) && is_integer(getData($addIssueRes)))
$this->logInfo("Plausicheck issue " . $fehler_kurzbz . " successfully produced, person_id: " . $person_id);
}
}
}
$this->logInfo("Plausicheck issue producer job stopped");
}
}
@@ -0,0 +1,55 @@
<?php
if (! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Library containing definitions of all core plausichecks.
*/
class PlausicheckDefinitionLib
{
// set fehler for core plausichecks
// structure: fehler_kurzbz => class (library) name for resolving
private $_fehlerLibMappings = array(
'AbbrecherAktiv' => 'AbbrecherAktiv',
'AbschlussstatusFehlt' => 'AbschlussstatusFehlt',
'AktSemesterNull' => 'AktSemesterNull',
'AktiverStudentOhneStatus' => 'AktiverStudentOhneStatus',
'AusbildungssemPrestudentUngleichAusbildungssemStatus' => 'AusbildungssemPrestudentUngleichAusbildungssemStatus',
'BewerberNichtZumRtAngetreten' => 'BewerberNichtZumRtAngetreten',
'DatumAbschlusspruefungFehlt' => 'DatumAbschlusspruefungFehlt',
'DatumSponsionFehlt' => 'DatumSponsionFehlt',
'DatumStudiensemesterFalscheReihenfolge' => 'DatumStudiensemesterFalscheReihenfolge',
'FalscheAnzahlAbschlusspruefungen' => 'FalscheAnzahlAbschlusspruefungen',
'FalscheAnzahlHeimatadressen' => 'FalscheAnzahlHeimatadressen',
'FalscheAnzahlZustelladressen' => 'FalscheAnzahlZustelladressen',
'GbDatumWeitZurueck' => 'GbDatumWeitZurueck',
'InaktiverStudentAktiverStatus' => 'InaktiverStudentAktiverStatus',
'IncomingHeimatNationOesterreich' => 'IncomingHeimatNationOesterreich',
'IncomingOhneIoDatensatz' => 'IncomingOhneIoDatensatz',
'IncomingOrGsFoerderrelevant' => 'IncomingOrGsFoerderrelevant',
'InskriptionVorLetzerBismeldung' => 'InskriptionVorLetzerBismeldung',
'NationNichtOesterreichAberGemeinde' => 'NationNichtOesterreichAberGemeinde',
'OrgformStgUngleichOrgformPrestudent' => 'OrgformStgUngleichOrgformPrestudent',
'PrestudentMischformOhneOrgform' => 'PrestudentMischformOhneOrgform',
'StgPrestudentUngleichStgStudienplan' => 'StgPrestudentUngleichStgStudienplan',
'StgPrestudentUngleichStgStudent' => 'StgPrestudentUngleichStgStudent',
'StudentstatusNachAbbrecher' => 'StudentstatusNachAbbrecher'
//'StudienplanUngueltig' => 'StudienplanUngueltig'
);
/**
* Gets all fehler_kurzbz for fehler which need to be checked.
*/
public function getFehlerLibMappings()
{
return $this->_fehlerLibMappings;
}
/**
* Gets all fehler_kurzbz for fehler which need to be checked.
*/
public function getFehlerKurzbz()
{
return array_keys($this->_fehlerLibMappings);
}
}
@@ -2,6 +2,9 @@
if (! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Library containing database queries for execution of core plausichecks.
*/
class PlausicheckLib
{
private $_ci; // Code igniter instance
@@ -4,43 +4,15 @@ if (! defined('BASEPATH')) exit('No direct script access allowed');
class PlausicheckProducerLib
{
const CI_LIBRARY_PATH = 'application/libraries';
const CI_PATH = 'application';
const CI_LIBRARY_FOLDER = 'libraries';
const EXTENSIONS_FOLDER = 'extensions';
const PLAUSI_ISSUES_FOLDER = 'issues/plausichecks';
const EXECUTE_PLAUSI_CHECK_METHOD_NAME = 'executePlausiCheck';
private $_ci; // ci instance
private $_currentStudiensemester; // current Studiensemester
// set fehler which can be produced by the job
// structure: fehler_kurzbz => class (library) name for resolving
private $_fehlerLibMappings = array(
'AbbrecherAktiv' => 'AbbrecherAktiv',
'AbschlussstatusFehlt' => 'AbschlussstatusFehlt',
'AktSemesterNull' => 'AktSemesterNull',
'AktiverStudentOhneStatus' => 'AktiverStudentOhneStatus',
'AusbildungssemPrestudentUngleichAusbildungssemStatus' => 'AusbildungssemPrestudentUngleichAusbildungssemStatus',
'BewerberNichtZumRtAngetreten' => 'BewerberNichtZumRtAngetreten',
'DatumAbschlusspruefungFehlt' => 'DatumAbschlusspruefungFehlt',
'DatumSponsionFehlt' => 'DatumSponsionFehlt',
'DatumStudiensemesterFalscheReihenfolge' => 'DatumStudiensemesterFalscheReihenfolge',
'FalscheAnzahlAbschlusspruefungen' => 'FalscheAnzahlAbschlusspruefungen',
'FalscheAnzahlHeimatadressen' => 'FalscheAnzahlHeimatadressen',
'FalscheAnzahlZustelladressen' => 'FalscheAnzahlZustelladressen',
'GbDatumWeitZurueck' => 'GbDatumWeitZurueck',
'InaktiverStudentAktiverStatus' => 'InaktiverStudentAktiverStatus',
'IncomingHeimatNationOesterreich' => 'IncomingHeimatNationOesterreich',
'IncomingOhneIoDatensatz' => 'IncomingOhneIoDatensatz',
'IncomingOrGsFoerderrelevant' => 'IncomingOrGsFoerderrelevant',
'InskriptionVorLetzerBismeldung' => 'InskriptionVorLetzerBismeldung',
'NationNichtOesterreichAberGemeinde' => 'NationNichtOesterreichAberGemeinde',
'OrgformStgUngleichOrgformPrestudent' => 'OrgformStgUngleichOrgformPrestudent',
'PrestudentMischformOhneOrgform' => 'PrestudentMischformOhneOrgform',
'StgPrestudentUngleichStgStudienplan' => 'StgPrestudentUngleichStgStudienplan',
'StgPrestudentUngleichStgStudent' => 'StgPrestudentUngleichStgStudent',
'StudentstatusNachAbbrecher' => 'StudentstatusNachAbbrecher'
//'StudienplanUngueltig' => 'StudienplanUngueltig'
);
public function __construct()
{
$this->_ci =& get_instance(); // get ci instance
@@ -54,27 +26,37 @@ class PlausicheckProducerLib
}
/**
* Executes check for a fehler_kurzbz, returns the result.
* @param $fehler_kurzbz string
* Executes plausicheck using a given library, returns the result.
* @param $libName string
* @param $studiensemester_kurzbz string optionally needed for issue production
* @param $studiengang_kz int optionally needed for issue production
*/
public function producePlausicheckIssue($fehler_kurzbz, $studiensemester_kurzbz = null, $studiengang_kz = null)
public function producePlausicheckIssue($libName, $studiensemester_kurzbz = null, $studiengang_kz = null)
{
$libName = $this->_fehlerLibMappings[$fehler_kurzbz];
// get Studiensemester
if (isEmptyString($studiensemester_kurzbz)) $studiensemester_kurzbz = $this->_currentStudiensemester;
// 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::PLAUSI_ISSUES_FOLDER . '/';
// file path of library for check if file exists
$issuesLibFilePath = DOC_ROOT . self::CI_PATH
. '/' . $libRootPath . self::CI_LIBRARY_FOLDER . '/' . self::PLAUSI_ISSUES_FOLDER . '/' . $libName . '.php';
// get path of library for issue to be produced
$issuesLibPath = DOC_ROOT . self::CI_LIBRARY_PATH . '/' . self::PLAUSI_ISSUES_FOLDER . '/';
$issuesLibFilePath = $issuesLibPath . $libName . '.php';
//~ $issuesLibPath = DOC_ROOT . self::CI_LIBRARY_PATH . '/' . self::PLAUSI_ISSUES_FOLDER . '/';
//~ $issuesLibFilePath = $issuesLibPath . $libName . '.php';
// check if library file exists
if (!file_exists($issuesLibFilePath)) return error("Issue library file " . $issuesLibFilePath . " does not exist");
// load library connected to fehlercode
$this->_ci->load->library(self::PLAUSI_ISSUES_FOLDER . '/'.$libName);
//$this->_ci->load->library(self::PLAUSI_ISSUES_FOLDER . '/'.$libName);
$this->_ci->load->library($issuesLibPath . $libName);
$lowercaseLibName = mb_strtolower($libName);
@@ -91,12 +73,4 @@ class PlausicheckProducerLib
// call the function for checking for issue production
return $this->_ci->{$lowercaseLibName}->{self::EXECUTE_PLAUSI_CHECK_METHOD_NAME}($paramsForCheck);
}
/**
* Gets all fehler_kurzbz for fehler which need to be checked.
*/
public function getFehlerKurzbz()
{
return array_keys($this->_fehlerLibMappings);
}
}