Skip to content

Commit

Permalink
Component/CmiXapi: contribute cron jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
nhaagen committed Dec 16, 2024
1 parent e0a0dba commit 3bad331
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 13 deletions.
12 changes: 12 additions & 0 deletions components/ILIAS/CmiXapi/CmiXapi.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,17 @@ public function init(
new \ilCmiXapiSetupAgent(
$pull[\ILIAS\Refinery\Factory::class]
);
$contribute[\ILIAS\Cron\CronJob::class] = static fn() =>
new \ilXapiResultsCronjob(
'components\\' . self::class,
$use[\ILIAS\Language\Language::class],
true
);
$contribute[\ILIAS\Cron\CronJob::class] = static fn() =>
new \ilCmiXapiDelCron(
'components\\' . self::class,
$use[\ILIAS\Language\Language::class],
true
);
}
}
22 changes: 16 additions & 6 deletions components/ILIAS/CmiXapi/classes/class.ilCmiXapiDelCron.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,29 @@ class ilCmiXapiDelCron extends ilCronJob

private \ILIAS\DI\Container $dic;

public function __construct()
public function __construct(
string $component,
\ILIAS\Language\Language $lng,
bool $registration = false
) {
parent::__construct($component, $lng);
$this->lng->loadLanguageModule('cmix');
if (!$registration) {
$this->additionalConstruct();
}
}

private function additionalConstruct()
{
global $DIC; /* @var \ILIAS\DI\Container $DIC */
$this->dic = $DIC;

$DIC->language()->loadLanguageModule('cmix');

$this->log = ilLoggerFactory::getLogger('cmix');

$settings = new ilSetting(self::JOB_ID);
$lrsTypeId = $settings->get('lrs_type_id', '0');

if($lrsTypeId) {
if ($lrsTypeId) {
$this->lrsType = new ilCmiXapiLrsType((int) $lrsTypeId);
} else {
$this->lrsType = null;
Expand Down Expand Up @@ -224,7 +234,7 @@ public function run(): ilCronJobResult
$deletedObjectData = array();
$allDone = true;
foreach ($newDeletedObjects as $deletedObject) {
$this->log->debug("delete for " . (string)$deletedObject['obj_id']);
$this->log->debug("delete for " . (string) $deletedObject['obj_id']);
// set object to updated
$this->model->setXapiObjAsUpdated($deletedObject['obj_id']);
// delete data
Expand All @@ -239,7 +249,7 @@ public function run(): ilCronJobResult
// entry in xxcf_users is already deleted from ilXapiCmi5StatementsDeleteRequest
// delete in obj_id from xxcf_data_settings
if ($done) {
$this->log->debug("deleted data for object: " . (string)$deletedObject['obj_id']);
$this->log->debug("deleted data for object: " . (string) $deletedObject['obj_id']);
$deletedObjectData[] = $deletedObject['obj_id'];
$this->model->deleteXapiObjectEntry($deletedObject['obj_id']);
} else {
Expand Down
16 changes: 13 additions & 3 deletions components/ILIAS/CmiXapi/classes/class.ilXapiResultsCronjob.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,23 @@ class ilXapiResultsCronjob extends ilCronJob

private \ILIAS\DI\Container $dic;

public function __construct()
public function __construct(
string $component,
\ILIAS\Language\Language $lng,
bool $registration = false
) {
parent::__construct($component, $lng);
$this->lng->loadLanguageModule('cmix');
if (!$registration) {
$this->additionalConstruct();
}
}

private function additionalConstruct()
{
global $DIC; /* @var \ILIAS\DI\Container $DIC */
$this->dic = $DIC;

$DIC->language()->loadLanguageModule('cmix');

$this->log = ilLoggerFactory::getLogger('cmix');

$this->initThisRunTS();
Expand Down
4 changes: 0 additions & 4 deletions components/ILIAS/CmiXapi/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@
<event type="listen" id="components/ILIAS/Course" />
<event type="listen" id="components/ILIAS/Group" />
</events>
<crons>
<cron id="xapi_results_evaluation" class="ilXapiResultsCronjob" />
<cron id="xapi_deletion_cron" class="ilCmiXapiDelCron" />
</crons>
<copage />
<web_access_checker />
<logging />
Expand Down

0 comments on commit 3bad331

Please sign in to comment.