Skip to content

Commit

Permalink
Test: Fix Access to Uninitialized Values in DIC
Browse files Browse the repository at this point in the history
  • Loading branch information
kergomard committed Sep 18, 2024
1 parent dfb75e3 commit 99fb6df
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions components/ILIAS/Test/classes/class.ilTestExportPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,12 @@ abstract class ilTestExportPlugin extends ilPlugin
'xml',
'csv'
];
private \ilGlobalTemplateInterface $main_tpl;
private \ilLanguage $lng;
private \ilCtrlInterface $ctrl;

public function __construct(
\ilDBInterface $db,
\ilComponentRepositoryWrite $component_repository,
string $id
) {
/** @var ILIAS\DI\Container $DIC */
global $DIC;
$this->main_tpl = $DIC['tpl'];
$this->lng = $DIC['lng'];
$this->ctrl = $DIC['ilCtrl'];

parent::__construct($db, $component_repository, $id);
}

Expand Down Expand Up @@ -105,6 +96,12 @@ final public function getFormat(): string
*/
final public function export(): void
{
/** @var ILIAS\DI\Container $DIC */
global $DIC;
$main_tpl = $DIC['tpl'];
$lng = $DIC['lng'];
$ctrl = $DIC['ilCtrl'];

if (!$this->getTest() instanceof ilObjTest) {
throw new ilException('Incomplete object configuration. Please pass an instance of ilObjTest before calling the export!');
}
Expand All @@ -113,15 +110,15 @@ final public function export(): void
$this->buildExportFile(new ilTestExportFilename($this->getTest()));
} catch (ilException $e) {
if ($this->txt($e->getMessage()) == '-' . $e->getMessage() . '-') {
$this->main_tpl->setOnScreenMessage('failure', $e->getMessage(), true);
$main_tpl->setOnScreenMessage('failure', $e->getMessage(), true);
} else {
$this->main_tpl->setOnScreenMessage('failure', $this->txt($e->getMessage()), true);
$main_tpl->setOnScreenMessage('failure', $this->txt($e->getMessage()), true);
}
$this->ctrl->redirectByClass('iltestexportgui');
$ctrl->redirectByClass('iltestexportgui');
}

$this->main_tpl->setOnScreenMessage('success', $this->lng->txt('exp_file_created'), true);
$this->ctrl->redirectByClass('iltestexportgui');
$main_tpl->setOnScreenMessage('success', $lng->txt('exp_file_created'), true);
$ctrl->redirectByClass('iltestexportgui');
}

/**
Expand Down

0 comments on commit 99fb6df

Please sign in to comment.