Skip to content

Commit

Permalink
Test export plugins cause error during ILIAS setup (42070)
Browse files Browse the repository at this point in the history
  • Loading branch information
fneumann authored and kergomard committed Sep 18, 2024
1 parent d941dfb commit fb811f9
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions Modules/Test/classes/class.ilTestExportPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,12 @@ abstract class ilTestExportPlugin extends ilPlugin
'csv'
);
private \ilGlobalTemplateInterface $main_tpl;
private \ilLanguage $lng;
private \ilCtrl $ctrl;

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

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

Expand Down Expand Up @@ -104,7 +97,12 @@ final public function getFormat(): string
*/
final public function export(): void
{
global $DIC; // $DIC['tpl'] is not available in the constructor, so we need to fetch it here
/** @var ILIAS\DI\Container $DIC */
global $DIC;
// these dependencies need to be fetched here because they are not available in constructor during ILIAS setup
$tpl = $DIC->ui()->mainTemplate();
$ctrl = $DIC->ctrl();
$lng = $DIC->language();

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

$DIC['tpl']->setOnScreenMessage('success', $this->lng->txt('exp_file_created'), true);
$this->ctrl->redirectByClass('iltestexportgui');
$tpl->setOnScreenMessage('success', $lng->txt('exp_file_created'), true);
$ctrl->redirectByClass('iltestexportgui');
}

/**
Expand Down

0 comments on commit fb811f9

Please sign in to comment.