From b7c4f6dddc0d29b40c57f5c96b2111096f6347e5 Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Wed, 11 Dec 2024 14:21:00 +0100 Subject: [PATCH 01/39] Component/Cron: init cron jobs via SetupAgent and Component's seek --- .../ILIAS/Authentication/Authentication.php | 6 + ...class.ilAuthDestroyExpiredSessionsCron.php | 12 +- ....ilComponentDefinitionsStoredObjective.php | 2 + components/ILIAS/Cron/Cron.php | 5 +- .../Setup/class.ilCronDefinitionProcessor.php | 1 + .../Setup/class.ilCronJobSetupAgent.php | 71 +++++++++++ ...ss.ilCronJobsMetricsCollectedObjective.php | 112 +++++++++++++++++ .../class.ilCronJobsRegisteredObjective.php | 117 ++++++++++++++++++ .../ILIAS/Cron/classes/class.ilCronJob.php | 14 ++- .../classes/class.ilCronJobRepositoryImpl.php | 14 ++- .../Cron/interfaces/interface.CronJob.php | 32 +++++ .../Init/classes/class.ilInitialisation.php | 3 +- 12 files changed, 377 insertions(+), 12 deletions(-) create mode 100644 components/ILIAS/Cron/classes/Setup/class.ilCronJobSetupAgent.php create mode 100644 components/ILIAS/Cron/classes/Setup/class.ilCronJobsMetricsCollectedObjective.php create mode 100644 components/ILIAS/Cron/classes/Setup/class.ilCronJobsRegisteredObjective.php create mode 100644 components/ILIAS/Cron/interfaces/interface.CronJob.php diff --git a/components/ILIAS/Authentication/Authentication.php b/components/ILIAS/Authentication/Authentication.php index 8390519017fc..af321f161a56 100644 --- a/components/ILIAS/Authentication/Authentication.php +++ b/components/ILIAS/Authentication/Authentication.php @@ -67,5 +67,11 @@ public function offsetUnset(mixed $offset): void new Component\Resource\Endpoint($this, "sessioncheck.php"); $contribute[Component\Resource\PublicAsset::class] = fn() => new Component\Resource\ComponentJS($this, "session_reminder.js"); + + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \ilAuthDestroyExpiredSessionsCron( + 'components\\' . self::class, + $use[\ILIAS\Language\Language::class] + ); } } diff --git a/components/ILIAS/Authentication/classes/Cron/class.ilAuthDestroyExpiredSessionsCron.php b/components/ILIAS/Authentication/classes/Cron/class.ilAuthDestroyExpiredSessionsCron.php index 2b9c6135b7d2..df64fe87bdf9 100755 --- a/components/ILIAS/Authentication/classes/Cron/class.ilAuthDestroyExpiredSessionsCron.php +++ b/components/ILIAS/Authentication/classes/Cron/class.ilAuthDestroyExpiredSessionsCron.php @@ -20,13 +20,11 @@ class ilAuthDestroyExpiredSessionsCron extends ilCronJob { - protected ilLanguage $lng; - - public function __construct() - { - global $DIC; - - $this->lng = $DIC->language(); + public function __construct( + string $component, + \ILIAS\Language\Language $lng, + ) { + parent::__construct($component, $lng); $this->lng->loadLanguageModule('auth'); } diff --git a/components/ILIAS/Component/classes/Setup/class.ilComponentDefinitionsStoredObjective.php b/components/ILIAS/Component/classes/Setup/class.ilComponentDefinitionsStoredObjective.php index 88638d83065d..72210a2486ef 100755 --- a/components/ILIAS/Component/classes/Setup/class.ilComponentDefinitionsStoredObjective.php +++ b/components/ILIAS/Component/classes/Setup/class.ilComponentDefinitionsStoredObjective.php @@ -143,12 +143,14 @@ public function write(): void new \ilCOPageDefinitionProcessor($db), new \ilComponentInfoDefinitionProcessor(), new \ilLoggingDefinitionProcessor($db), + /* new \ilCronDefinitionProcessor( $db, $settings_factory->settingsFor(), $component_repository, $component_factory ), + */ new \ilMailTemplateContextDefinitionProcessor($db), new \ilObjectDefinitionProcessor($db), new \ilSystemCheckDefinitionProcessor($db), diff --git a/components/ILIAS/Cron/Cron.php b/components/ILIAS/Cron/Cron.php index 8c77b9fcf587..b13e9efc8b19 100644 --- a/components/ILIAS/Cron/Cron.php +++ b/components/ILIAS/Cron/Cron.php @@ -32,6 +32,9 @@ public function init( array | \ArrayAccess &$pull, array | \ArrayAccess &$internal, ): void { - // ... + $contribute[\ILIAS\Setup\Agent::class] = static fn() => + new \ilCronJobSetupAgent( + $seek[\ILIAS\Cron\CronJob::class] + ); } } diff --git a/components/ILIAS/Cron/classes/Setup/class.ilCronDefinitionProcessor.php b/components/ILIAS/Cron/classes/Setup/class.ilCronDefinitionProcessor.php index 879d8203e116..3d091c77bb94 100755 --- a/components/ILIAS/Cron/classes/Setup/class.ilCronDefinitionProcessor.php +++ b/components/ILIAS/Cron/classes/Setup/class.ilCronDefinitionProcessor.php @@ -34,6 +34,7 @@ public function __construct( ilComponentFactory $componentFactory ) { $this->has_cron = []; + //throw new Exception("CRON JOB DEFINITION", 1); $this->cronRepository = new ilCronJobRepositoryImpl( $this->db, diff --git a/components/ILIAS/Cron/classes/Setup/class.ilCronJobSetupAgent.php b/components/ILIAS/Cron/classes/Setup/class.ilCronJobSetupAgent.php new file mode 100644 index 000000000000..517348e5f43e --- /dev/null +++ b/components/ILIAS/Cron/classes/Setup/class.ilCronJobSetupAgent.php @@ -0,0 +1,71 @@ +cronjobs + ); + } + + public function getUpdateObjective(Setup\Config $config = null): Setup\Objective + { + return new ilCronjobsRegisteredObjective( + $this->cronjobs + ); + } + + public function getBuildObjective(): Setup\Objective + { + return new Setup\Objective\NullObjective(); + } + + public function getStatusObjective(Setup\Metrics\Storage $storage): Setup\Objective + { + return new ilCronJobsMetricsCollectedObjective($storage); + } + + public function getMigrations(): array + { + return []; + } +} diff --git a/components/ILIAS/Cron/classes/Setup/class.ilCronJobsMetricsCollectedObjective.php b/components/ILIAS/Cron/classes/Setup/class.ilCronJobsMetricsCollectedObjective.php new file mode 100644 index 000000000000..31a2d776640a --- /dev/null +++ b/components/ILIAS/Cron/classes/Setup/class.ilCronJobsMetricsCollectedObjective.php @@ -0,0 +1,112 @@ +getResource(Setup\Environment::RESOURCE_DATABASE); + $component_repository = $environment->getResource(Setup\Environment::RESOURCE_COMPONENT_REPOSITORY); + $component_factory = $environment->getResource(Setup\Environment::RESOURCE_COMPONENT_FACTORY); + $settings_factory = $environment->getResource(Setup\Environment::RESOURCE_SETTINGS_FACTORY); + + $mock_lng = new class () implements \ILIAS\Language\Language { + public function txt(string $a_topic, string $a_default_lang_fallback_mod = ""): string + { + return ''; + } + public function loadLanguageModule(string $a_module): void + { + } + }; + + $repo = new ilCronJobRepositoryImpl( + $db, + $settings_factory->settingsFor(), + new ILIAS\components\Logging\NullLogger(), + $component_repository, + $component_factory, + $mock_lng + ); + + //@var ilCronJobEntity[] + $collection = $repo->findAll()->toArray(); + $cron_jobs = []; + foreach ($collection as $entity) { + $active = new Setup\Metrics\Metric( + Setup\Metrics\Metric::STABILITY_VOLATILE, + Setup\Metrics\Metric::TYPE_BOOL, + (bool) $entity->getJobStatus(), + "Is the job active?" + ); + $component = new Setup\Metrics\Metric( + Setup\Metrics\Metric::STABILITY_STABLE, + Setup\Metrics\Metric::TYPE_TEXT, + $entity->getComponent() + ); + $cron_jobs[$entity->getJobId()] = new Setup\Metrics\Metric( + Setup\Metrics\Metric::STABILITY_MIXED, + Setup\Metrics\Metric::TYPE_COLLECTION, + [ + "component" => $component, + "active" => $active + ] + ); + } + $cron_jobs = new Setup\Metrics\Metric( + Setup\Metrics\Metric::STABILITY_MIXED, + Setup\Metrics\Metric::TYPE_COLLECTION, + $cron_jobs + ); + + $cron_jobs_count = new Setup\Metrics\Metric( + Setup\Metrics\Metric::STABILITY_STABLE, + Setup\Metrics\Metric::TYPE_GAUGE, + count($collection) + ); + $storage->store( + "number of cron jobs", + $cron_jobs_count + ); + $storage->store( + "cron jobs", + $cron_jobs + ); + } +} diff --git a/components/ILIAS/Cron/classes/Setup/class.ilCronJobsRegisteredObjective.php b/components/ILIAS/Cron/classes/Setup/class.ilCronJobsRegisteredObjective.php new file mode 100644 index 000000000000..a42aa88a450d --- /dev/null +++ b/components/ILIAS/Cron/classes/Setup/class.ilCronJobsRegisteredObjective.php @@ -0,0 +1,117 @@ +getResource(Setup\Environment::RESOURCE_DATABASE); + /** @var ilComponentRepository $component_repository */ + $component_repository = $environment->getResource(Setup\Environment::RESOURCE_COMPONENT_REPOSITORY); + /** @var ilComponentFactory $component_factory */ + $component_factory = $environment->getResource(Setup\Environment::RESOURCE_COMPONENT_FACTORY); + /** @var ilSettingsFactory $settings_factory */ + $settings_factory = $environment->getResource(Setup\Environment::RESOURCE_SETTINGS_FACTORY); + + $mock_lng = new class () implements \ILIAS\Language\Language { + public function txt(string $a_topic, string $a_default_lang_fallback_mod = ""): string + { + return ''; + } + public function loadLanguageModule(string $a_module): void + { + } + }; + + $repo = new ilCronJobRepositoryImpl( + $db, + $settings_factory->settingsFor(), + new ILIAS\components\Logging\NullLogger(), + $component_repository, + $component_factory, + $mock_lng + ); + + $repo->unregisterAllJobs(); + + foreach ($this->cronjobs as $class => $job) { + $repo->registerJob( + $job->getComponent(), + $job->getId(), + get_class($job), + null //path! + ); + } + + return $environment; + } + + /** + * @inheritdoc + */ + public function isApplicable(Setup\Environment $environment): bool + { + return true; + } +} diff --git a/components/ILIAS/Cron/classes/class.ilCronJob.php b/components/ILIAS/Cron/classes/class.ilCronJob.php index c1881e23e968..0409d8ae1382 100755 --- a/components/ILIAS/Cron/classes/class.ilCronJob.php +++ b/components/ILIAS/Cron/classes/class.ilCronJob.php @@ -19,13 +19,25 @@ declare(strict_types=1); use ILIAS\Cron\Schedule\CronJobScheduleType; +use ILIAS\Cron\CronJob; -abstract class ilCronJob +abstract class ilCronJob implements CronJob { protected ?CronJobScheduleType $schedule_type = null; protected ?int $schedule_value = null; protected ?Closure $date_time_provider = null; + public function __construct( + protected readonly string $component, + protected readonly \ILIAS\Language\Language $lng, + ) { + } + + public function getComponent(): string + { + return $this->component; + } + private function checkWeeklySchedule(DateTimeImmutable $last_run, DateTimeImmutable $now): bool { $last_year = (int) $last_run->format('Y'); diff --git a/components/ILIAS/Cron/classes/class.ilCronJobRepositoryImpl.php b/components/ILIAS/Cron/classes/class.ilCronJobRepositoryImpl.php index 6fd98b96af1a..d10ff81ceda3 100755 --- a/components/ILIAS/Cron/classes/class.ilCronJobRepositoryImpl.php +++ b/components/ILIAS/Cron/classes/class.ilCronJobRepositoryImpl.php @@ -29,7 +29,8 @@ public function __construct( private readonly ilSetting $setting, private readonly ilLogger $logger, private readonly ilComponentRepository $componentRepository, - private readonly ilComponentFactory $componentFactory + private readonly ilComponentFactory $componentFactory, + private readonly ILIAS\Language\Language $lng ) { } @@ -94,7 +95,10 @@ public function getJobInstance( $refl = new ReflectionClass($a_class); $job = $refl->newInstanceWithoutConstructor(); } else { - $job = new $a_class(); + $job = new $a_class( + $a_component, + $this->lng + ); } if ($job instanceof ilCronJob && $job->getId() === $a_id) { @@ -153,6 +157,12 @@ public function registerJob( } } + public function unregisterAllJobs(): void + { + $query = 'TRUNCATE cron_job;'; + $res = $this->db->manipulate($query); + } + public function unregisterJob(string $a_component, array $a_xml_job_ids): void { if (!$this->db->tableExists('cron_job')) { diff --git a/components/ILIAS/Cron/interfaces/interface.CronJob.php b/components/ILIAS/Cron/interfaces/interface.CronJob.php new file mode 100644 index 000000000000..16cc54f7d082 --- /dev/null +++ b/components/ILIAS/Cron/interfaces/interface.CronJob.php @@ -0,0 +1,32 @@ +settings(), $c->logger()->cron(), $c['component.repository'], - $c['component.factory'] + $c['component.factory'], + $c['lng'] ); }; From a84b7957cd50f0bf1084823ff7c5c713d989aead Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Fri, 13 Dec 2024 15:21:52 +0100 Subject: [PATCH 02/39] Component/Cron: remove ilCronDefinitionProcessor --- cli/hello_world.php | 2 +- components/ILIAS/Authentication/service.xml | 3 - ....ilComponentDefinitionsStoredObjective.php | 8 -- .../Setup/class.ilCronDefinitionProcessor.php | 93 ------------------- 4 files changed, 1 insertion(+), 105 deletions(-) delete mode 100755 components/ILIAS/Cron/classes/Setup/class.ilCronDefinitionProcessor.php diff --git a/cli/hello_world.php b/cli/hello_world.php index 6dfa4b3b403d..dc3c32f710c9 100644 --- a/cli/hello_world.php +++ b/cli/hello_world.php @@ -16,7 +16,7 @@ * *********************************************************************/ -require_once(__DIR__ . "/../artifacts/bootstrap.php"); +require_once(__DIR__ . "/../artifacts/bootstrap_setup.php"); // This calls a simple entrypoint, for testing and documentation purpose. This // should just print a simple hello and will work when bootstrapping works. diff --git a/components/ILIAS/Authentication/service.xml b/components/ILIAS/Authentication/service.xml index ab8ba0262925..78b703afe9b3 100755 --- a/components/ILIAS/Authentication/service.xml +++ b/components/ILIAS/Authentication/service.xml @@ -23,7 +23,4 @@ - - - diff --git a/components/ILIAS/Component/classes/Setup/class.ilComponentDefinitionsStoredObjective.php b/components/ILIAS/Component/classes/Setup/class.ilComponentDefinitionsStoredObjective.php index 72210a2486ef..d42bd09b292a 100755 --- a/components/ILIAS/Component/classes/Setup/class.ilComponentDefinitionsStoredObjective.php +++ b/components/ILIAS/Component/classes/Setup/class.ilComponentDefinitionsStoredObjective.php @@ -143,14 +143,6 @@ public function write(): void new \ilCOPageDefinitionProcessor($db), new \ilComponentInfoDefinitionProcessor(), new \ilLoggingDefinitionProcessor($db), - /* - new \ilCronDefinitionProcessor( - $db, - $settings_factory->settingsFor(), - $component_repository, - $component_factory - ), - */ new \ilMailTemplateContextDefinitionProcessor($db), new \ilObjectDefinitionProcessor($db), new \ilSystemCheckDefinitionProcessor($db), diff --git a/components/ILIAS/Cron/classes/Setup/class.ilCronDefinitionProcessor.php b/components/ILIAS/Cron/classes/Setup/class.ilCronDefinitionProcessor.php deleted file mode 100755 index 3d091c77bb94..000000000000 --- a/components/ILIAS/Cron/classes/Setup/class.ilCronDefinitionProcessor.php +++ /dev/null @@ -1,93 +0,0 @@ -has_cron = []; - //throw new Exception("CRON JOB DEFINITION", 1); - - $this->cronRepository = new ilCronJobRepositoryImpl( - $this->db, - $setting, - new NullLogger(), - $componentRepository, - $componentFactory - ); - } - - public function purge(): void - { - } - - public function beginComponent(string $component, string $type): void - { - $this->component = $type . "/" . $component; - $this->has_cron = []; - } - - public function endComponent(string $component, string $type): void - { - $this->component = null; - $this->has_cron = []; - } - - public function beginTag(string $name, array $attributes): void - { - if ($name !== "cron") { - return; - } - - $component = $attributes["component"] ?? null; - if (!$component) { - $component = $this->component; - } - - $this->cronRepository->registerJob( - $component, - $attributes["id"], - $attributes["class"], - ($attributes["path"] ?? null) - ); - - $this->has_cron[] = $attributes["id"]; - } - - public function endTag(string $name): void - { - if ($name !== "module" && $name !== "service") { - return; - } - - $this->cronRepository->unregisterJob($this->component, $this->has_cron); - } -} From 3a3bd3e5e79e8fd471a843893721e1b48630caca Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Mon, 16 Dec 2024 08:33:50 +0100 Subject: [PATCH 03/39] Component/User: contribute cron jobs --- components/ILIAS/User/User.php | 26 ++++++++++++++++++- ...ss.ilCronDeleteInactivatedUserAccounts.php | 9 +++---- ...class.ilCronDeleteInactiveUserAccounts.php | 16 ++++-------- ....ilCronDeleteNeverLoggedInUserAccounts.php | 10 +++---- .../Cron/class.ilUserCronCheckAccounts.php | 14 +++------- components/ILIAS/User/service.xml | 6 ----- 6 files changed, 40 insertions(+), 41 deletions(-) diff --git a/components/ILIAS/User/User.php b/components/ILIAS/User/User.php index b1ea29a8da1d..f4e8450f234f 100644 --- a/components/ILIAS/User/User.php +++ b/components/ILIAS/User/User.php @@ -21,7 +21,6 @@ namespace ILIAS; use ILIAS\User\Setup\Agent; - use ILIAS\Setup\Agent as SetupAgent; use ILIAS\Refinery\Factory as Refinery; @@ -41,5 +40,30 @@ public function init( new Agent( $pull[Refinery::class] ); + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \ilCronDeleteInactiveUserAccounts( + self::class, + $use[\ILIAS\Language\Language::class], + $use[\ILIAS\Logging\LoggerFactory::class] + ); + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \ilCronDeleteInactivatedUserAccounts( + self::class, + $use[\ILIAS\Language\Language::class], + $use[\ILIAS\Logging\LoggerFactory::class] + ); + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \ilUserCronCheckAccounts( + self::class, + $use[\ILIAS\Language\Language::class], + $use[\ILIAS\Logging\LoggerFactory::class] + ); + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \ilCronDeleteNeverLoggedInUserAccounts( + self::class, + $use[\ILIAS\Language\Language::class], + $use[\ILIAS\Logging\LoggerFactory::class] + ); + } } diff --git a/components/ILIAS/User/classes/Cron/class.ilCronDeleteInactivatedUserAccounts.php b/components/ILIAS/User/classes/Cron/class.ilCronDeleteInactivatedUserAccounts.php index 8547b0f0846c..7af9792f210b 100755 --- a/components/ILIAS/User/classes/Cron/class.ilCronDeleteInactivatedUserAccounts.php +++ b/components/ILIAS/User/classes/Cron/class.ilCronDeleteInactivatedUserAccounts.php @@ -33,14 +33,15 @@ class ilCronDeleteInactivatedUserAccounts extends ilCronJob /** @var int[] */ private array $include_roles; private ilSetting $settings; - private Language $lng; private ilRbacReview $rbac_review; private ilObjectDataCache $objectDataCache; private \ILIAS\HTTP\GlobalHttpState $http; private \ILIAS\Refinery\Factory $refinery; - public function __construct() + public function init(): void { + $this->lng->loadLanguageModule('usr'); + /** @var ILIAS\DI\Container $DIC */ global $DIC; @@ -48,10 +49,6 @@ public function __construct() $this->http = $DIC['http']; } - if (isset($DIC['lng'])) { - $this->lng = $DIC['lng']; - } - if (isset($DIC['refinery'])) { $this->refinery = $DIC['refinery']; } diff --git a/components/ILIAS/User/classes/Cron/class.ilCronDeleteInactiveUserAccounts.php b/components/ILIAS/User/classes/Cron/class.ilCronDeleteInactiveUserAccounts.php index 4a2ce608ea4e..22a4bddf6906 100755 --- a/components/ILIAS/User/classes/Cron/class.ilCronDeleteInactiveUserAccounts.php +++ b/components/ILIAS/User/classes/Cron/class.ilCronDeleteInactiveUserAccounts.php @@ -42,7 +42,6 @@ class ilCronDeleteInactiveUserAccounts extends ilCronJob private array $include_roles; private ilCronDeleteInactiveUserReminderMail $cron_delete_reminder_mail; private ilSetting $settings; - private Language $lng; private ilComponentLogger $log; private ilRbacReview $rbac_review; private ilObjectDataCache $objectDataCache; @@ -51,8 +50,11 @@ class ilCronDeleteInactiveUserAccounts extends ilCronJob private ilCronJobRepository $cronRepository; private \ilGlobalTemplateInterface $main_tpl; - public function __construct() + public function init(): void { + $this->lng->loadLanguageModule('usr'); + $this->log = $this->logger_factory->getRootLogger(); + /** @var ILIAS\DI\Container $DIC */ global $DIC; @@ -67,14 +69,6 @@ public function __construct() $this->http = $DIC['http']; } - if (isset($DIC['lng'])) { - $this->lng = $DIC['lng']; - } - - if (isset($DIC['ilLog'])) { - $this->log = $DIC['ilLog']; - } - if (isset($DIC['refinery'])) { $this->refinery = $DIC['refinery']; } @@ -259,7 +253,7 @@ private function deleteUserOrSendReminderMail($usr_id): int if ($this->reminder_period > 0) { $timestamp_for_deletion = $timestamp_last_login - $grace_period_over; $account_will_be_deleted_on = $this->calculateDeletionData($timestamp_for_deletion); - if( + if ( $this->cron_delete_reminder_mail->sendReminderMailIfNeeded( $user, $this->reminder_period, diff --git a/components/ILIAS/User/classes/Cron/class.ilCronDeleteNeverLoggedInUserAccounts.php b/components/ILIAS/User/classes/Cron/class.ilCronDeleteNeverLoggedInUserAccounts.php index ef2abff39eb4..046aa79df89f 100755 --- a/components/ILIAS/User/classes/Cron/class.ilCronDeleteNeverLoggedInUserAccounts.php +++ b/components/ILIAS/User/classes/Cron/class.ilCronDeleteNeverLoggedInUserAccounts.php @@ -28,7 +28,6 @@ class ilCronDeleteNeverLoggedInUserAccounts extends \ilCronJob private string $roleIdWhiteliste = ''; private int $thresholdInDays = self::DEFAULT_CREATION_THRESHOLD; - private Language $lng; private ilSetting $settings; private ilRbacReview $rbacreview; private ilObjectDataCache $objectDataCache; @@ -36,8 +35,10 @@ class ilCronDeleteNeverLoggedInUserAccounts extends \ilCronJob private \ILIAS\Refinery\Factory $refinery; private \ilGlobalTemplateInterface $main_tpl; - public function __construct() + public function init(): void { + $this->lng->loadLanguageModule('usr'); + global $DIC; $this->main_tpl = $DIC->ui()->mainTemplate(); @@ -56,11 +57,6 @@ public function __construct() ); } - if (isset($DIC['lng'])) { - $this->lng = $DIC->language(); - $this->lng->loadLanguageModule('usr'); - } - if (isset($DIC['rbacreview'])) { $this->rbacreview = $DIC->rbac()->review(); } diff --git a/components/ILIAS/User/classes/Cron/class.ilUserCronCheckAccounts.php b/components/ILIAS/User/classes/Cron/class.ilUserCronCheckAccounts.php index 93e361a63280..48dc36cc9eb4 100755 --- a/components/ILIAS/User/classes/Cron/class.ilUserCronCheckAccounts.php +++ b/components/ILIAS/User/classes/Cron/class.ilUserCronCheckAccounts.php @@ -29,25 +29,19 @@ class ilUserCronCheckAccounts extends ilCronJob protected int $counter = 0; private ilDBInterface $db; - private ilLanguage $lng; private ilComponentLogger $log; - public function __construct() + public function init(): void { + $this->lng->loadLanguageModule('usr'); + $this->log = $this->logger_factory->getRootLogger(); + /** @var ILIAS\DI\Container $DIC */ global $DIC; if (isset($DIC['ilDB'])) { $this->db = $DIC['ilDB']; } - - if (isset($DIC['lng'])) { - $this->lng = $DIC['lng']; - } - - if (isset($DIC['ilDB'])) { - $this->log = $DIC['ilLog']; - } } public function getId(): string diff --git a/components/ILIAS/User/service.xml b/components/ILIAS/User/service.xml index 92221d63de87..fecf8a1fcc1f 100755 --- a/components/ILIAS/User/service.xml +++ b/components/ILIAS/User/service.xml @@ -22,12 +22,6 @@ - - - - - - From 44de060b61bf5bb98e61b0b2c494cd94a738521e Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Thu, 2 Jan 2025 14:12:03 +0100 Subject: [PATCH 04/39] Component/Authentication: contribute cron --- components/ILIAS/Authentication/Authentication.php | 5 +++-- .../Cron/class.ilAuthDestroyExpiredSessionsCron.php | 7 ++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/components/ILIAS/Authentication/Authentication.php b/components/ILIAS/Authentication/Authentication.php index af321f161a56..b9f703c4fb7a 100644 --- a/components/ILIAS/Authentication/Authentication.php +++ b/components/ILIAS/Authentication/Authentication.php @@ -70,8 +70,9 @@ public function offsetUnset(mixed $offset): void $contribute[\ILIAS\Cron\CronJob::class] = static fn() => new \ilAuthDestroyExpiredSessionsCron( - 'components\\' . self::class, - $use[\ILIAS\Language\Language::class] + self::class, + $use[\ILIAS\Language\Language::class], + $use[\ILIAS\Logging\LoggerFactory::class] ); } } diff --git a/components/ILIAS/Authentication/classes/Cron/class.ilAuthDestroyExpiredSessionsCron.php b/components/ILIAS/Authentication/classes/Cron/class.ilAuthDestroyExpiredSessionsCron.php index df64fe87bdf9..9132c25a4a38 100755 --- a/components/ILIAS/Authentication/classes/Cron/class.ilAuthDestroyExpiredSessionsCron.php +++ b/components/ILIAS/Authentication/classes/Cron/class.ilAuthDestroyExpiredSessionsCron.php @@ -20,11 +20,8 @@ class ilAuthDestroyExpiredSessionsCron extends ilCronJob { - public function __construct( - string $component, - \ILIAS\Language\Language $lng, - ) { - parent::__construct($component, $lng); + public function init(): void + { $this->lng->loadLanguageModule('auth'); } From 3cce6370622bd7286640e96de4d8e82a1827e127 Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Mon, 16 Dec 2024 08:34:58 +0100 Subject: [PATCH 05/39] Component/BookingManager: contribute cron jobs --- .../ILIAS/BookingManager/BookingManager.php | 13 +++++++++++++ .../classes/class.ilBookCronNotification.php | 19 ++++++------------- .../classes/class.ilBookingPrefBookCron.php | 8 ++------ components/ILIAS/BookingManager/module.xml | 4 ---- 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/components/ILIAS/BookingManager/BookingManager.php b/components/ILIAS/BookingManager/BookingManager.php index f49fde78f512..aee12e570ebd 100644 --- a/components/ILIAS/BookingManager/BookingManager.php +++ b/components/ILIAS/BookingManager/BookingManager.php @@ -39,5 +39,18 @@ public function init( $contribute[Component\Resource\PublicAsset::class] = fn() => new Component\Resource\ComponentJS($this, "ScheduleInput.js"); + + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \ilBookCronNotification( + self::class, + $use[\ILIAS\Language\Language::class], + $use[\ILIAS\Logging\LoggerFactory::class] + ); + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \ilBookingPrefBookCron( + self::class, + $use[\ILIAS\Language\Language::class], + $use[\ILIAS\Logging\LoggerFactory::class] + ); } } diff --git a/components/ILIAS/BookingManager/classes/class.ilBookCronNotification.php b/components/ILIAS/BookingManager/classes/class.ilBookCronNotification.php index cb8f479f8e2e..15686f1bba37 100755 --- a/components/ILIAS/BookingManager/classes/class.ilBookCronNotification.php +++ b/components/ILIAS/BookingManager/classes/class.ilBookCronNotification.php @@ -25,15 +25,14 @@ class ilBookCronNotification extends ilCronJob { protected \ILIAS\BookingManager\InternalRepoService $repo; - protected ilLanguage $lng; protected ilLogger $book_log; - public function __construct() + public function init(): void { - global $DIC; - - $this->lng = $DIC->language(); + $this->lng->loadLanguageModule('dateplaner'); + $this->lng->loadLanguageModule('book'); + global $DIC; $this->book_log = ilLoggerFactory::getLogger("book"); $this->repo = $DIC->bookingManager() ->internal() @@ -47,18 +46,12 @@ public function getId(): string public function getTitle(): string { - $lng = $this->lng; - - $lng->loadLanguageModule("book"); - return $lng->txt("book_notification"); + return $this->lng->txt("book_notification"); } public function getDescription(): string { - $lng = $this->lng; - - $lng->loadLanguageModule("book"); - return $lng->txt("book_notification_info"); + return $this->lng->txt("book_notification_info"); } public function getDefaultScheduleType(): CronJobScheduleType diff --git a/components/ILIAS/BookingManager/classes/class.ilBookingPrefBookCron.php b/components/ILIAS/BookingManager/classes/class.ilBookingPrefBookCron.php index eaa67ecf2c99..778ed05a98b1 100755 --- a/components/ILIAS/BookingManager/classes/class.ilBookingPrefBookCron.php +++ b/components/ILIAS/BookingManager/classes/class.ilBookingPrefBookCron.php @@ -26,13 +26,9 @@ */ class ilBookingPrefBookCron extends ilCronJob { - protected ilLanguage $lng; - - public function __construct() + public function init(): void { - global $DIC; - - $this->lng = $DIC->language(); + $this->lng->loadLanguageModule('book'); } public function getId(): string diff --git a/components/ILIAS/BookingManager/module.xml b/components/ILIAS/BookingManager/module.xml index a5f775ba7db2..41226d366bc1 100755 --- a/components/ILIAS/BookingManager/module.xml +++ b/components/ILIAS/BookingManager/module.xml @@ -21,9 +21,5 @@ - - - - From b173916b6f13fe69d19d77073f9b6550da768eaa Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Mon, 16 Dec 2024 08:35:20 +0100 Subject: [PATCH 06/39] Component/Certificate: contribute cron jobs --- components/ILIAS/Certificate/Certificate.php | 7 +++ .../classes/class.ilCertificateCron.php | 22 +++---- components/ILIAS/Certificate/service.xml | 3 - .../tests/ilCertificateCronTest.php | 60 ++++++++++++++++--- 4 files changed, 65 insertions(+), 27 deletions(-) diff --git a/components/ILIAS/Certificate/Certificate.php b/components/ILIAS/Certificate/Certificate.php index 952bd54700c7..1feff4b6f99c 100644 --- a/components/ILIAS/Certificate/Certificate.php +++ b/components/ILIAS/Certificate/Certificate.php @@ -36,5 +36,12 @@ public function init( new \ilCertificatSetupAgent( $pull[\ILIAS\Refinery\Factory::class] ); + + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \ilCertificateCron( + 'components\\' . self::class, + $use[\ILIAS\Language\Language::class], + $use[\ILIAS\Logging\LoggerFactory::class] + ); } } diff --git a/components/ILIAS/Certificate/classes/class.ilCertificateCron.php b/components/ILIAS/Certificate/classes/class.ilCertificateCron.php index b748b7d65815..427fa3046332 100755 --- a/components/ILIAS/Certificate/classes/class.ilCertificateCron.php +++ b/components/ILIAS/Certificate/classes/class.ilCertificateCron.php @@ -26,33 +26,23 @@ */ class ilCertificateCron extends ilCronJob { - protected ?ilLanguage $lng; - private ?Container $dic; + private ?Container $dic = null; public function __construct( + string $component, + \ILIAS\Language\Language $lng, + \ILIAS\Logging\LoggerFactory $logger_factory, private ?ilCertificateQueueRepository $queueRepository = null, private ?ilCertificateTemplateRepository $templateRepository = null, private ?ilUserCertificateRepository $userRepository = null, private ?ilCertificateValueReplacement $valueReplacement = null, private ?ilLogger $logger = null, ?Container $dic = null, - ?ilLanguage $language = null, private ?ilCertificateObjectHelper $objectHelper = null, private ?ilSetting $settings = null, private ?ilCronManager $cronManager = null, ) { - if (null === $dic) { - global $DIC; - $dic = $DIC; - } - $this->dic = $dic; - - if ($dic && isset($dic['lng'])) { - $language = $dic->language(); - $language->loadLanguageModule('certificate'); - } - - $this->lng = $language; + parent::__construct($component, $lng, $logger_factory); } public function getTitle(): string @@ -67,6 +57,8 @@ public function getDescription(): string public function init(): void { + $this->lng->loadLanguageModule('certificate'); + if (null === $this->dic) { global $DIC; $this->dic = $DIC; diff --git a/components/ILIAS/Certificate/service.xml b/components/ILIAS/Certificate/service.xml index 430437ec71d9..7f7b5c2dfebd 100755 --- a/components/ILIAS/Certificate/service.xml +++ b/components/ILIAS/Certificate/service.xml @@ -14,8 +14,5 @@ - - - diff --git a/components/ILIAS/Certificate/tests/ilCertificateCronTest.php b/components/ILIAS/Certificate/tests/ilCertificateCronTest.php index 1d538ee0df50..06e27c5b6fa6 100755 --- a/components/ILIAS/Certificate/tests/ilCertificateCronTest.php +++ b/components/ILIAS/Certificate/tests/ilCertificateCronTest.php @@ -19,6 +19,7 @@ declare(strict_types=1); use ILIAS\Cron\Schedule\CronJobScheduleType; +use ILIAS\Logging\LoggerFactory; /** * @author Niels Theen @@ -71,14 +72,20 @@ public function testGetTitle(): void $dic['lng'] = $languageMock; + $logger_factory = $this->getMockBuilder(LoggerFactory::class) + ->disableOriginalConstructor() + ->getMock(); + $cron = new ilCertificateCron( + 'components\ILIAS\Certificate', + $languageMock, + $logger_factory, $queueRepository, $templateRepository, $userRepository, $valueReplacement, $logger, - $dic, - $languageMock + $dic ); $title = $cron->getTitle(); @@ -132,14 +139,20 @@ public function testGetDescription(): void $dic['lng'] = $languageMock; + $logger_factory = $this->getMockBuilder(LoggerFactory::class) + ->disableOriginalConstructor() + ->getMock(); + $cron = new ilCertificateCron( + 'components\ILIAS\Certificate', + $languageMock, + $logger_factory, $queueRepository, $templateRepository, $userRepository, $valueReplacement, $logger, - $dic, - $languageMock + $dic ); $title = $cron->getDescription(); @@ -211,14 +224,20 @@ public function testGetId(): void $userMock ); + $logger_factory = $this->getMockBuilder(LoggerFactory::class) + ->disableOriginalConstructor() + ->getMock(); + $cron = new ilCertificateCron( + 'components\ILIAS\Certificate', + $languageMock, + $logger_factory, $queueRepository, $templateRepository, $userRepository, $valueReplacement, $logger, $dic, - $languageMock, $objectHelper ); @@ -292,15 +311,20 @@ public function testActivation(): void $objectMock, $userMock ); + $logger_factory = $this->getMockBuilder(LoggerFactory::class) + ->disableOriginalConstructor() + ->getMock(); $cron = new ilCertificateCron( + 'components\ILIAS\Certificate', + $languageMock, + $logger_factory, $queueRepository, $templateRepository, $userRepository, $valueReplacement, $logger, $dic, - $languageMock, $objectHelper ); @@ -375,14 +399,20 @@ public function testFlexibleActivation(): void $userMock ); + $logger_factory = $this->getMockBuilder(LoggerFactory::class) + ->disableOriginalConstructor() + ->getMock(); + $cron = new ilCertificateCron( + 'components\ILIAS\Certificate', + $languageMock, + $logger_factory, $queueRepository, $templateRepository, $userRepository, $valueReplacement, $logger, $dic, - $languageMock, $objectHelper ); @@ -457,14 +487,20 @@ public function testGetDefaultScheduleType(): void $userMock ); + $logger_factory = $this->getMockBuilder(LoggerFactory::class) + ->disableOriginalConstructor() + ->getMock(); + $cron = new ilCertificateCron( + 'components\ILIAS\Certificate', + $languageMock, + $logger_factory, $queueRepository, $templateRepository, $userRepository, $valueReplacement, $logger, $dic, - $languageMock, $objectHelper ); @@ -539,14 +575,20 @@ public function testGetDefaultScheduleValue(): void $userMock ); + $logger_factory = $this->getMockBuilder(LoggerFactory::class) + ->disableOriginalConstructor() + ->getMock(); + $cron = new ilCertificateCron( + 'components\ILIAS\Certificate', + $languageMock, + $logger_factory, $queueRepository, $templateRepository, $userRepository, $valueReplacement, $logger, $dic, - $languageMock, $objectHelper ); From 60c20b710a5e24ce8ebc363a48889f5e91b1d805 Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Mon, 16 Dec 2024 08:35:59 +0100 Subject: [PATCH 07/39] Component/COPage: contribute cron jobs --- components/ILIAS/COPage/COPage.php | 7 ++++++- .../Cron/class.ilCleanCOPageHistoryCronjob.php | 17 +++++------------ components/ILIAS/COPage/service.xml | 3 --- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/components/ILIAS/COPage/COPage.php b/components/ILIAS/COPage/COPage.php index 650460610472..b0d1040f2fb9 100644 --- a/components/ILIAS/COPage/COPage.php +++ b/components/ILIAS/COPage/COPage.php @@ -110,6 +110,11 @@ public function getTarget(): string return "assets/js/ilIntLink.js"; } }; - + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \ilCleanCOPageHistoryCronjob( + self::class, + $use[\ILIAS\Language\Language::class], + $use[\ILIAS\Logging\LoggerFactory::class] + ); } } diff --git a/components/ILIAS/COPage/Cron/class.ilCleanCOPageHistoryCronjob.php b/components/ILIAS/COPage/Cron/class.ilCleanCOPageHistoryCronjob.php index 67e34831b2db..7855ddfb55c2 100755 --- a/components/ILIAS/COPage/Cron/class.ilCleanCOPageHistoryCronjob.php +++ b/components/ILIAS/COPage/Cron/class.ilCleanCOPageHistoryCronjob.php @@ -28,13 +28,12 @@ class ilCleanCOPageHistoryCronjob extends ilCronJob { protected HistoryManager $history_manager; protected ilSetting $settings; - protected ilLanguage $lng; - public function __construct() + public function init(): void { - global $DIC; + $this->lng->loadLanguageModule("copg"); - $this->lng = $DIC->language(); + global $DIC; $this->settings = $DIC->settings(); $this->history_manager = $DIC ->copage() @@ -50,18 +49,12 @@ public function getId(): string public function getTitle(): string { - $lng = $this->lng; - - $lng->loadLanguageModule("copg"); - return $lng->txt("copg_history_cleanup_cron"); + return $this->lng->txt("copg_history_cleanup_cron"); } public function getDescription(): string { - $lng = $this->lng; - - $lng->loadLanguageModule("copg"); - return $lng->txt("copg_history_cleanup_cron_info"); + return $this->lng->txt("copg_history_cleanup_cron_info"); } public function getDefaultScheduleType(): CronJobScheduleType diff --git a/components/ILIAS/COPage/service.xml b/components/ILIAS/COPage/service.xml index 63036614d25c..865f5c4c2ba5 100755 --- a/components/ILIAS/COPage/service.xml +++ b/components/ILIAS/COPage/service.xml @@ -38,7 +38,4 @@ - - - From 2b80281e055b33533a0efef4a2e4eaec6f24ffcc Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Mon, 16 Dec 2024 08:36:35 +0100 Subject: [PATCH 08/39] Component/Calendar: contribute cron jobs --- components/ILIAS/Calendar/Calendar.php | 12 ++++++++++++ .../class.ilConsultationHourCron.php | 8 +++----- .../Cron/class.ilCalendarCronRemoteReader.php | 13 ++++--------- components/ILIAS/Calendar/service.xml | 4 ---- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/components/ILIAS/Calendar/Calendar.php b/components/ILIAS/Calendar/Calendar.php index 77c3b176c694..9f8423742576 100644 --- a/components/ILIAS/Calendar/Calendar.php +++ b/components/ILIAS/Calendar/Calendar.php @@ -51,5 +51,17 @@ public function init( $contribute[Component\Resource\PublicAsset::class] = fn() => new Component\Resource\NodeModule("eonasdan-bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js"); */ + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \ilCalendarCronRemoteReader( + self::class, + $use[\ILIAS\Language\Language::class], + $use[\ILIAS\Logging\LoggerFactory::class] + ); + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \ilConsultationHourCron( + self::class, + $use[\ILIAS\Language\Language::class], + $use[\ILIAS\Logging\LoggerFactory::class] + ); } } diff --git a/components/ILIAS/Calendar/classes/ConsultationHours/class.ilConsultationHourCron.php b/components/ILIAS/Calendar/classes/ConsultationHours/class.ilConsultationHourCron.php index e942060b69a4..ccb9edf8a583 100755 --- a/components/ILIAS/Calendar/classes/ConsultationHours/class.ilConsultationHourCron.php +++ b/components/ILIAS/Calendar/classes/ConsultationHours/class.ilConsultationHourCron.php @@ -26,16 +26,14 @@ */ class ilConsultationHourCron extends ilCronJob { - protected ilLanguage $lng; protected ilDBInterface $db; protected ilSetting $setting; - public function __construct() + public function init(): void { - global $DIC; - - $this->lng = $DIC->language(); $this->lng->loadLanguageModule('dateplaner'); + + global $DIC; $this->db = $DIC->database(); $this->setting = $DIC->settings(); } diff --git a/components/ILIAS/Calendar/classes/Cron/class.ilCalendarCronRemoteReader.php b/components/ILIAS/Calendar/classes/Cron/class.ilCalendarCronRemoteReader.php index 91ff6df4a77e..9f63e0c5245d 100755 --- a/components/ILIAS/Calendar/classes/Cron/class.ilCalendarCronRemoteReader.php +++ b/components/ILIAS/Calendar/classes/Cron/class.ilCalendarCronRemoteReader.php @@ -24,16 +24,13 @@ class ilCalendarCronRemoteReader extends ilCronJob { private const DEFAULT_SYNC_HOURS = 1; - private ilLanguage $lng; private ilLogger $logger; - private ?ilCalendarSettings $calendar_settings = null; - public function __construct() + public function init(): void { + $this->lng->loadLanguageModule('dateplaner'); global $DIC; - - $this->lng = $DIC->language(); $this->logger = $DIC->logger()->cal(); $this->calendar_settings = ilCalendarSettings::_getInstance(); } @@ -45,13 +42,11 @@ public function getId(): string public function getTitle(): string { - $this->lng->loadLanguageModule('dateplaner'); return $this->lng->txt('cal_cronjob_remote_title'); } public function getDescription(): string { - $this->lng->loadLanguageModule('dateplaner'); return $this->lng->txt('cal_cronjob_remote_description'); } @@ -106,8 +101,8 @@ public function run(): ilCronJobResult $reader->setUser($remoteCalendar->getRemoteUser()); $reader->setPass($remoteCalendar->getRemotePass()); try { - $reader->read(); - $reader->import($remoteCalendar); + $reader->read(); + $reader->import($remoteCalendar); } catch (Exception $e) { $this->logger->warning('Remote Calendar: ' . $remoteCalendar->getCategoryID()); $this->logger->warning('Reading remote calendar failed with message: ' . $e->getMessage()); diff --git a/components/ILIAS/Calendar/service.xml b/components/ILIAS/Calendar/service.xml index cdb7cda6246a..3bf74812cc04 100755 --- a/components/ILIAS/Calendar/service.xml +++ b/components/ILIAS/Calendar/service.xml @@ -16,10 +16,6 @@ - - - - From f5619129d83d4f58e1dbd86160a455021c1f99fa Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Mon, 16 Dec 2024 08:45:49 +0100 Subject: [PATCH 09/39] Component/WebServices: contribute cron jobs --- components/ILIAS/WebServices/WebServices.php | 8 ++++++ .../classes/class.ilCronEcsTaskScheduler.php | 25 +++++++++++++------ components/ILIAS/WebServices/service.xml | 3 --- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/components/ILIAS/WebServices/WebServices.php b/components/ILIAS/WebServices/WebServices.php index 6ae160704ecf..6a908208b846 100644 --- a/components/ILIAS/WebServices/WebServices.php +++ b/components/ILIAS/WebServices/WebServices.php @@ -41,5 +41,13 @@ public function init( new \ilECSAgent( $pull[\ILIAS\Refinery\Factory::class] ); + + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \ilCronEcsTaskScheduler( + self::class, + $use[\ILIAS\Language\Language::class], + $use[\ILIAS\Logging\LoggerFactory::class] + ); + } } diff --git a/components/ILIAS/WebServices/classes/class.ilCronEcsTaskScheduler.php b/components/ILIAS/WebServices/classes/class.ilCronEcsTaskScheduler.php index d5325edad04b..ac822661c332 100755 --- a/components/ILIAS/WebServices/classes/class.ilCronEcsTaskScheduler.php +++ b/components/ILIAS/WebServices/classes/class.ilCronEcsTaskScheduler.php @@ -1,6 +1,20 @@ logger = $DIC->logger()->wsrv(); - $this->lng = $DIC->language(); $this->lng->loadLanguageModule('ecs'); + global $DIC; + $this->logger = $DIC->logger()->wsrv(); $this->result = new \ilCronJobResult(); } diff --git a/components/ILIAS/WebServices/service.xml b/components/ILIAS/WebServices/service.xml index 6196f8e25a90..81ba86b9d9ec 100755 --- a/components/ILIAS/WebServices/service.xml +++ b/components/ILIAS/WebServices/service.xml @@ -15,9 +15,6 @@ - - - From 5068334ca08ef85c6dba32c00c52efcde0eaf3f3 Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Mon, 16 Dec 2024 09:14:51 +0100 Subject: [PATCH 10/39] Component/Test: contribute cron jobs --- components/ILIAS/Test/Test.php | 6 ++++ ...class.ilCronFinishUnfinishedTestPasses.php | 16 +++++----- components/ILIAS/Test/module.xml | 3 -- .../ilCronFinishUnfinishedTestPassesTest.php | 31 +++++++++++++++++-- 4 files changed, 41 insertions(+), 15 deletions(-) diff --git a/components/ILIAS/Test/Test.php b/components/ILIAS/Test/Test.php index 866a38de18b7..ea183ba0a0ef 100644 --- a/components/ILIAS/Test/Test.php +++ b/components/ILIAS/Test/Test.php @@ -48,5 +48,11 @@ public function init( new Component\Resource\ComponentCSS($this, "test_print.css"); $contribute[Component\Resource\PublicAsset::class] = fn() => new Component\Resource\ComponentCSS($this, "test_print_hide_content.css"); + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \ilCronFinishUnfinishedTestPasses( + self::class, + $use[\ILIAS\Language\Language::class], + $use[\ILIAS\Logging\LoggerFactory::class] + ); } } diff --git a/components/ILIAS/Test/classes/class.ilCronFinishUnfinishedTestPasses.php b/components/ILIAS/Test/classes/class.ilCronFinishUnfinishedTestPasses.php index d62456d89acd..5708b08eed52 100755 --- a/components/ILIAS/Test/classes/class.ilCronFinishUnfinishedTestPasses.php +++ b/components/ILIAS/Test/classes/class.ilCronFinishUnfinishedTestPasses.php @@ -30,12 +30,10 @@ */ class ilCronFinishUnfinishedTestPasses extends ilCronJob { - protected readonly TestLogger $logger; - - protected readonly ilLanguage $lng; - protected readonly ilDBInterface $db; - protected readonly ilObjUser $user; - protected readonly ilObjectDataCache $obj_data_cache; + protected TestLogger $logger; + protected ilDBInterface $db; + protected ilObjUser $user; + protected ilObjectDataCache $obj_data_cache; protected int $now; protected array $unfinished_passes; protected array $test_ids; @@ -43,15 +41,15 @@ class ilCronFinishUnfinishedTestPasses extends ilCronJob protected ilTestProcessLockerFactory $processLockerFactory; protected TestResultRepository $test_pass_result_repository; - public function __construct() + public function init(): void { + $this->lng->loadLanguageModule('assessment'); + /** @var ILIAS\DI\Container $DIC */ global $DIC; $this->logger = TestDIC::dic()['logging.logger']; - $this->lng = $DIC['lng']; $this->user = $DIC['ilUser']; - $this->lng->loadLanguageModule('assessment'); $this->db = $DIC->database(); $this->obj_data_cache = $DIC['ilObjDataCache']; $this->now = time(); diff --git a/components/ILIAS/Test/module.xml b/components/ILIAS/Test/module.xml index b08137b7ad80..cb4e48da3cba 100755 --- a/components/ILIAS/Test/module.xml +++ b/components/ILIAS/Test/module.xml @@ -30,9 +30,6 @@ wfld - - - diff --git a/components/ILIAS/Test/tests/ilCronFinishUnfinishedTestPassesTest.php b/components/ILIAS/Test/tests/ilCronFinishUnfinishedTestPassesTest.php index 00516db28fa8..30a204d159bb 100755 --- a/components/ILIAS/Test/tests/ilCronFinishUnfinishedTestPassesTest.php +++ b/components/ILIAS/Test/tests/ilCronFinishUnfinishedTestPassesTest.php @@ -19,6 +19,7 @@ declare(strict_types=1); use ILIAS\Cron\Schedule\CronJobScheduleType; +use ILIAS\Logging\LoggerFactory; /** * Class ilCronFinishUnfinishedTestPassesTest @@ -40,7 +41,15 @@ protected function setUp(): void define("ILIAS_LOG_ENABLED", false); } - $this->test_obj = new ilCronFinishUnfinishedTestPasses(); + $logger_factory = $this->getMockBuilder(LoggerFactory::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->test_obj = new ilCronFinishUnfinishedTestPasses( + 'components\ILIAS\Test', + $GLOBALS['lng'], + $logger_factory + ); } public function test_instantiateObject_shouldReturnInstance(): void @@ -63,8 +72,16 @@ public function testGetTitle(): void ->willReturn('testString') ; + $logger_factory = $this->getMockBuilder(LoggerFactory::class) + ->disableOriginalConstructor() + ->getMock(); + $this->setGlobalVariable('lng', $lng_mock); - $test_obj = new ilCronFinishUnfinishedTestPasses(); + $test_obj = new ilCronFinishUnfinishedTestPasses( + 'components\ILIAS\Test', + $GLOBALS['lng'], + $logger_factory + ); $this->assertEquals('testString', $test_obj->getTitle()); } @@ -79,8 +96,16 @@ public function testGetDescription(): void ->willReturn('testString') ; + $logger_factory = $this->getMockBuilder(LoggerFactory::class) + ->disableOriginalConstructor() + ->getMock(); + $this->setGlobalVariable('lng', $lng_mock); - $test_obj = new ilCronFinishUnfinishedTestPasses(); + $test_obj = new ilCronFinishUnfinishedTestPasses( + 'components\ILIAS\Test', + $GLOBALS['lng'], + $logger_factory + ); $this->assertEquals('testString', $test_obj->getDescription()); } From 1fc6de65d9dfae9c3f08518f605c9d0d0a40eb63 Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Mon, 16 Dec 2024 09:15:11 +0100 Subject: [PATCH 11/39] Component/MetaData: contribute cron jobs --- components/ILIAS/MetaData/MetaData.php | 8 ++++++++ .../ILIAS/MetaData/classes/class.ilCronOerHarvester.php | 9 +++------ components/ILIAS/MetaData/service.xml | 3 --- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/components/ILIAS/MetaData/MetaData.php b/components/ILIAS/MetaData/MetaData.php index 7fc312612276..a16d66d9bbd9 100644 --- a/components/ILIAS/MetaData/MetaData.php +++ b/components/ILIAS/MetaData/MetaData.php @@ -42,5 +42,13 @@ public function init( $contribute[Component\Resource\PublicAsset::class] = fn() => new Component\Resource\Endpoint($this, "oai.php"); + + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \ilCronOerHarvester( + self::class, + $use[\ILIAS\Language\Language::class], + $use[\ILIAS\Logging\LoggerFactory::class] + ); + } } diff --git a/components/ILIAS/MetaData/classes/class.ilCronOerHarvester.php b/components/ILIAS/MetaData/classes/class.ilCronOerHarvester.php index c026983043ec..55c2da8472e9 100755 --- a/components/ILIAS/MetaData/classes/class.ilCronOerHarvester.php +++ b/components/ILIAS/MetaData/classes/class.ilCronOerHarvester.php @@ -33,18 +33,15 @@ class ilCronOerHarvester extends ilCronJob protected const DEFAULT_SCHEDULE_VALUE = 1; private ilLogger $logger; - private ilLanguage $lng; private Initiator $initiator; private SettingsInterface $settings; - public function __construct() + public function init(): void { - global $DIC; - - $this->logger = $DIC->logger()->meta(); - $this->lng = $DIC->language(); $this->lng->loadLanguageModule('meta'); + $this->logger = $this->logger_factory->getLogger('meta'); + global $DIC; $this->initiator = new Initiator($DIC); $this->settings = $this->initiator->settings(); } diff --git a/components/ILIAS/MetaData/service.xml b/components/ILIAS/MetaData/service.xml index 47cd91d29cc2..76c5a1d3c82c 100755 --- a/components/ILIAS/MetaData/service.xml +++ b/components/ILIAS/MetaData/service.xml @@ -9,8 +9,5 @@ adm - - - From 6dd58f6b40f873b58ec43d58c8701024fdba99e3 Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Mon, 16 Dec 2024 09:32:26 +0100 Subject: [PATCH 12/39] Component/OrgUnits: contribute cron jobs --- components/ILIAS/OrgUnit/OrgUnit.php | 7 +++++++ .../classes/class.ilCronUpdateOrgUnitPaths.php | 12 ------------ components/ILIAS/OrgUnit/module.xml | 5 +---- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/components/ILIAS/OrgUnit/OrgUnit.php b/components/ILIAS/OrgUnit/OrgUnit.php index b65df02e25d1..3ad2eee35550 100644 --- a/components/ILIAS/OrgUnit/OrgUnit.php +++ b/components/ILIAS/OrgUnit/OrgUnit.php @@ -38,5 +38,12 @@ public function init( ); $contribute[Component\Resource\PublicAsset::class] = fn() => new Component\Resource\ComponentJS($this, "authority.js"); + + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \ilCronUpdateOrgUnitPaths( + self::class, + $use[\ILIAS\Language\Language::class], + $use[\ILIAS\Logging\LoggerFactory::class] + ); } } diff --git a/components/ILIAS/OrgUnit/classes/class.ilCronUpdateOrgUnitPaths.php b/components/ILIAS/OrgUnit/classes/class.ilCronUpdateOrgUnitPaths.php index b25e5887beb3..ae6432307541 100755 --- a/components/ILIAS/OrgUnit/classes/class.ilCronUpdateOrgUnitPaths.php +++ b/components/ILIAS/OrgUnit/classes/class.ilCronUpdateOrgUnitPaths.php @@ -26,18 +26,6 @@ class ilCronUpdateOrgUnitPaths extends ilCronJob { public const ID = "orgunit_paths"; - protected ilDBInterface $db; - protected ilLogger $log; - protected ilTree $tree; - - private ilLanguage $lng; - - public function __construct() - { - global $DIC; - - $this->lng = $DIC->language(); - } public function getId(): string { diff --git a/components/ILIAS/OrgUnit/module.xml b/components/ILIAS/OrgUnit/module.xml index d0ddab88bad9..3336a696fbdd 100755 --- a/components/ILIAS/OrgUnit/module.xml +++ b/components/ILIAS/OrgUnit/module.xml @@ -23,7 +23,4 @@ - - - - + From 3762f77f53f0e1109da9ee6904b0142434d1c516 Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Mon, 16 Dec 2024 09:35:38 +0100 Subject: [PATCH 13/39] Component/Exercise: contribute cron jobs --- components/ILIAS/Exercise/Exercise.php | 12 ++++++++++++ .../class.ilExcCronFeedbackNotification.php | 19 ++++--------------- .../classes/class.ilExcCronReminders.php | 8 ++------ components/ILIAS/Exercise/module.xml | 4 ---- 4 files changed, 18 insertions(+), 25 deletions(-) diff --git a/components/ILIAS/Exercise/Exercise.php b/components/ILIAS/Exercise/Exercise.php index e6dc61d77cd9..c70f85f70100 100644 --- a/components/ILIAS/Exercise/Exercise.php +++ b/components/ILIAS/Exercise/Exercise.php @@ -42,5 +42,17 @@ public function init( new Component\Resource\ComponentJS($this, "ilExcPresentation.js"); $contribute[Component\Resource\PublicAsset::class] = fn() => new Component\Resource\ComponentJS($this, "ilExcPeerReview.js"); + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \ilExcCronFeedbackNotification( + self::class, + $use[\ILIAS\Language\Language::class], + $use[\ILIAS\Logging\LoggerFactory::class] + ); + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \ilExcCronReminders( + self::class, + $use[\ILIAS\Language\Language::class], + $use[\ILIAS\Logging\LoggerFactory::class] + ); } } diff --git a/components/ILIAS/Exercise/classes/class.ilExcCronFeedbackNotification.php b/components/ILIAS/Exercise/classes/class.ilExcCronFeedbackNotification.php index 94fb217fd142..405f24fc9051 100755 --- a/components/ILIAS/Exercise/classes/class.ilExcCronFeedbackNotification.php +++ b/components/ILIAS/Exercise/classes/class.ilExcCronFeedbackNotification.php @@ -26,14 +26,9 @@ */ class ilExcCronFeedbackNotification extends ilCronJob { - protected ilLanguage $lng; - - - public function __construct() + public function init(): void { - global $DIC; - - $this->lng = $DIC->language(); + $this->lng->loadLanguageModule('exc'); } public function getId(): string @@ -43,18 +38,12 @@ public function getId(): string public function getTitle(): string { - $lng = $this->lng; - - $lng->loadLanguageModule("exc"); - return $lng->txt("exc_global_feedback_file_cron"); + return $this->lng->txt("exc_global_feedback_file_cron"); } public function getDescription(): string { - $lng = $this->lng; - - $lng->loadLanguageModule("exc"); - return $lng->txt("exc_global_feedback_file_cron_info"); + return $this->lng->txt("exc_global_feedback_file_cron_info"); } public function getDefaultScheduleType(): CronJobScheduleType diff --git a/components/ILIAS/Exercise/classes/class.ilExcCronReminders.php b/components/ILIAS/Exercise/classes/class.ilExcCronReminders.php index b14b9f85ad37..23f653b43f52 100755 --- a/components/ILIAS/Exercise/classes/class.ilExcCronReminders.php +++ b/components/ILIAS/Exercise/classes/class.ilExcCronReminders.php @@ -26,13 +26,9 @@ */ class ilExcCronReminders extends ilCronJob { - protected ilLanguage $lng; - - public function __construct() + public function init(): void { - global $DIC; - - $this->lng = $DIC->language(); + $this->lng->loadLanguageModule('exc'); } public function getId(): string diff --git a/components/ILIAS/Exercise/module.xml b/components/ILIAS/Exercise/module.xml index cecc31ad9787..05ffd61ce1ea 100755 --- a/components/ILIAS/Exercise/module.xml +++ b/components/ILIAS/Exercise/module.xml @@ -25,10 +25,6 @@ wfld - - - - From 30e7653f468406aa7a6ddf4e6692a330e389953e Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Mon, 16 Dec 2024 10:45:49 +0100 Subject: [PATCH 14/39] Component/Tracking: contribute cron jobs --- components/ILIAS/Tracking/Tracking.php | 7 +++++++ .../classes/class.ilLPCronObjectStatistics.php | 11 ++++------- components/ILIAS/Tracking/service.xml | 3 --- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/components/ILIAS/Tracking/Tracking.php b/components/ILIAS/Tracking/Tracking.php index b597fb4fe297..fd914d7d0797 100644 --- a/components/ILIAS/Tracking/Tracking.php +++ b/components/ILIAS/Tracking/Tracking.php @@ -39,5 +39,12 @@ public function init( $contribute[SetupAgentInterface::class] = fn() => new SetupAgent($pull[Refinery::class]); $contribute[Component\Resource\PublicAsset::class] = fn() => new Component\Resource\ComponentJS($this, "ilObjStat.js"); + + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \ilLPCronObjectStatistics( + self::class, + $use[Language\Language::class], + $use[\ILIAS\Logging\LoggerFactory::class] + ); } } diff --git a/components/ILIAS/Tracking/classes/class.ilLPCronObjectStatistics.php b/components/ILIAS/Tracking/classes/class.ilLPCronObjectStatistics.php index 64e541aa9b70..05a39d4a813e 100755 --- a/components/ILIAS/Tracking/classes/class.ilLPCronObjectStatistics.php +++ b/components/ILIAS/Tracking/classes/class.ilLPCronObjectStatistics.php @@ -28,20 +28,17 @@ class ilLPCronObjectStatistics extends ilCronJob { protected int $date = 0; - - protected ilLanguage $lng; protected ilDBInterface $db; protected ilTree $tree; protected ilLogger $logger; protected ilCronManager $cron_manager; - public function __construct() + public function init(): void { - global $DIC; + $this->lng->loadLanguageModule('trac'); + $this->logger = $this->logger_factory->getLogger('trac'); - $this->logger = $DIC->logger()->trac(); - $this->lng = $DIC->language(); - $this->lng->loadLanguageModule("trac"); + global $DIC; $this->db = $DIC->database(); $this->tree = $DIC->repositoryTree(); $this->cron_manager = $DIC->cron()->manager(); diff --git a/components/ILIAS/Tracking/service.xml b/components/ILIAS/Tracking/service.xml index 9803e32764fe..358d71cc0eb4 100755 --- a/components/ILIAS/Tracking/service.xml +++ b/components/ILIAS/Tracking/service.xml @@ -17,8 +17,5 @@ - - - From 7b350700315a52d4862539a9c6ad28dad112f97f Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Mon, 16 Dec 2024 10:46:32 +0100 Subject: [PATCH 15/39] Component/StudyProgramme: contribute cron jobs --- .../ILIAS/StudyProgramme/StudyProgramme.php | 31 +++++++++++++++++++ ...lPrgInvalidateExpiredProgressesCronJob.php | 8 ++--- .../class.ilPrgRestartAssignmentsCronJob.php | 7 ++--- .../class.ilPrgUpdateProgressCronJob.php | 9 ++---- .../class.ilPrgUserNotRestartedCronJob.php | 11 +++---- .../class.ilPrgUserRiskyToFailCronJob.php | 15 ++++----- components/ILIAS/StudyProgramme/module.xml | 7 ----- 7 files changed, 49 insertions(+), 39 deletions(-) diff --git a/components/ILIAS/StudyProgramme/StudyProgramme.php b/components/ILIAS/StudyProgramme/StudyProgramme.php index 29e04a00d8ea..56879a5eea47 100644 --- a/components/ILIAS/StudyProgramme/StudyProgramme.php +++ b/components/ILIAS/StudyProgramme/StudyProgramme.php @@ -38,5 +38,36 @@ public function init( ); $contribute[Component\Resource\PublicAsset::class] = fn() => new Component\Resource\ComponentCSS($this, "css/ilStudyProgramme.css"); + + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \ilPrgInvalidateExpiredProgressesCronJob( + self::class, + $use[\ILIAS\Language\Language::class], + $use[\ILIAS\Logging\LoggerFactory::class] + ); + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \ilPrgRestartAssignmentsCronJob( + self::class, + $use[\ILIAS\Language\Language::class], + $use[\ILIAS\Logging\LoggerFactory::class] + ); + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \ilPrgUserNotRestartedCronJob( + self::class, + $use[\ILIAS\Language\Language::class], + $use[\ILIAS\Logging\LoggerFactory::class] + ); + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \ilPrgUserRiskyToFailCronJob( + self::class, + $use[\ILIAS\Language\Language::class], + $use[\ILIAS\Logging\LoggerFactory::class] + ); + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \ilPrgUpdateProgressCronJob( + self::class, + $use[\ILIAS\Language\Language::class], + $use[\ILIAS\Logging\LoggerFactory::class] + ); } } diff --git a/components/ILIAS/StudyProgramme/classes/class.ilPrgInvalidateExpiredProgressesCronJob.php b/components/ILIAS/StudyProgramme/classes/class.ilPrgInvalidateExpiredProgressesCronJob.php index 878ed71e05be..2842f49a5118 100755 --- a/components/ILIAS/StudyProgramme/classes/class.ilPrgInvalidateExpiredProgressesCronJob.php +++ b/components/ILIAS/StudyProgramme/classes/class.ilPrgInvalidateExpiredProgressesCronJob.php @@ -32,16 +32,14 @@ class ilPrgInvalidateExpiredProgressesCronJob extends ilCronJob private const ID = 'prg_invalidate_expired_progresses'; protected ilComponentLogger $log; - protected ilLanguage $lng; protected ilPRGAssignmentDBRepository $assignment_repo; protected ilStudyProgrammeSettingsDBRepository $settings_repo; - public function __construct() + + public function init(): void { - global $DIC; - $this->log = $DIC['ilLog']; - $this->lng = $DIC['lng']; $this->lng->loadLanguageModule('prg'); + $this->log = $this->logger_factory->getLogger('prg'); $dic = ilStudyProgrammeDIC::dic(); $this->assignment_repo = $dic['repo.assignment']; diff --git a/components/ILIAS/StudyProgramme/classes/class.ilPrgRestartAssignmentsCronJob.php b/components/ILIAS/StudyProgramme/classes/class.ilPrgRestartAssignmentsCronJob.php index 5dd612b0e018..b9ab171a2a48 100755 --- a/components/ILIAS/StudyProgramme/classes/class.ilPrgRestartAssignmentsCronJob.php +++ b/components/ILIAS/StudyProgramme/classes/class.ilPrgRestartAssignmentsCronJob.php @@ -31,18 +31,15 @@ class ilPrgRestartAssignmentsCronJob extends ilCronJob private const ACTING_USR_ID = ilPRGAssignment::AUTO_ASSIGNED_BY_RESTART; protected ilComponentLogger $log; - protected ilLanguage $lng; protected ilPRGAssignmentDBRepository $assignment_repo; protected ilPrgCronJobAdapter $adapter; protected array $prgs = []; - public function __construct() + public function init(): void { - global $DIC; - $this->log = $DIC['ilLog']; - $this->lng = $DIC['lng']; $this->lng->loadLanguageModule('prg'); + $this->log = $this->logger_factory->getLogger('prg'); $dic = ilStudyProgrammeDIC::dic(); $this->assignment_repo = $dic['repo.assignment']; diff --git a/components/ILIAS/StudyProgramme/classes/class.ilPrgUpdateProgressCronJob.php b/components/ILIAS/StudyProgramme/classes/class.ilPrgUpdateProgressCronJob.php index 558fabf1ac45..dabae47ab0bf 100755 --- a/components/ILIAS/StudyProgramme/classes/class.ilPrgUpdateProgressCronJob.php +++ b/components/ILIAS/StudyProgramme/classes/class.ilPrgUpdateProgressCronJob.php @@ -1,7 +1,5 @@ lng = $DIC['lng']; $this->lng->loadLanguageModule('prg'); $dic = ilStudyProgrammeDIC::dic(); diff --git a/components/ILIAS/StudyProgramme/classes/class.ilPrgUserNotRestartedCronJob.php b/components/ILIAS/StudyProgramme/classes/class.ilPrgUserNotRestartedCronJob.php index d2e54e408617..ccab74a414e7 100755 --- a/components/ILIAS/StudyProgramme/classes/class.ilPrgUserNotRestartedCronJob.php +++ b/components/ILIAS/StudyProgramme/classes/class.ilPrgUserNotRestartedCronJob.php @@ -1,7 +1,5 @@ log = $DIC['ilLog']; - $this->lng = $DIC['lng']; $this->lng->loadLanguageModule('prg'); + $this->log = $this->logger_factory->getLogger('prg'); $dic = ilStudyProgrammeDIC::dic(); $this->assignment_repo = $dic['repo.assignment']; diff --git a/components/ILIAS/StudyProgramme/classes/class.ilPrgUserRiskyToFailCronJob.php b/components/ILIAS/StudyProgramme/classes/class.ilPrgUserRiskyToFailCronJob.php index db5e8fa1d77f..8c1707037c14 100755 --- a/components/ILIAS/StudyProgramme/classes/class.ilPrgUserRiskyToFailCronJob.php +++ b/components/ILIAS/StudyProgramme/classes/class.ilPrgUserRiskyToFailCronJob.php @@ -1,9 +1,5 @@ log = $DIC['ilLog']; - $this->lng = $DIC['lng']; $this->lng->loadLanguageModule('prg'); + $this->log = $this->logger_factory->getLogger('prg'); $dic = ilStudyProgrammeDIC::dic(); $this->assignment_repo = $dic['repo.assignment']; diff --git a/components/ILIAS/StudyProgramme/module.xml b/components/ILIAS/StudyProgramme/module.xml index c3a5b546c010..1d5a1d883405 100755 --- a/components/ILIAS/StudyProgramme/module.xml +++ b/components/ILIAS/StudyProgramme/module.xml @@ -43,13 +43,6 @@ - - - - - - - From 1c46f3785d81dc951e826d5a7cb2b95c0aa014b1 Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Mon, 16 Dec 2024 10:47:11 +0100 Subject: [PATCH 16/39] Component/Search: contribute cron jobs --- components/ILIAS/Search/Search.php | 6 +++++ .../classes/Lucene/class.ilLuceneIndexer.php | 23 ++++++++++++++----- components/ILIAS/Search/service.xml | 3 --- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/components/ILIAS/Search/Search.php b/components/ILIAS/Search/Search.php index bd999909464c..2964a8dce702 100644 --- a/components/ILIAS/Search/Search.php +++ b/components/ILIAS/Search/Search.php @@ -36,5 +36,11 @@ public function init( new Component\Resource\ComponentJS($this, "SearchMainMenu.js"); $contribute[Component\Resource\PublicAsset::class] = fn() => new Component\Resource\ComponentJS($this, "Search.js"); + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \ilLuceneIndexer( + self::class, + $use[\ILIAS\Language\Language::class], + $use[\ILIAS\Logging\LoggerFactory::class] + ); } } diff --git a/components/ILIAS/Search/classes/Lucene/class.ilLuceneIndexer.php b/components/ILIAS/Search/classes/Lucene/class.ilLuceneIndexer.php index beeddd62fe96..3d051eb19c19 100755 --- a/components/ILIAS/Search/classes/Lucene/class.ilLuceneIndexer.php +++ b/components/ILIAS/Search/classes/Lucene/class.ilLuceneIndexer.php @@ -1,7 +1,22 @@ lng = $DIC->language(); $this->setting = $DIC->settings(); } diff --git a/components/ILIAS/Search/service.xml b/components/ILIAS/Search/service.xml index 1932c03249b6..2eee4dc6ec6b 100755 --- a/components/ILIAS/Search/service.xml +++ b/components/ILIAS/Search/service.xml @@ -14,8 +14,5 @@ - - - From f3d87472f8f6c7272ce42bdc4db26320e0769fd7 Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Mon, 16 Dec 2024 10:47:42 +0100 Subject: [PATCH 17/39] Component/Membership: contribute cron jobs --- components/ILIAS/Membership/Membership.php | 14 +++++++++++++- .../Cron/class.ilMembershipCronMinMembers.php | 15 ++------------- .../Cron/class.ilMembershipCronNotifications.php | 11 +++-------- .../class.ilMembershipCronNotificationsData.php | 6 ++---- components/ILIAS/Membership/service.xml | 4 ---- 5 files changed, 20 insertions(+), 30 deletions(-) diff --git a/components/ILIAS/Membership/Membership.php b/components/ILIAS/Membership/Membership.php index b43c82b90d66..ad24df70e387 100644 --- a/components/ILIAS/Membership/Membership.php +++ b/components/ILIAS/Membership/Membership.php @@ -32,6 +32,18 @@ public function init( array | \ArrayAccess &$pull, array | \ArrayAccess &$internal, ): void { - // ... + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \ilMembershipCronMinMembers( + self::class, + $use[\ILIAS\Language\Language::class], + $use[\ILIAS\Logging\LoggerFactory::class], + ); + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \ilMembershipCronNotifications( + self::class, + $use[\ILIAS\Language\Language::class], + $use[\ILIAS\Logging\LoggerFactory::class], + ); + } } diff --git a/components/ILIAS/Membership/classes/Cron/class.ilMembershipCronMinMembers.php b/components/ILIAS/Membership/classes/Cron/class.ilMembershipCronMinMembers.php index e214ba53f0b0..2b44e065c573 100755 --- a/components/ILIAS/Membership/classes/Cron/class.ilMembershipCronMinMembers.php +++ b/components/ILIAS/Membership/classes/Cron/class.ilMembershipCronMinMembers.php @@ -1,9 +1,5 @@ lng = $DIC->language(); - } - public function getId(): string { return "mem_min_members"; diff --git a/components/ILIAS/Membership/classes/Cron/class.ilMembershipCronNotifications.php b/components/ILIAS/Membership/classes/Cron/class.ilMembershipCronNotifications.php index a673e9b83b00..99ab4877e356 100755 --- a/components/ILIAS/Membership/classes/Cron/class.ilMembershipCronNotifications.php +++ b/components/ILIAS/Membership/classes/Cron/class.ilMembershipCronNotifications.php @@ -1,9 +1,5 @@ lng = $DIC->language(); $this->db = $DIC->database(); $this->logger = $DIC->logger()->mmbr(); $this->tree = $DIC->repositoryTree(); diff --git a/components/ILIAS/Membership/classes/Cron/class.ilMembershipCronNotificationsData.php b/components/ILIAS/Membership/classes/Cron/class.ilMembershipCronNotificationsData.php index 03246f6a12ef..a8c606848245 100755 --- a/components/ILIAS/Membership/classes/Cron/class.ilMembershipCronNotificationsData.php +++ b/components/ILIAS/Membership/classes/Cron/class.ilMembershipCronNotificationsData.php @@ -1,9 +1,5 @@ - - - - From b0e6a036435cb5e0688d0080616778b082e4da6b Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Mon, 16 Dec 2024 10:48:17 +0100 Subject: [PATCH 18/39] Component/Forum: contribute cron jobs --- components/ILIAS/Forum/Forum.php | 10 ++++- .../classes/class.ilForumCronNotification.php | 38 +++++++------------ components/ILIAS/Forum/module.xml | 3 -- 3 files changed, 23 insertions(+), 28 deletions(-) diff --git a/components/ILIAS/Forum/Forum.php b/components/ILIAS/Forum/Forum.php index 0d79bcdc6cc0..6d5abd09e998 100644 --- a/components/ILIAS/Forum/Forum.php +++ b/components/ILIAS/Forum/Forum.php @@ -38,7 +38,15 @@ public function init( ); $contribute[Component\Resource\PublicAsset::class] = fn() => new Component\Resource\ComponentJS($this, "autosave_forum.js"); + $contribute[Component\Resource\PublicAsset::class] = fn() => - new Component\Resource\ComponentCSS($this, "forum_table.css"); + new Component\Resource\ComponentCSS($this, "forum_table.css"); + + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \ilForumCronNotification( + self::class, + $use[\ILIAS\Language\Language::class], + $use[\ILIAS\Logging\LoggerFactory::class] + ); } } diff --git a/components/ILIAS/Forum/classes/class.ilForumCronNotification.php b/components/ILIAS/Forum/classes/class.ilForumCronNotification.php index 87f2e029d8b9..7180db3f6a08 100755 --- a/components/ILIAS/Forum/classes/class.ilForumCronNotification.php +++ b/components/ILIAS/Forum/classes/class.ilForumCronNotification.php @@ -41,32 +41,24 @@ class ilForumCronNotification extends ilCronJob /** @var array */ private static array $container_by_frm_ref_id = []; - private readonly ilLanguage $lng; - private readonly ilSetting $settings; + private ilSetting $settings; private ilLogger $logger; private ilTree $tree; private int $num_sent_messages = 0; - private readonly ilDBInterface $ilDB; - private readonly ilForumNotificationCache $notificationCache; - private readonly \ILIAS\Refinery\Factory $refinery; - private readonly ilCronManager $cronManager; - - public function __construct( - ?ilDBInterface $database = null, - ?ilForumNotificationCache $notificationCache = null, - ?ilLanguage $lng = null, - ?ilSetting $settings = null, - ?\ILIAS\Refinery\Factory $refinery = null, - ?ilCronManager $cronManager = null - ) { - global $DIC; + private ilDBInterface $ilDB; + private ilForumNotificationCache $notificationCache; + private \ILIAS\Refinery\Factory $refinery; + private ilCronManager $cronManager; - $this->settings = $settings ?? new ilSetting('frma'); - $this->lng = $lng ?? $DIC->language(); - $this->ilDB = $database ?? $DIC->database(); - $this->notificationCache = $notificationCache ?? new ilForumNotificationCache(); - $this->refinery = $refinery ?? $DIC->refinery(); - $this->cronManager = $cronManager ?? $DIC->cron()->manager(); + public function init(): void + { + $this->logger = $this->logger_factory->getLogger('frm'); + global $DIC; + $this->settings = new ilSetting('frma'); + $this->ilDB = $DIC->database(); + $this->notificationCache = new ilForumNotificationCache(); + $this->refinery = $DIC->refinery(); + $this->cronManager = $DIC->cron()->manager(); } public function getId(): string @@ -119,8 +111,6 @@ public function keepAlive(): void public function run(): ilCronJobResult { global $DIC; - - $this->logger = $DIC->logger()->frm(); $this->tree = $DIC->repositoryTree(); $status = ilCronJobResult::STATUS_NO_ACTION; diff --git a/components/ILIAS/Forum/module.xml b/components/ILIAS/Forum/module.xml index ad0e3726f968..ed9b7f1fe1a6 100755 --- a/components/ILIAS/Forum/module.xml +++ b/components/ILIAS/Forum/module.xml @@ -32,9 +32,6 @@ - - - From 70c484b24cc74e72be368a6bff2c533b40067ba3 Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Mon, 16 Dec 2024 10:49:55 +0100 Subject: [PATCH 19/39] Component/Mail: contribute cron jobs --- components/ILIAS/Mail/Mail.php | 12 ++++++++++++ .../Mail/classes/class.ilMailCronNotification.php | 12 +++--------- .../Mail/classes/class.ilMailCronOrphanedMails.php | 6 +----- components/ILIAS/Mail/service.xml | 4 ---- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/components/ILIAS/Mail/Mail.php b/components/ILIAS/Mail/Mail.php index 065d26d5ea48..d8979aabd811 100644 --- a/components/ILIAS/Mail/Mail.php +++ b/components/ILIAS/Mail/Mail.php @@ -38,5 +38,17 @@ public function init( ); $contribute[Component\Resource\PublicAsset::class] = fn() => new Component\Resource\ComponentJS($this, "ilMailComposeFunctions.js"); + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \ilMailCronNotification( + self::class, + $use[\ILIAS\Language\Language::class], + $use[\ILIAS\Logging\LoggerFactory::class] + ); + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \ilMailCronOrphanedMails( + self::class, + $use[\ILIAS\Language\Language::class], + $use[\ILIAS\Logging\LoggerFactory::class] + ); } } diff --git a/components/ILIAS/Mail/classes/class.ilMailCronNotification.php b/components/ILIAS/Mail/classes/class.ilMailCronNotification.php index 27657ec9d09e..21fa5725397c 100755 --- a/components/ILIAS/Mail/classes/class.ilMailCronNotification.php +++ b/components/ILIAS/Mail/classes/class.ilMailCronNotification.php @@ -28,17 +28,17 @@ class ilMailCronNotification extends ilCronJob { private GlobalHttpState $http; - protected ilLanguage $lng; protected ilSetting $settings; protected bool $initDone = false; - protected function init(): void + public function init(): void { + $this->lng->loadLanguageModule('mail'); + global $DIC; if (!$this->initDone) { $this->settings = $DIC->settings(); - $this->lng = $DIC->language(); $this->http = $DIC->http(); $this->initDone = true; @@ -52,17 +52,11 @@ public function getId(): string public function getTitle(): string { - $this->init(); - return $this->lng->txt('cron_mail_notification'); } public function getDescription(): string { - $this->init(); - - $this->lng->loadLanguageModule('mail'); - return sprintf( $this->lng->txt('cron_mail_notification_desc'), $this->lng->txt('mail_allow_external') diff --git a/components/ILIAS/Mail/classes/class.ilMailCronOrphanedMails.php b/components/ILIAS/Mail/classes/class.ilMailCronOrphanedMails.php index 01701a192db1..8710039dbeb9 100755 --- a/components/ILIAS/Mail/classes/class.ilMailCronOrphanedMails.php +++ b/components/ILIAS/Mail/classes/class.ilMailCronOrphanedMails.php @@ -36,20 +36,18 @@ class ilMailCronOrphanedMails extends ilCronJob { private GlobalHttpState $http; private Refinery $refinery; - private ilLanguage $lng; private ilSetting $settings; private ilDBInterface $db; private ilObjUser $user; private bool $initDone = false; private ilCronManager $cron_manager; - private function init(): void + public function init(): void { global $DIC; if (!$this->initDone) { $this->settings = $DIC->settings(); - $this->lng = $DIC->language(); $this->db = $DIC->database(); $this->user = $DIC->user(); $this->http = $DIC->http(); @@ -91,13 +89,11 @@ public function getId(): string public function getTitle(): string { - $this->init(); return $this->lng->txt('mail_orphaned_mails'); } public function getDescription(): string { - $this->init(); return $this->lng->txt('mail_orphaned_mails_desc'); } diff --git a/components/ILIAS/Mail/service.xml b/components/ILIAS/Mail/service.xml index c1919cdeb647..80122b01f2fa 100755 --- a/components/ILIAS/Mail/service.xml +++ b/components/ILIAS/Mail/service.xml @@ -10,10 +10,6 @@ adm - - - - From 72dc8b623c6904e3119887283a725b8c34c369da Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Mon, 16 Dec 2024 10:50:11 +0100 Subject: [PATCH 20/39] Component/LDAP: contribute cron jobs --- components/ILIAS/LDAP/LDAP.php | 8 +++++++- .../LDAP/classes/class.ilLDAPCronSynchronization.php | 8 +++----- components/ILIAS/LDAP/service.xml | 3 --- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/components/ILIAS/LDAP/LDAP.php b/components/ILIAS/LDAP/LDAP.php index 2488615ea94c..795ba2c87c9c 100644 --- a/components/ILIAS/LDAP/LDAP.php +++ b/components/ILIAS/LDAP/LDAP.php @@ -33,6 +33,12 @@ public function init( array | \ArrayAccess &$internal, ): void { $contribute[\ILIAS\Setup\Agent::class] = static fn() => - new \ILIAS\LDAP\Setup\Agent(); + new \ILIAS\LDAP\Setup\Agent(); + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \ilLDAPCronSynchronization( + self::class, + $use[\ILIAS\Language\Language::class], + $use[\ILIAS\Logging\LoggerFactory::class] + ); } } diff --git a/components/ILIAS/LDAP/classes/class.ilLDAPCronSynchronization.php b/components/ILIAS/LDAP/classes/class.ilLDAPCronSynchronization.php index 2afe678f8bba..ee9cf30bfa9e 100755 --- a/components/ILIAS/LDAP/classes/class.ilLDAPCronSynchronization.php +++ b/components/ILIAS/LDAP/classes/class.ilLDAPCronSynchronization.php @@ -26,20 +26,18 @@ */ class ilLDAPCronSynchronization extends ilCronJob { - private ilLanguage $lng; private ilLogger $logger; private ilCronManager $cronManager; private int $counter = 0; - public function __construct() + public function init(): void { - global $DIC; + $this->lng->loadLanguageModule('ldap'); + global $DIC; $this->logger = $DIC->logger()->auth(); $this->cronManager = $DIC->cron()->manager(); - $this->lng = $DIC->language(); - $this->lng->loadLanguageModule('ldap'); } public function getId(): string diff --git a/components/ILIAS/LDAP/service.xml b/components/ILIAS/LDAP/service.xml index b80fb92c506e..7b0dde5bd2a0 100755 --- a/components/ILIAS/LDAP/service.xml +++ b/components/ILIAS/LDAP/service.xml @@ -6,7 +6,4 @@ - - - From 3b01caf215e1d636b72eb11cefef5a0a33b2cd9c Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Mon, 16 Dec 2024 10:50:30 +0100 Subject: [PATCH 21/39] Component/LTIProvider: contribute cron jobs --- components/ILIAS/LTIProvider/LTIProvider.php | 7 +++++++ .../LTIProvider/classes/class.ilLTICronOutcomeService.php | 7 +++---- components/ILIAS/LTIProvider/service.xml | 3 --- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/components/ILIAS/LTIProvider/LTIProvider.php b/components/ILIAS/LTIProvider/LTIProvider.php index fd0843291de0..959c41db8328 100644 --- a/components/ILIAS/LTIProvider/LTIProvider.php +++ b/components/ILIAS/LTIProvider/LTIProvider.php @@ -39,5 +39,12 @@ public function init( $contribute[Component\Resource\PublicAsset::class] = fn() => new Component\Resource\Endpoint($this, "lti.php"); + + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \ilLTICronOutcomeService( + self::class, + $use[\ILIAS\Language\Language::class], + $use[\ILIAS\Logging\LoggerFactory::class] + ); } } diff --git a/components/ILIAS/LTIProvider/classes/class.ilLTICronOutcomeService.php b/components/ILIAS/LTIProvider/classes/class.ilLTICronOutcomeService.php index 334e7f70b76b..9077f4b11254 100644 --- a/components/ILIAS/LTIProvider/classes/class.ilLTICronOutcomeService.php +++ b/components/ILIAS/LTIProvider/classes/class.ilLTICronOutcomeService.php @@ -28,14 +28,13 @@ */ class ilLTICronOutcomeService extends ilCronJob { - private ilLanguage $lng; private ilCronJobRepository $cronRepo; - public function __construct() + public function init(): void { + $this->lng->loadLanguageModule('lti'); + global $DIC; - $this->lng = $DIC->language(); - $this->lng->loadLanguageModule("lti"); $this->cronRepo = $DIC->cron()->repository(); } diff --git a/components/ILIAS/LTIProvider/service.xml b/components/ILIAS/LTIProvider/service.xml index 0d2564f42fa7..b35e0640222e 100644 --- a/components/ILIAS/LTIProvider/service.xml +++ b/components/ILIAS/LTIProvider/service.xml @@ -13,8 +13,5 @@ - - - From 58071bd0e4791443b214fcd721502621aacbe181 Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Mon, 16 Dec 2024 10:50:48 +0100 Subject: [PATCH 22/39] Component/Logging: contribute cron jobs --- components/ILIAS/Logging/Logging.php | 6 +++++ .../class.ilLoggerCronCleanErrorFiles.php | 26 ++++++++++++------- components/ILIAS/Logging/service.xml | 3 --- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/components/ILIAS/Logging/Logging.php b/components/ILIAS/Logging/Logging.php index ea5202974232..c2369d94edf0 100644 --- a/components/ILIAS/Logging/Logging.php +++ b/components/ILIAS/Logging/Logging.php @@ -36,5 +36,11 @@ public function init( new \ilLoggingSetupAgent( $pull[\ILIAS\Refinery\Factory::class] ); + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \ilLoggerCronCleanErrorFiles( + 'components\\' . self::class, + $use[\ILIAS\Language\Language::class], + true + ); } } diff --git a/components/ILIAS/Logging/classes/error/class.ilLoggerCronCleanErrorFiles.php b/components/ILIAS/Logging/classes/error/class.ilLoggerCronCleanErrorFiles.php index e9b3eb734b21..4ba01555f120 100755 --- a/components/ILIAS/Logging/classes/error/class.ilLoggerCronCleanErrorFiles.php +++ b/components/ILIAS/Logging/classes/error/class.ilLoggerCronCleanErrorFiles.php @@ -1,9 +1,5 @@ lng->loadLanguageModule('logging'); + if (!$registration) { + $this->additionalConstruct(); + } + } + + private function additionalConstruct() { global $DIC; - - $this->lng = $DIC->language(); - $this->lng->loadLanguageModule("logging"); $this->settings = new ilSetting('log'); $this->error_settings = ilLoggingErrorSettings::getInstance(); } diff --git a/components/ILIAS/Logging/service.xml b/components/ILIAS/Logging/service.xml index 13cdbbe73f12..31e109a29e12 100755 --- a/components/ILIAS/Logging/service.xml +++ b/components/ILIAS/Logging/service.xml @@ -9,8 +9,5 @@ adm - - - From 32f9d4cd8115ffaa567ae188501fecb3f7877327 Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Mon, 16 Dec 2024 11:18:51 +0100 Subject: [PATCH 23/39] Component/WOPI: contribute cron jobs --- components/ILIAS/WOPI/WOPI.php | 7 +++++++ .../ILIAS/WOPI/classes/Cron/class.ilWOPICrawler.php | 12 +++++------- components/ILIAS/WOPI/service.xml | 3 --- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/components/ILIAS/WOPI/WOPI.php b/components/ILIAS/WOPI/WOPI.php index 25474b5063e0..06d17bb8de7c 100644 --- a/components/ILIAS/WOPI/WOPI.php +++ b/components/ILIAS/WOPI/WOPI.php @@ -49,5 +49,12 @@ public function init( $contribute[PublicAsset::class] = fn(): ComponentJS => new ComponentJS($this, "js/dist/wopi.min.js"); + + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \ilWOPICrawler( + self::class, + $use[\ILIAS\Language\Language::class], + $use[\ILIAS\Logging\LoggerFactory::class] + ); } } diff --git a/components/ILIAS/WOPI/classes/Cron/class.ilWOPICrawler.php b/components/ILIAS/WOPI/classes/Cron/class.ilWOPICrawler.php index 6be7766735b8..63df938bf0fd 100755 --- a/components/ILIAS/WOPI/classes/Cron/class.ilWOPICrawler.php +++ b/components/ILIAS/WOPI/classes/Cron/class.ilWOPICrawler.php @@ -31,20 +31,18 @@ */ class ilWOPICrawler extends ilCronJob { - private ilLanguage $language; private ilSetting $settings; private Crawler $crawler; private AppRepository $app_repository; private ActionRepository $action_repository; - public function __construct() + public function init(): void { + $this->lng->loadLanguageModule('wopi'); + global $DIC; - $this->language = $DIC->language(); - $this->language->loadLanguageModule('wopi'); $this->settings = $DIC->settings(); $this->crawler = new Crawler(); - $this->app_repository = new AppDBRepository($DIC->database()); $this->action_repository = new ActionDBRepository($DIC->database()); } @@ -56,12 +54,12 @@ public function getId(): string public function getTitle(): string { - return $this->language->txt('wopi_crawler_cronjob_title'); + return $this->lng->txt('wopi_crawler_cronjob_title'); } public function getDescription(): string { - return $this->language->txt('wopi_crawler_cronjob_description'); + return $this->lng->txt('wopi_crawler_cronjob_description'); } public function hasAutoActivation(): bool diff --git a/components/ILIAS/WOPI/service.xml b/components/ILIAS/WOPI/service.xml index 8e4540c995cf..70ce5def2865 100755 --- a/components/ILIAS/WOPI/service.xml +++ b/components/ILIAS/WOPI/service.xml @@ -1,7 +1,4 @@ - - - From 43f4dfabd46af57a1a04de9cf869247ae4b1112f Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Mon, 16 Dec 2024 11:19:05 +0100 Subject: [PATCH 24/39] Component/SystemCheck: contribute cron jobs --- components/ILIAS/SystemCheck/SystemCheck.php | 7 ++++++- .../SystemCheck/classes/class.ilSCCronTrash.php | 12 +++++------- components/ILIAS/SystemCheck/service.xml | 3 --- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/components/ILIAS/SystemCheck/SystemCheck.php b/components/ILIAS/SystemCheck/SystemCheck.php index fd0ea0f20f4c..99d4c2513017 100644 --- a/components/ILIAS/SystemCheck/SystemCheck.php +++ b/components/ILIAS/SystemCheck/SystemCheck.php @@ -32,6 +32,11 @@ public function init( array | \ArrayAccess &$pull, array | \ArrayAccess &$internal, ): void { - // ... + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \ilSCCronTrash( + self::class, + $use[\ILIAS\Language\Language::class], + $use[\ILIAS\Logging\LoggerFactory::class] + ); } } diff --git a/components/ILIAS/SystemCheck/classes/class.ilSCCronTrash.php b/components/ILIAS/SystemCheck/classes/class.ilSCCronTrash.php index 1a672f668066..a4ec49102a95 100755 --- a/components/ILIAS/SystemCheck/classes/class.ilSCCronTrash.php +++ b/components/ILIAS/SystemCheck/classes/class.ilSCCronTrash.php @@ -1,7 +1,5 @@ lng->loadLanguageModule('sysc'); - $this->lng = $DIC->language(); + global $DIC; $this->tree = $DIC->repositoryTree(); $this->objDefinition = $DIC['objDefinition']; - $this->lng->loadLanguageModule('sysc'); } public function getId(): string diff --git a/components/ILIAS/SystemCheck/service.xml b/components/ILIAS/SystemCheck/service.xml index 4bac44be71ff..7ea5cd687aac 100755 --- a/components/ILIAS/SystemCheck/service.xml +++ b/components/ILIAS/SystemCheck/service.xml @@ -7,8 +7,5 @@ adm - - - From 74668e6e4f8b70b2c294e4c1e5b1212d5974f77e Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Mon, 16 Dec 2024 11:19:40 +0100 Subject: [PATCH 25/39] Component/Survey: contribute cron jobs --- components/ILIAS/Survey/Survey.php | 6 ++++++ .../ILIAS/Survey/classes/class.ilSurveyCronNotification.php | 5 +---- components/ILIAS/Survey/module.xml | 3 --- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/components/ILIAS/Survey/Survey.php b/components/ILIAS/Survey/Survey.php index ad72be6ccc39..0e8cec9509fd 100644 --- a/components/ILIAS/Survey/Survey.php +++ b/components/ILIAS/Survey/Survey.php @@ -34,5 +34,11 @@ public function init( ): void { $contribute[Component\Resource\PublicAsset::class] = fn() => new Component\Resource\ComponentCSS($this, "survey.css"); + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \ilSurveyCronNotification( + self::class, + $use[\ILIAS\Language\Language::class], + $use[\ILIAS\Logging\LoggerFactory::class] + ); } } diff --git a/components/ILIAS/Survey/classes/class.ilSurveyCronNotification.php b/components/ILIAS/Survey/classes/class.ilSurveyCronNotification.php index b497ba03d0f1..5a5a28ee7a0b 100755 --- a/components/ILIAS/Survey/classes/class.ilSurveyCronNotification.php +++ b/components/ILIAS/Survey/classes/class.ilSurveyCronNotification.php @@ -26,14 +26,11 @@ */ class ilSurveyCronNotification extends ilCronJob { - protected ilLanguage $lng; protected ilTree $tree; - public function __construct() + public function init(): void { global $DIC; - - $this->lng = $DIC->language(); if (isset($DIC["tree"])) { $this->tree = $DIC->repositoryTree(); } diff --git a/components/ILIAS/Survey/module.xml b/components/ILIAS/Survey/module.xml index ef12edb39b7d..302a1754b883 100755 --- a/components/ILIAS/Survey/module.xml +++ b/components/ILIAS/Survey/module.xml @@ -21,9 +21,6 @@ adm - - - From 111ef6695612a40c6516811d66a5ecfd63f933ba Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Mon, 16 Dec 2024 11:20:57 +0100 Subject: [PATCH 26/39] Component/Skill: contribute cron jobs --- components/ILIAS/Skill/Skill.php | 7 +++++++ .../classes/class.ilSkillNotifications.php | 21 +++++++------------ components/ILIAS/Skill/service.xml | 3 --- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/components/ILIAS/Skill/Skill.php b/components/ILIAS/Skill/Skill.php index 14809de6b706..b76d446c447a 100644 --- a/components/ILIAS/Skill/Skill.php +++ b/components/ILIAS/Skill/Skill.php @@ -38,5 +38,12 @@ public function init( ); $contribute[Component\Resource\PublicAsset::class] = fn() => new Component\Resource\ComponentJS($this, "SkillEntries.js"); + + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \ilSkillNotifications( + self::class, + $use[\ILIAS\Language\Language::class], + $use[\ILIAS\Logging\LoggerFactory::class] + ); } } diff --git a/components/ILIAS/Skill/classes/class.ilSkillNotifications.php b/components/ILIAS/Skill/classes/class.ilSkillNotifications.php index e3372acc0ad5..4b2ebe2f7e36 100755 --- a/components/ILIAS/Skill/classes/class.ilSkillNotifications.php +++ b/components/ILIAS/Skill/classes/class.ilSkillNotifications.php @@ -1,7 +1,5 @@ lng->loadLanguageModule("skll"); + global $DIC; - $this->lng = $DIC->language(); if (isset($DIC["ilUser"])) { $this->user = $DIC->user(); } @@ -59,16 +58,12 @@ public function getId(): string public function getTitle(): string { - $lng = $this->lng; - $lng->loadLanguageModule("skll"); - return $lng->txt("skll_skill_notification"); + return $this->lng->txt("skll_skill_notification"); } public function getDescription(): string { - $lng = $this->lng; - $lng->loadLanguageModule("skll"); - return $lng->txt("skll_skill_notification_desc"); + return $this->lng->txt("skll_skill_notification_desc"); } public function getDefaultScheduleType(): CronJobScheduleType diff --git a/components/ILIAS/Skill/service.xml b/components/ILIAS/Skill/service.xml index 8379fd2e1879..c9097fddbd02 100755 --- a/components/ILIAS/Skill/service.xml +++ b/components/ILIAS/Skill/service.xml @@ -19,7 +19,4 @@ - - - From eab7e9f96d4df9eef912000ed37a7af69e5751ee Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Mon, 16 Dec 2024 11:21:17 +0100 Subject: [PATCH 27/39] Component/Filesystem: contribute cron jobs --- components/ILIAS/Filesystem/Filesystem.php | 7 +++++++ .../class.ilFileSystemCleanTempDirCron.php | 20 +++++-------------- components/ILIAS/Filesystem/service.xml | 3 --- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/components/ILIAS/Filesystem/Filesystem.php b/components/ILIAS/Filesystem/Filesystem.php index 421dc2883e95..4a9528c07715 100644 --- a/components/ILIAS/Filesystem/Filesystem.php +++ b/components/ILIAS/Filesystem/Filesystem.php @@ -40,5 +40,12 @@ public function init( new \ilFileSystemSetupAgent( $pull[Factory::class] ); + + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \ilFileSystemCleanTempDirCron( + self::class, + $use[\ILIAS\Language\Language::class], + $use[\ILIAS\Logging\LoggerFactory::class] + ); } } diff --git a/components/ILIAS/Filesystem/classes/class.ilFileSystemCleanTempDirCron.php b/components/ILIAS/Filesystem/classes/class.ilFileSystemCleanTempDirCron.php index 4c4b19cacbe5..816147ace95d 100755 --- a/components/ILIAS/Filesystem/classes/class.ilFileSystemCleanTempDirCron.php +++ b/components/ILIAS/Filesystem/classes/class.ilFileSystemCleanTempDirCron.php @@ -28,29 +28,19 @@ class ilFileSystemCleanTempDirCron extends ilCronJob { protected Filesystem $filesystem; - - protected ilLanguage $language; - protected ilLogger $logger; - /** - * @inheritDoc - */ - public function __construct() + public function init(): void { + $this->logger = $this->logger_factory->getRootLogger(); + /** * @var $DIC Container */ global $DIC; - if ($DIC->offsetExists('lng')) { - $this->language = $DIC['lng']; - } if ($DIC->offsetExists('filesystem')) { $this->filesystem = $DIC->filesystem()->temp(); } - if ($DIC->offsetExists('ilLoggerFactory')) { - $this->logger = $DIC->logger()->root(); - } } private function initDependencies(): void @@ -64,12 +54,12 @@ public function getId(): string public function getTitle(): string { - return $this->language->txt('file_system_clean_temp_dir_cron'); + return $this->lng->txt('file_system_clean_temp_dir_cron'); } public function getDescription(): string { - return $this->language->txt("file_system_clean_temp_dir_cron_info"); + return $this->lng->txt("file_system_clean_temp_dir_cron_info"); } public function hasAutoActivation(): bool diff --git a/components/ILIAS/Filesystem/service.xml b/components/ILIAS/Filesystem/service.xml index dc131c3873cf..c14d8bee117a 100755 --- a/components/ILIAS/Filesystem/service.xml +++ b/components/ILIAS/Filesystem/service.xml @@ -3,7 +3,4 @@ id="filesys"> - - - From ff226c1cf640b4e9fbda684cd3e8d69b5ba10399 Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Mon, 16 Dec 2024 11:21:36 +0100 Subject: [PATCH 28/39] Component/Course: contribute cron jobs --- components/ILIAS/Course/Course.php | 6 ++++++ .../classes/class.ilTimingsCronReminder.php | 21 +++++++------------ components/ILIAS/Course/module.xml | 3 --- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/components/ILIAS/Course/Course.php b/components/ILIAS/Course/Course.php index 085ff5185c3c..0affdbf602c9 100644 --- a/components/ILIAS/Course/Course.php +++ b/components/ILIAS/Course/Course.php @@ -40,5 +40,11 @@ public function init( new \ilCourseSetupAgent( $pull[\ILIAS\Refinery\Factory::class] ); + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \ilTimingsCronReminder( + self::class, + $use[\ILIAS\Language\Language::class], + $use[\ILIAS\Logging\LoggerFactory::class] + ); } } diff --git a/components/ILIAS/Course/classes/class.ilTimingsCronReminder.php b/components/ILIAS/Course/classes/class.ilTimingsCronReminder.php index 18b6bd4a342f..d7031c0ec91d 100755 --- a/components/ILIAS/Course/classes/class.ilTimingsCronReminder.php +++ b/components/ILIAS/Course/classes/class.ilTimingsCronReminder.php @@ -1,9 +1,5 @@ log = $DIC->logger()->crs(); - $this->lng = $DIC->language(); $this->lng->loadLanguageModule('crs'); + $this->log = $this->logger_factory->getLogger('crs'); + + global $DIC; $this->db = $DIC->database(); $this->obj_data_cache = $DIC['ilObjDataCache']; diff --git a/components/ILIAS/Course/module.xml b/components/ILIAS/Course/module.xml index 582678d6a00a..f68168f120de 100755 --- a/components/ILIAS/Course/module.xml +++ b/components/ILIAS/Course/module.xml @@ -41,9 +41,6 @@ - - - From 1771a88ee4cfef859e376bc7990f80f0d783c860 Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Mon, 16 Dec 2024 11:21:59 +0100 Subject: [PATCH 29/39] Component/CmiXapi: contribute cron jobs --- components/ILIAS/CmiXapi/CmiXapi.php | 12 +++++++++++ .../classes/class.ilCmiXapiDelCron.php | 20 ++++++++----------- .../classes/class.ilXapiResultsCronjob.php | 14 +++++-------- components/ILIAS/CmiXapi/module.xml | 4 ---- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/components/ILIAS/CmiXapi/CmiXapi.php b/components/ILIAS/CmiXapi/CmiXapi.php index 082632f6ef66..923de6dc1553 100644 --- a/components/ILIAS/CmiXapi/CmiXapi.php +++ b/components/ILIAS/CmiXapi/CmiXapi.php @@ -36,5 +36,17 @@ public function init( new \ilCmiXapiSetupAgent( $pull[\ILIAS\Refinery\Factory::class] ); + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \ilXapiResultsCronjob( + self::class, + $use[\ILIAS\Language\Language::class], + $use[\ILIAS\Logging\LoggerFactory::class] + ); + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \ilCmiXapiDelCron( + self::class, + $use[\ILIAS\Language\Language::class], + $use[\ILIAS\Logging\LoggerFactory::class] + ); } } diff --git a/components/ILIAS/CmiXapi/classes/class.ilCmiXapiDelCron.php b/components/ILIAS/CmiXapi/classes/class.ilCmiXapiDelCron.php index aa275055763c..749f68e452a6 100755 --- a/components/ILIAS/CmiXapi/classes/class.ilCmiXapiDelCron.php +++ b/components/ILIAS/CmiXapi/classes/class.ilCmiXapiDelCron.php @@ -39,19 +39,15 @@ class ilCmiXapiDelCron extends ilCronJob private \ILIAS\DI\Container $dic; - public function __construct() + public function init(): void { - global $DIC; /* @var \ILIAS\DI\Container $DIC */ - $this->dic = $DIC; - - $DIC->language()->loadLanguageModule('cmix'); - - $this->log = ilLoggerFactory::getLogger('cmix'); + $this->lng->loadLanguageModule('cmix'); + $this->log = $this->logger_factory->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; @@ -67,12 +63,12 @@ public function getId(): string public function getTitle(): string { - return $this->dic->language()->txt("cron_xapi_del"); + return $this->lng->txt("cron_xapi_del"); } public function getDescription(): string { - return $this->dic->language()->txt("cron_xapi_del_desc"); + return $this->lng->txt("cron_xapi_del_desc"); } /** @@ -224,7 +220,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 @@ -239,7 +235,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 { diff --git a/components/ILIAS/CmiXapi/classes/class.ilXapiResultsCronjob.php b/components/ILIAS/CmiXapi/classes/class.ilXapiResultsCronjob.php index bbc5a70ab3ad..153e5fee9943 100755 --- a/components/ILIAS/CmiXapi/classes/class.ilXapiResultsCronjob.php +++ b/components/ILIAS/CmiXapi/classes/class.ilXapiResultsCronjob.php @@ -40,14 +40,10 @@ class ilXapiResultsCronjob extends ilCronJob private \ILIAS\DI\Container $dic; - public function __construct() + public function init(): void { - global $DIC; /* @var \ILIAS\DI\Container $DIC */ - $this->dic = $DIC; - - $DIC->language()->loadLanguageModule('cmix'); - - $this->log = ilLoggerFactory::getLogger('cmix'); + $this->lng->loadLanguageModule('cmix'); + $this->log = $this->logger_factory->getLogger('cmix'); $this->initThisRunTS(); $this->readLastRunTS(); @@ -88,12 +84,12 @@ public function getId(): string public function getTitle(): string { - return $this->dic->language()->txt("cron_xapi_results_evaluation"); + return $this->lng->txt("cron_xapi_results_evaluation"); } public function getDescription(): string { - return $this->dic->language()->txt("cron_xapi_results_evaluation_desc"); + return $this->lng->txt("cron_xapi_results_evaluation_desc"); } public function hasAutoActivation(): bool diff --git a/components/ILIAS/CmiXapi/module.xml b/components/ILIAS/CmiXapi/module.xml index 2406a25b12b2..822525c81ae2 100755 --- a/components/ILIAS/CmiXapi/module.xml +++ b/components/ILIAS/CmiXapi/module.xml @@ -31,10 +31,6 @@ - - - - From dc7210be33ebb1dd43f2db2a062b10f855438b3b Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Mon, 16 Dec 2024 12:23:16 +0100 Subject: [PATCH 30/39] fix copyrights --- .../ILIAS/COPage/Cron/class.ilCleanCOPageHistoryCronjob.php | 4 ++-- .../ConsultationHours/class.ilConsultationHourCron.php | 4 ++-- .../ILIAS/CmiXapi/classes/class.ilXapiResultsCronjob.php | 5 +++-- .../Setup/class.ilComponentDefinitionsStoredObjective.php | 1 + 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/components/ILIAS/COPage/Cron/class.ilCleanCOPageHistoryCronjob.php b/components/ILIAS/COPage/Cron/class.ilCleanCOPageHistoryCronjob.php index 7855ddfb55c2..496343f1ed06 100755 --- a/components/ILIAS/COPage/Cron/class.ilCleanCOPageHistoryCronjob.php +++ b/components/ILIAS/COPage/Cron/class.ilCleanCOPageHistoryCronjob.php @@ -1,7 +1,5 @@ Date: Mon, 16 Dec 2024 13:24:45 +0100 Subject: [PATCH 31/39] Cron: update readme --- components/ILIAS/Cron/README.md | 41 ++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/components/ILIAS/Cron/README.md b/components/ILIAS/Cron/README.md index 6d39ebdb0b29..2751a6f24b34 100755 --- a/components/ILIAS/Cron/README.md +++ b/components/ILIAS/Cron/README.md @@ -21,27 +21,32 @@ described in [RFC 2119](https://www.ietf.org/rfc/rfc2119.txt). ## Implementing and Configuring a Cron-Job To give more control of if and when cron-jobs are executed to administrators a 2nd implementation of cron-jobs -has been added to ILIAS 4.4+. All existing cron-jobs have been migrated and thus moved to their respective modules -and services. The top-level directory "cron/" will probably be kept because of cron.php but should otherwise be empty -at some point. +has been added to ILIAS 4.4+. All existing cron-jobs have been migrated and thus moved to their respective component. +The top-level directory "cron/" was removed. ### Providing a Cron-Job -A module or service has to "announce" its cron-jobs to the system by adding them to their respective -module.xml or service.xml. - -- The job id has to be unique. -- An optional path can be added if the module/service directory layout differs from the ILIAS standard. - +A component has to contribute its cron-jobs to the system in its Component-class: ```php - - - ... - - - - +class MyComponent implements Component\Component +{ + public function init( + array | \ArrayAccess &$define, + array | \ArrayAccess &$implement, + array | \ArrayAccess &$use, + array | \ArrayAccess &$contribute, + array | \ArrayAccess &$seek, + array | \ArrayAccess &$provide, + array | \ArrayAccess &$pull, + array | \ArrayAccess &$internal, + ): void { + $contribute[\ILIAS\Cron\CronJob::class] = static fn() => + new \MyComponentCronJob( + 'components\\' . self::class, + $use[\ILIAS\Language\Language::class] + ); + } +} ``` There are 3 basic concepts: cron-job, schedule and cron-result. Using them as intended should make testing @@ -176,7 +181,7 @@ So as mentioned above the cron-tab can safely be set to every few minutes. In order to execute the cron job manager, the following command MUST be used: ```shell -/usr/bin/php [PATH_TO_ILIAS]/cron/cron.php run-jobs run-jobs +/usr/bin/php [PATH_TO_ILIAS]/cli/cron.php run-jobs ``` The `` MUST be a valid (but arbitrary) user account of the ILIAS installation. From f7aa2373c6585537810fa1a89471cb3409a365bf Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Thu, 2 Jan 2025 10:52:07 +0100 Subject: [PATCH 32/39] Cron: init with CronRegistry and LoggerFactory --- components/ILIAS/Cron/Cron.php | 11 ++ components/ILIAS/Cron/README.md | 2 +- .../Setup/class.ilCronJobSetupAgent.php | 16 ++- ...ss.ilCronJobsMetricsCollectedObjective.php | 112 ------------------ .../class.ilCronJobsRegisteredObjective.php | 17 ++- .../ILIAS/Cron/classes/class.ilCronJob.php | 9 ++ .../Cron/classes/class.ilCronJobEntity.php | 16 ++- .../classes/class.ilCronJobRepositoryImpl.php | 91 ++++---------- .../Cron/classes/class.ilCronManagerImpl.php | 1 + .../Cron/interfaces/interface.CronJob.php | 6 + .../interface.ilCronJobRepository.php | 3 +- components/ILIAS/Cron/src/CronRegistry.php | 37 ++++++ components/ILIAS/Cron/src/Registry.php | 26 ++++ .../ILIAS/Logging/src/LoggerFactory.php | 27 +++++ 14 files changed, 184 insertions(+), 190 deletions(-) delete mode 100644 components/ILIAS/Cron/classes/Setup/class.ilCronJobsMetricsCollectedObjective.php create mode 100644 components/ILIAS/Cron/src/CronRegistry.php create mode 100644 components/ILIAS/Cron/src/Registry.php create mode 100644 components/ILIAS/Logging/src/LoggerFactory.php diff --git a/components/ILIAS/Cron/Cron.php b/components/ILIAS/Cron/Cron.php index b13e9efc8b19..4c719055ca76 100644 --- a/components/ILIAS/Cron/Cron.php +++ b/components/ILIAS/Cron/Cron.php @@ -36,5 +36,16 @@ public function init( new \ilCronJobSetupAgent( $seek[\ILIAS\Cron\CronJob::class] ); + + $define[] = Cron\Registry::class; + + $provide[Cron\Registry::class] = static fn() => + $internal[Cron\CronRegistry::class]; + + $internal[Cron\CronRegistry::class] = static fn() => + new Cron\CronRegistry( + $seek[\ILIAS\Cron\CronJob::class] + ); + } } diff --git a/components/ILIAS/Cron/README.md b/components/ILIAS/Cron/README.md index 2751a6f24b34..4eead8c1edae 100755 --- a/components/ILIAS/Cron/README.md +++ b/components/ILIAS/Cron/README.md @@ -42,7 +42,7 @@ class MyComponent implements Component\Component ): void { $contribute[\ILIAS\Cron\CronJob::class] = static fn() => new \MyComponentCronJob( - 'components\\' . self::class, + self::class, $use[\ILIAS\Language\Language::class] ); } diff --git a/components/ILIAS/Cron/classes/Setup/class.ilCronJobSetupAgent.php b/components/ILIAS/Cron/classes/Setup/class.ilCronJobSetupAgent.php index 517348e5f43e..707597a55767 100644 --- a/components/ILIAS/Cron/classes/Setup/class.ilCronJobSetupAgent.php +++ b/components/ILIAS/Cron/classes/Setup/class.ilCronJobSetupAgent.php @@ -23,8 +23,6 @@ class ilCronJobSetupAgent implements Setup\Agent { - use Setup\Agent\HasNoNamedObjective; - public function __construct( private array $cronjobs ) { @@ -61,11 +59,23 @@ public function getBuildObjective(): Setup\Objective public function getStatusObjective(Setup\Metrics\Storage $storage): Setup\Objective { - return new ilCronJobsMetricsCollectedObjective($storage); + return new Setup\Objective\NullObjective(); } public function getMigrations(): array { return []; } + + public function getNamedObjectives(?Setup\Config $config = null): array + { + return [ + 'registerCronJobs' => new Setup\ObjectiveConstructor( + 'registers cron jobs', + fn(): Setup\Objective => new ilCronjobsRegisteredObjective( + $this->cronjobs + ) + ) + ]; + } } diff --git a/components/ILIAS/Cron/classes/Setup/class.ilCronJobsMetricsCollectedObjective.php b/components/ILIAS/Cron/classes/Setup/class.ilCronJobsMetricsCollectedObjective.php deleted file mode 100644 index 31a2d776640a..000000000000 --- a/components/ILIAS/Cron/classes/Setup/class.ilCronJobsMetricsCollectedObjective.php +++ /dev/null @@ -1,112 +0,0 @@ -getResource(Setup\Environment::RESOURCE_DATABASE); - $component_repository = $environment->getResource(Setup\Environment::RESOURCE_COMPONENT_REPOSITORY); - $component_factory = $environment->getResource(Setup\Environment::RESOURCE_COMPONENT_FACTORY); - $settings_factory = $environment->getResource(Setup\Environment::RESOURCE_SETTINGS_FACTORY); - - $mock_lng = new class () implements \ILIAS\Language\Language { - public function txt(string $a_topic, string $a_default_lang_fallback_mod = ""): string - { - return ''; - } - public function loadLanguageModule(string $a_module): void - { - } - }; - - $repo = new ilCronJobRepositoryImpl( - $db, - $settings_factory->settingsFor(), - new ILIAS\components\Logging\NullLogger(), - $component_repository, - $component_factory, - $mock_lng - ); - - //@var ilCronJobEntity[] - $collection = $repo->findAll()->toArray(); - $cron_jobs = []; - foreach ($collection as $entity) { - $active = new Setup\Metrics\Metric( - Setup\Metrics\Metric::STABILITY_VOLATILE, - Setup\Metrics\Metric::TYPE_BOOL, - (bool) $entity->getJobStatus(), - "Is the job active?" - ); - $component = new Setup\Metrics\Metric( - Setup\Metrics\Metric::STABILITY_STABLE, - Setup\Metrics\Metric::TYPE_TEXT, - $entity->getComponent() - ); - $cron_jobs[$entity->getJobId()] = new Setup\Metrics\Metric( - Setup\Metrics\Metric::STABILITY_MIXED, - Setup\Metrics\Metric::TYPE_COLLECTION, - [ - "component" => $component, - "active" => $active - ] - ); - } - $cron_jobs = new Setup\Metrics\Metric( - Setup\Metrics\Metric::STABILITY_MIXED, - Setup\Metrics\Metric::TYPE_COLLECTION, - $cron_jobs - ); - - $cron_jobs_count = new Setup\Metrics\Metric( - Setup\Metrics\Metric::STABILITY_STABLE, - Setup\Metrics\Metric::TYPE_GAUGE, - count($collection) - ); - $storage->store( - "number of cron jobs", - $cron_jobs_count - ); - $storage->store( - "cron jobs", - $cron_jobs - ); - } -} diff --git a/components/ILIAS/Cron/classes/Setup/class.ilCronJobsRegisteredObjective.php b/components/ILIAS/Cron/classes/Setup/class.ilCronJobsRegisteredObjective.php index a42aa88a450d..1f6d606e75a4 100644 --- a/components/ILIAS/Cron/classes/Setup/class.ilCronJobsRegisteredObjective.php +++ b/components/ILIAS/Cron/classes/Setup/class.ilCronJobsRegisteredObjective.php @@ -57,6 +57,8 @@ public function isNotable(): bool public function getPreconditions(Setup\Environment $environment): array { return [ + new \ilSettingsFactoryExistsObjective(), + new \ilComponentFactoryExistsObjective(), new \ilDatabaseUpdatedObjective() ]; } @@ -82,15 +84,28 @@ public function txt(string $a_topic, string $a_default_lang_fallback_mod = ""): public function loadLanguageModule(string $a_module): void { } + public function getLangKey(): string + { + } + public function toJS($key): void + { + } }; + $mock_logger_factory = new class () implements \ILIAS\Logging\LoggerFactory { + }; + + $registry = new ILIAS\Cron\CronRegistry($this->cronjobs); + $repo = new ilCronJobRepositoryImpl( + $registry, $db, $settings_factory->settingsFor(), new ILIAS\components\Logging\NullLogger(), $component_repository, $component_factory, - $mock_lng + $mock_lng, + $mock_logger_factory ); $repo->unregisterAllJobs(); diff --git a/components/ILIAS/Cron/classes/class.ilCronJob.php b/components/ILIAS/Cron/classes/class.ilCronJob.php index 0409d8ae1382..6ddb7c626727 100755 --- a/components/ILIAS/Cron/classes/class.ilCronJob.php +++ b/components/ILIAS/Cron/classes/class.ilCronJob.php @@ -30,9 +30,18 @@ abstract class ilCronJob implements CronJob public function __construct( protected readonly string $component, protected readonly \ILIAS\Language\Language $lng, + protected readonly \ILIAS\Logging\LoggerFactory $logger_factory, ) { } + /** + * init is called when actually using the job; + * once the jobs are properly constructed via Component,this is obsolete. + */ + public function init(): void + { + } + public function getComponent(): string { return $this->component; diff --git a/components/ILIAS/Cron/classes/class.ilCronJobEntity.php b/components/ILIAS/Cron/classes/class.ilCronJobEntity.php index 4c253cb0a816..624ac777f0e8 100755 --- a/components/ILIAS/Cron/classes/class.ilCronJobEntity.php +++ b/components/ILIAS/Cron/classes/class.ilCronJobEntity.php @@ -50,16 +50,24 @@ class ilCronJobEntity */ public function __construct(private readonly ilCronJob $job, array $record, private readonly bool $isPlugin = false) { - $this->mapRecord($record); + $job->init(); + $this->mapRecord($job, $record); } /** * @param array $record */ - private function mapRecord(array $record): void + private function mapRecord(ilCronJob $job, array $record): void { - $this->jobId = (string) $record['job_id']; - $this->component = (string) $record['component']; + if (! array_key_exists('job_id', $record)) { + //TODO: remove! + var_dump($record); + die(); + } + //$this->jobId = (string) $record['job_id']; + //$this->component = (string) $record['component']; + $this->jobId = $job->getId(); + $this->component = $job->getComponent(); $this->scheduleType = is_numeric($record['schedule_type']) ? CronJobScheduleType::tryFrom((int) $record['schedule_type']) : null; $this->scheduleValue = (int) $record['schedule_value']; $this->jobStatus = (int) $record['job_status']; diff --git a/components/ILIAS/Cron/classes/class.ilCronJobRepositoryImpl.php b/components/ILIAS/Cron/classes/class.ilCronJobRepositoryImpl.php index d10ff81ceda3..b975ed7075c4 100755 --- a/components/ILIAS/Cron/classes/class.ilCronJobRepositoryImpl.php +++ b/components/ILIAS/Cron/classes/class.ilCronJobRepositoryImpl.php @@ -19,64 +19,34 @@ declare(strict_types=1); use ILIAS\Cron\Schedule\CronJobScheduleType; +use ILIAS\Cron\Registry; class ilCronJobRepositoryImpl implements ilCronJobRepository { private const TYPE_PLUGINS = 'Plugins'; public function __construct( + private readonly Registry $registry, private readonly ilDBInterface $db, private readonly ilSetting $setting, private readonly ilLogger $logger, private readonly ilComponentRepository $componentRepository, private readonly ilComponentFactory $componentFactory, - private readonly ILIAS\Language\Language $lng + private readonly ILIAS\Language\Language $lng, + private readonly ILIAS\Logging\LoggerFactory $logger_factory ) { } public function getJobInstanceById(string $id): ?ilCronJob { - // plugin - if (str_starts_with($id, 'pl__')) { - $parts = explode('__', $id); - $pl_name = $parts[1]; - $job_id = $parts[2]; - - foreach ($this->componentRepository->getPlugins() as $pl) { - if ($pl->getName() !== $pl_name || !$pl->isActive()) { - continue; - } - - $plugin = $this->componentFactory->getPlugin($pl->getId()); - if (!$plugin instanceof ilCronJobProvider) { - continue; - } - - try { - $job = $plugin->getCronJobInstance($job_id); - - // should never happen but who knows... - $jobs_data = $this->getCronJobData($job_id); - if ($jobs_data === []) { - // as job is not 'imported' from xml - $this->createDefaultEntry($job, $pl_name, self::TYPE_PLUGINS, ''); - } - return $job; - } catch (OutOfBoundsException) { - // Maybe a job was removed from plugin, renamed etc. - } - break; - } - } else { - $jobs_data = $this->getCronJobData($id); - if ($jobs_data !== [] && $jobs_data[0]['job_id'] === $id) { - return $this->getJobInstance( - $jobs_data[0]['job_id'], - $jobs_data[0]['component'], - $jobs_data[0]['class'] - ); - } + $jobs_data = $this->getCronJobData($id); + if ($jobs_data !== [] && $jobs_data[0]['job_id'] === $id) { + return $this->getJobInstance( + $jobs_data[0]['job_id'], + $jobs_data[0]['component'], + $jobs_data[0]['class'] + ); } $this->logger->info('CRON - job ' . $id . ' seems invalid or is inactive'); @@ -87,19 +57,15 @@ public function getJobInstanceById(string $id): ?ilCronJob public function getJobInstance( string $a_id, string $a_component, - string $a_class, - bool $isCreationContext = false + string $a_class ): ?ilCronJob { + if (class_exists($a_class)) { - if ($isCreationContext) { - $refl = new ReflectionClass($a_class); - $job = $refl->newInstanceWithoutConstructor(); - } else { - $job = new $a_class( - $a_component, - $this->lng - ); - } + $job = new $a_class( + $a_component, + $this->lng, + $this->logger_factory + ); if ($job instanceof ilCronJob && $job->getId() === $a_id) { return $job; @@ -151,7 +117,8 @@ public function registerJob( return; } - $job = $this->getJobInstance($a_id, $a_component, $a_class, true); + //$job = $this->getJobInstance($a_id, $a_component, $a_class, true); + $job = $this->getJobInstance($a_id, $a_component, $a_class); if ($job) { $this->createDefaultEntry($job, $a_component, $a_class, $a_path); } @@ -401,21 +368,11 @@ public function findAll(): ilCronJobCollection { $collection = new ilCronJobEntities(); - foreach ($this->getCronJobData() as $item) { - $job = $this->getJobInstance( - $item['job_id'], - $item['component'], - $item['class'] - ); - if ($job) { - $collection->add(new ilCronJobEntity($job, $item)); - } + foreach ($this->registry->getAllJobs() as $job) { + $job_data = $this->getCronJobData($job->getId()); + $entity = new ilCronJobEntity($job, array_shift($job_data)); + $collection->add($entity); } - - foreach ($this->getPluginJobs() as $item) { - $collection->add(new ilCronJobEntity($item[0], $item[1], true)); - } - return $collection; } } diff --git a/components/ILIAS/Cron/classes/class.ilCronManagerImpl.php b/components/ILIAS/Cron/classes/class.ilCronManagerImpl.php index cc8c8fd32911..10f4941f9704 100755 --- a/components/ILIAS/Cron/classes/class.ilCronManagerImpl.php +++ b/components/ILIAS/Cron/classes/class.ilCronManagerImpl.php @@ -166,6 +166,7 @@ private function runJob(ilCronJob $job, ilObjUser $actor, ?array $jobData = null $ts_in = $this->getMicrotime(); try { + $job->init(); $result = $job->run(); } catch (Throwable $e) { $result = new ilCronJobResult(); diff --git a/components/ILIAS/Cron/interfaces/interface.CronJob.php b/components/ILIAS/Cron/interfaces/interface.CronJob.php index 16cc54f7d082..a7e963534fe3 100644 --- a/components/ILIAS/Cron/interfaces/interface.CronJob.php +++ b/components/ILIAS/Cron/interfaces/interface.CronJob.php @@ -29,4 +29,10 @@ public function getDescription(): string; public function getScheduleType(): ?Schedule\CronJobScheduleType; public function getScheduleValue(): ?int; public function run(): \ilCronJobResult; + + /** + * initialize further dependencies of the job; + * once the jobs are properly constructed via Component,this is obsolete. + */ + public function init(): void; } diff --git a/components/ILIAS/Cron/interfaces/interface.ilCronJobRepository.php b/components/ILIAS/Cron/interfaces/interface.ilCronJobRepository.php index 0aa9a3a7110c..28e9db193648 100755 --- a/components/ILIAS/Cron/interfaces/interface.ilCronJobRepository.php +++ b/components/ILIAS/Cron/interfaces/interface.ilCronJobRepository.php @@ -27,8 +27,7 @@ public function getJobInstanceById(string $id): ?ilCronJob; public function getJobInstance( string $a_id, string $a_component, - string $a_class, - bool $isCreationContext = false + string $a_class ): ?ilCronJob; /** diff --git a/components/ILIAS/Cron/src/CronRegistry.php b/components/ILIAS/Cron/src/CronRegistry.php new file mode 100644 index 000000000000..49ed81acce6b --- /dev/null +++ b/components/ILIAS/Cron/src/CronRegistry.php @@ -0,0 +1,37 @@ +jobs; + } +} diff --git a/components/ILIAS/Cron/src/Registry.php b/components/ILIAS/Cron/src/Registry.php new file mode 100644 index 000000000000..fa4bc765e991 --- /dev/null +++ b/components/ILIAS/Cron/src/Registry.php @@ -0,0 +1,26 @@ + Date: Thu, 2 Jan 2025 14:13:17 +0100 Subject: [PATCH 33/39] Cron: initialisation --- components/ILIAS/Init/Init.php | 1 + components/ILIAS/Init/classes/class.ilInitialisation.php | 4 +++- components/ILIAS/Init/src/AllModernComponents.php | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/components/ILIAS/Init/Init.php b/components/ILIAS/Init/Init.php index 0f55e64f96fd..a2501c2135a0 100644 --- a/components/ILIAS/Init/Init.php +++ b/components/ILIAS/Init/Init.php @@ -120,6 +120,7 @@ public function init( $pull[\ILIAS\UI\Implementation\Component\Progress\Factory::class], $pull[\ILIAS\UI\Implementation\Component\Progress\State\Factory::class], $pull[\ILIAS\UI\Implementation\Component\Progress\State\Bar\Factory::class], + $pull[\ILIAS\Cron\Registry::class], ); } } diff --git a/components/ILIAS/Init/classes/class.ilInitialisation.php b/components/ILIAS/Init/classes/class.ilInitialisation.php index 36c2e3800c2b..a239b8372ed0 100755 --- a/components/ILIAS/Init/classes/class.ilInitialisation.php +++ b/components/ILIAS/Init/classes/class.ilInitialisation.php @@ -762,12 +762,14 @@ protected static function initCron(\ILIAS\DI\Container $c): void { $c['cron.repository'] = static function (\ILIAS\DI\Container $c): ilCronJobRepository { return new ilCronJobRepositoryImpl( + $c['cron.registry'], $c->database(), $c->settings(), $c->logger()->cron(), $c['component.repository'], $c['component.factory'], - $c['lng'] + $c['lng'], + $c['ilLoggerFactory'] ); }; diff --git a/components/ILIAS/Init/src/AllModernComponents.php b/components/ILIAS/Init/src/AllModernComponents.php index 7b302bd04e2a..8a926d3602bd 100644 --- a/components/ILIAS/Init/src/AllModernComponents.php +++ b/components/ILIAS/Init/src/AllModernComponents.php @@ -91,6 +91,7 @@ public function __construct( protected \ILIAS\UI\Implementation\Component\Progress\Factory $ui_progress_factory, protected \ILIAS\UI\Implementation\Component\Progress\State\Factory $ui_progress_state_factory, protected \ILIAS\UI\Implementation\Component\Progress\State\Bar\Factory $ui_progress_state_bar_factory, + protected \ILIAS\Cron\Registry $cron_registry, ) { } @@ -165,6 +166,8 @@ protected function populateComponentsInLegacyEnvironment(\Pimple\Container $DIC) $DIC['ui.factory.input.field'] = fn() => $this->ui_factory_input_field; $DIC['ui.factory'] = fn() => $this->ui_factory; $DIC['ui.renderer'] = fn() => $this->ui_renderer; + + $DIC['cron.registry'] = fn() => $this->cron_registry; } public function getName(): string From a290a9683863d292f97d22eaab5ecb891dcae691 Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Thu, 2 Jan 2025 14:14:21 +0100 Subject: [PATCH 34/39] (Cron)/Logging: provide logger factory --- components/ILIAS/Logging/Logging.php | 51 ++++++++++++++++++- .../class.ilLoggerCronCleanErrorFiles.php | 14 +---- .../classes/public/class.ilLoggerFactory.php | 20 ++++---- .../ILIAS/Logging/src/LoggerFactory.php | 1 - 4 files changed, 62 insertions(+), 24 deletions(-) diff --git a/components/ILIAS/Logging/Logging.php b/components/ILIAS/Logging/Logging.php index c2369d94edf0..f54b812f834c 100644 --- a/components/ILIAS/Logging/Logging.php +++ b/components/ILIAS/Logging/Logging.php @@ -32,15 +32,62 @@ public function init( array | \ArrayAccess &$pull, array | \ArrayAccess &$internal, ): void { + $define[] = \ILIAS\Logging\LoggerFactory::class; + + $implement[\ILIAS\Logging\LoggerFactory::class] = static fn() => + $internal[\ilLoggerFactory::class]; + $contribute[\ILIAS\Setup\Agent::class] = static fn() => new \ilLoggingSetupAgent( $pull[\ILIAS\Refinery\Factory::class] ); $contribute[\ILIAS\Cron\CronJob::class] = static fn() => new \ilLoggerCronCleanErrorFiles( - 'components\\' . self::class, + self::class, $use[\ILIAS\Language\Language::class], - true + $use[\ILIAS\Logging\LoggerFactory::class] ); + $internal[\ilLoggerFactory::class] = static fn() => + \ilLoggerFactory::getInstance( + $internal[\ilLoggingSettings::class] + ); + + $internal[\ilLoggingSettings::class] = static fn() => + new class () implements \ilLoggingSettings { + public function isEnabled(): bool + { + return false; + } + public function getLogDir(): string + { + } + public function getLogFile(): string + { + } + public function getLevel(): int + { + } + public function getLevelByComponent(string $a_component_id): int + { + } + public function getCacheLevel(): int + { + } + public function isCacheEnabled(): bool + { + } + public function isMemoryUsageEnabled(): bool + { + } + public function isBrowserLogEnabled(): bool + { + } + public function isBrowserLogEnabledForUser(string $a_login): bool + { + } + public function getBrowserLogUsers(): array + { + } + }; } } diff --git a/components/ILIAS/Logging/classes/error/class.ilLoggerCronCleanErrorFiles.php b/components/ILIAS/Logging/classes/error/class.ilLoggerCronCleanErrorFiles.php index 4ba01555f120..da29f33ec2f2 100755 --- a/components/ILIAS/Logging/classes/error/class.ilLoggerCronCleanErrorFiles.php +++ b/components/ILIAS/Logging/classes/error/class.ilLoggerCronCleanErrorFiles.php @@ -27,20 +27,10 @@ class ilLoggerCronCleanErrorFiles extends ilCronJob protected ilSetting $settings; protected ilLoggingErrorSettings $error_settings; - public function __construct( - string $component, - \ILIAS\Language\Language $lng, - bool $registration = false - ) { - parent::__construct($component, $lng); + public function init(): void + { $this->lng->loadLanguageModule('logging'); - if (!$registration) { - $this->additionalConstruct(); - } - } - private function additionalConstruct() - { global $DIC; $this->settings = new ilSetting('log'); $this->error_settings = ilLoggingErrorSettings::getInstance(); diff --git a/components/ILIAS/Logging/classes/public/class.ilLoggerFactory.php b/components/ILIAS/Logging/classes/public/class.ilLoggerFactory.php index 497d789f69ed..00633d33bd9a 100755 --- a/components/ILIAS/Logging/classes/public/class.ilLoggerFactory.php +++ b/components/ILIAS/Logging/classes/public/class.ilLoggerFactory.php @@ -28,6 +28,7 @@ use Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy; use ILIAS\DI\Container; use Monolog\Processor\PsrLogMessageProcessor; +use ILIAS\Logging\LoggerFactory; /** * Logging factory @@ -35,7 +36,7 @@ * @author Stefan Meyer * */ -class ilLoggerFactory +class ilLoggerFactory implements LoggerFactory { protected const DEFAULT_FORMAT = "[%suid%] [%datetime%] %channel%.%level_name%: %message% %context% %extra%\n"; @@ -45,8 +46,7 @@ class ilLoggerFactory private static ?ilLoggerFactory $instance = null; - private ilLoggingSettings $settings; - protected Container $dic; + protected ?Container $dic; private bool $enabled = false; //ToDo PHP8 Review: This is a private var never read only written and should probably be removed. @@ -55,19 +55,21 @@ class ilLoggerFactory */ private array $loggers = array(); - protected function __construct(ilLoggingSettings $settings) - { + protected function __construct( + private ilLoggingSettings $settings + ) { global $DIC; - $this->dic = $DIC; - $this->settings = $settings; $this->enabled = $this->getSettings()->isEnabled(); } - public static function getInstance(): ilLoggerFactory + public static function getInstance(?\ilLoggingSettings $settings = null): ilLoggerFactory { - if (!static::$instance instanceof ilLoggerFactory) { + if (is_null($settings)) { $settings = ilLoggingDBSettings::getInstance(); + static::$instance = null; + } + if (!static::$instance instanceof ilLoggerFactory) { static::$instance = new ilLoggerFactory($settings); } return static::$instance; diff --git a/components/ILIAS/Logging/src/LoggerFactory.php b/components/ILIAS/Logging/src/LoggerFactory.php index bc7a78dcbacf..e99d9ffe4cb9 100644 --- a/components/ILIAS/Logging/src/LoggerFactory.php +++ b/components/ILIAS/Logging/src/LoggerFactory.php @@ -23,5 +23,4 @@ interface LoggerFactory { - } From f63345b11bec148f78eb1d90d96e1d1ddb9ea07c Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Thu, 2 Jan 2025 15:40:34 +0100 Subject: [PATCH 35/39] Cron: ilCronJobEntities is more of array than iterator --- .../Cron/classes/class.ilCronJobEntities.php | 17 +++--- .../Cron/classes/class.ilCronJobEntity.php | 5 +- .../ILIAS/Cron/tests/CronJobEntityTest.php | 54 +++++++++++++++++-- 3 files changed, 62 insertions(+), 14 deletions(-) diff --git a/components/ILIAS/Cron/classes/class.ilCronJobEntities.php b/components/ILIAS/Cron/classes/class.ilCronJobEntities.php index 1b7c6156bd78..e4b06965dd52 100755 --- a/components/ILIAS/Cron/classes/class.ilCronJobEntities.php +++ b/components/ILIAS/Cron/classes/class.ilCronJobEntities.php @@ -20,11 +20,11 @@ class ilCronJobEntities implements ilCronJobCollection { - private readonly ArrayIterator $jobs; + private array $jobs; public function __construct(ilCronJobEntity ...$jobs) { - $this->jobs = new ArrayIterator($jobs); + $this->jobs = $jobs; } /** @@ -32,27 +32,28 @@ public function __construct(ilCronJobEntity ...$jobs) */ public function getIterator(): ArrayIterator { - return $this->jobs; + return new ArrayIterator($this->jobs); } public function count(): int { - return iterator_count($this); + return count($this->jobs); } public function add(ilCronJobEntity $job): void { - $this->jobs->append($job); + $this->jobs[] = $job; } public function filter(callable $callable): ilCronJobCollection { - return new static(...array_filter(iterator_to_array($this), $callable)); + + return new static(...array_filter($this->jobs, $callable)); } public function slice(int $offset, ?int $length = null): ilCronJobCollection { - return new static(...array_slice(iterator_to_array($this), $offset, $length, true)); + return new static(...array_slice($this->jobs, $offset, $length, true)); } /** @@ -60,6 +61,6 @@ public function slice(int $offset, ?int $length = null): ilCronJobCollection */ public function toArray(): array { - return iterator_to_array($this); + return $this->jobs; } } diff --git a/components/ILIAS/Cron/classes/class.ilCronJobEntity.php b/components/ILIAS/Cron/classes/class.ilCronJobEntity.php index 624ac777f0e8..980a9b30c2f1 100755 --- a/components/ILIAS/Cron/classes/class.ilCronJobEntity.php +++ b/components/ILIAS/Cron/classes/class.ilCronJobEntity.php @@ -19,6 +19,7 @@ declare(strict_types=1); use ILIAS\Cron\Schedule\CronJobScheduleType; +use ILIAS\Cron\CronJob; class ilCronJobEntity { @@ -48,7 +49,7 @@ class ilCronJobEntity * @param array $record * @param bool $isPlugin */ - public function __construct(private readonly ilCronJob $job, array $record, private readonly bool $isPlugin = false) + public function __construct(private readonly CronJob $job, array $record, private readonly bool $isPlugin = false) { $job->init(); $this->mapRecord($job, $record); @@ -57,7 +58,7 @@ public function __construct(private readonly ilCronJob $job, array $record, priv /** * @param array $record */ - private function mapRecord(ilCronJob $job, array $record): void + private function mapRecord(CronJob $job, array $record): void { if (! array_key_exists('job_id', $record)) { //TODO: remove! diff --git a/components/ILIAS/Cron/tests/CronJobEntityTest.php b/components/ILIAS/Cron/tests/CronJobEntityTest.php index 61e291f1005e..cd13c7267329 100755 --- a/components/ILIAS/Cron/tests/CronJobEntityTest.php +++ b/components/ILIAS/Cron/tests/CronJobEntityTest.php @@ -20,6 +20,7 @@ use PHPUnit\Framework\TestCase; use ILIAS\Cron\Schedule\CronJobScheduleType; +use ILIAS\Cron\CronJob; /** * Class CronJobEntityTest @@ -36,7 +37,47 @@ private function getEntity( int $schedule_value = 5, bool $is_plugin = false ): ilCronJobEntity { - $job_instance ??= $this->createMock(ilCronJob::class); + $job_instance ??= new class ( + $schedule_type, + $schedule_value + ) implements CronJob { + public function __construct( + private $schedule_type, + private $schedule_value + ) { + } + public function getId(): string + { + return 'phpunit'; + } + public function getComponent(): string + { + return 'phpunit'; + } + public function getTitle(): string + { + return 'phpunit'; + } + public function getDescription(): string + { + return 'phpunit'; + } + public function getScheduleType(): ?CronJobScheduleType + { + return $this->schedule_type; + } + public function getScheduleValue(): ?int + { + return $this->schedule_value; + } + public function run(): \ilCronJobResult + { + return new \ilCronJobResult(); + } + public function init(): void + { + } + }; if ($schedule_type === null) { $schedule_type = CronJobScheduleType::SCHEDULE_TYPE_IN_MINUTES->value; @@ -91,9 +132,14 @@ public function testCollectionCanBeChanged(ilCronJobEntities $entities): ilCronJ */ public function testCollectionCanBeFilteredAndSliced(ilCronJobEntities $entities): void { - $this->assertCount(0, $entities->filter(static function (ilCronJobEntity $entity): bool { - return $entity->getJobId() !== 'phpunit'; - })); + $this->assertCount( + 0, + $entities->filter( + static function (ilCronJobEntity $entity): bool { + return $entity->getJobId() !== 'phpunit'; + } + ) + ); $this->assertCount(1, $entities->slice(1, 1)); } From 4eca2af6540bd0feb148d4eb542f79fe3e5f9e94 Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Fri, 3 Jan 2025 08:35:43 +0100 Subject: [PATCH 36/39] Cron: use ilSetupLanguage in Objective --- .../class.ilCronJobsRegisteredObjective.php | 19 ++----------------- .../Cron/classes/class.ilCronJobEntities.php | 1 - 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/components/ILIAS/Cron/classes/Setup/class.ilCronJobsRegisteredObjective.php b/components/ILIAS/Cron/classes/Setup/class.ilCronJobsRegisteredObjective.php index 1f6d606e75a4..518b058b1f99 100644 --- a/components/ILIAS/Cron/classes/Setup/class.ilCronJobsRegisteredObjective.php +++ b/components/ILIAS/Cron/classes/Setup/class.ilCronJobsRegisteredObjective.php @@ -76,26 +76,11 @@ public function achieve(Setup\Environment $environment): Setup\Environment /** @var ilSettingsFactory $settings_factory */ $settings_factory = $environment->getResource(Setup\Environment::RESOURCE_SETTINGS_FACTORY); - $mock_lng = new class () implements \ILIAS\Language\Language { - public function txt(string $a_topic, string $a_default_lang_fallback_mod = ""): string - { - return ''; - } - public function loadLanguageModule(string $a_module): void - { - } - public function getLangKey(): string - { - } - public function toJS($key): void - { - } - }; - $mock_logger_factory = new class () implements \ILIAS\Logging\LoggerFactory { }; $registry = new ILIAS\Cron\CronRegistry($this->cronjobs); + $language = new ilSetupLanguage('en'); $repo = new ilCronJobRepositoryImpl( $registry, @@ -104,7 +89,7 @@ public function toJS($key): void new ILIAS\components\Logging\NullLogger(), $component_repository, $component_factory, - $mock_lng, + $language, $mock_logger_factory ); diff --git a/components/ILIAS/Cron/classes/class.ilCronJobEntities.php b/components/ILIAS/Cron/classes/class.ilCronJobEntities.php index e4b06965dd52..3ace3f892ee3 100755 --- a/components/ILIAS/Cron/classes/class.ilCronJobEntities.php +++ b/components/ILIAS/Cron/classes/class.ilCronJobEntities.php @@ -47,7 +47,6 @@ public function add(ilCronJobEntity $job): void public function filter(callable $callable): ilCronJobCollection { - return new static(...array_filter($this->jobs, $callable)); } From 1e23281cefaa09d7e9150dd376d37702fc9bb029 Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Fri, 3 Jan 2025 09:28:08 +0100 Subject: [PATCH 37/39] Cron: update Readme --- components/ILIAS/Cron/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/components/ILIAS/Cron/README.md b/components/ILIAS/Cron/README.md index 4eead8c1edae..1d33755f309c 100755 --- a/components/ILIAS/Cron/README.md +++ b/components/ILIAS/Cron/README.md @@ -43,7 +43,8 @@ class MyComponent implements Component\Component $contribute[\ILIAS\Cron\CronJob::class] = static fn() => new \MyComponentCronJob( self::class, - $use[\ILIAS\Language\Language::class] + $use[\ILIAS\Language\Language::class], + $use[\ILIAS\Logging\LoggerFactory::class], ); } } @@ -66,6 +67,7 @@ Several abstract methods have to be implemented to make a new cron-job usable: - `getDefaultScheduleType()`: see Schedule - `getDefaultScheduleValue()`: see Schedule - `run()`: process the cron-job +- `init()`: called in ilCronJobEntity; may be used to initialize further dependencies ### ilCronJobResult From ce5cac9a4a924977fdc32029f670bdbef74ce22f Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Fri, 3 Jan 2025 11:42:10 +0100 Subject: [PATCH 38/39] Cron: use component bootstrap/entry point for runner --- cli/cron.php | 8 +++++--- components/ILIAS/Cron/classes/class.ilCronJobEntity.php | 8 +------- .../ILIAS/Cron/classes/class.ilCronJobRepositoryImpl.php | 3 --- components/ILIAS/Cron/classes/class.ilCronStartUp.php | 7 ------- 4 files changed, 6 insertions(+), 20 deletions(-) diff --git a/cli/cron.php b/cli/cron.php index a54536e3c6e1..97a357d732a7 100755 --- a/cli/cron.php +++ b/cli/cron.php @@ -18,10 +18,12 @@ declare(strict_types=1); -chdir(__DIR__); -chdir('..'); +require_once __DIR__ . '/../vendor/composer/vendor/autoload.php'; +require_once __DIR__ . '/../artifacts/bootstrap_default.php'; -require_once './vendor/composer/vendor/autoload.php'; +ilContext::init(ilContext::CONTEXT_CRON); + +entry_point('ILIAS Legacy Initialisation Adapter'); $cron = new ILIAS\Cron\CLI\App( new ILIAS\Cron\CLI\Commands\RunActiveJobsCommand() diff --git a/components/ILIAS/Cron/classes/class.ilCronJobEntity.php b/components/ILIAS/Cron/classes/class.ilCronJobEntity.php index 980a9b30c2f1..7531277b21df 100755 --- a/components/ILIAS/Cron/classes/class.ilCronJobEntity.php +++ b/components/ILIAS/Cron/classes/class.ilCronJobEntity.php @@ -60,15 +60,9 @@ public function __construct(private readonly CronJob $job, array $record, privat */ private function mapRecord(CronJob $job, array $record): void { - if (! array_key_exists('job_id', $record)) { - //TODO: remove! - var_dump($record); - die(); - } - //$this->jobId = (string) $record['job_id']; - //$this->component = (string) $record['component']; $this->jobId = $job->getId(); $this->component = $job->getComponent(); + $this->scheduleType = is_numeric($record['schedule_type']) ? CronJobScheduleType::tryFrom((int) $record['schedule_type']) : null; $this->scheduleValue = (int) $record['schedule_value']; $this->jobStatus = (int) $record['job_status']; diff --git a/components/ILIAS/Cron/classes/class.ilCronJobRepositoryImpl.php b/components/ILIAS/Cron/classes/class.ilCronJobRepositoryImpl.php index b975ed7075c4..3ade4c3c771d 100755 --- a/components/ILIAS/Cron/classes/class.ilCronJobRepositoryImpl.php +++ b/components/ILIAS/Cron/classes/class.ilCronJobRepositoryImpl.php @@ -39,7 +39,6 @@ public function __construct( public function getJobInstanceById(string $id): ?ilCronJob { - $jobs_data = $this->getCronJobData($id); if ($jobs_data !== [] && $jobs_data[0]['job_id'] === $id) { return $this->getJobInstance( @@ -116,8 +115,6 @@ public function registerJob( if (!$this->db->tableExists('cron_job')) { return; } - - //$job = $this->getJobInstance($a_id, $a_component, $a_class, true); $job = $this->getJobInstance($a_id, $a_component, $a_class); if ($job) { $this->createDefaultEntry($job, $a_component, $a_class, $a_path); diff --git a/components/ILIAS/Cron/classes/class.ilCronStartUp.php b/components/ILIAS/Cron/classes/class.ilCronStartUp.php index 048ac1472ff2..e0194fc95bb3 100755 --- a/components/ILIAS/Cron/classes/class.ilCronStartUp.php +++ b/components/ILIAS/Cron/classes/class.ilCronStartUp.php @@ -28,13 +28,6 @@ public function __construct( private readonly string $username, ?ilAuthSession $authSession = null ) { - /** @noRector */ - ilContext::init(ilContext::CONTEXT_CRON); - - // TODO @see mantis 20371: To get rid of this, the authentication service has to provide a mechanism to pass the client_id - $_GET['client_id'] = $this->client; - ilInitialisation::initILIAS(); - if (null === $authSession) { global $DIC; $authSession = $DIC['ilAuthSession']; From dbf4c548eb16452000cabada8a0c158227fe54b8 Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Tue, 11 Mar 2025 08:48:53 +0100 Subject: [PATCH 39/39] Cron: minor adjustments --- .../Setup/class.ilCronJobSetupAgent.php | 2 +- .../class.ilCronJobsRegisteredObjective.php | 20 +------------------ .../classes/class.ilCronJobRepositoryImpl.php | 2 +- .../interface.ilCronJobRepository.php | 3 +++ components/ILIAS/Cron/src/CronRegistry.php | 2 +- 5 files changed, 7 insertions(+), 22 deletions(-) diff --git a/components/ILIAS/Cron/classes/Setup/class.ilCronJobSetupAgent.php b/components/ILIAS/Cron/classes/Setup/class.ilCronJobSetupAgent.php index 707597a55767..a15546ad80eb 100644 --- a/components/ILIAS/Cron/classes/Setup/class.ilCronJobSetupAgent.php +++ b/components/ILIAS/Cron/classes/Setup/class.ilCronJobSetupAgent.php @@ -24,7 +24,7 @@ class ilCronJobSetupAgent implements Setup\Agent { public function __construct( - private array $cronjobs + private readonly array $cronjobs ) { } diff --git a/components/ILIAS/Cron/classes/Setup/class.ilCronJobsRegisteredObjective.php b/components/ILIAS/Cron/classes/Setup/class.ilCronJobsRegisteredObjective.php index 518b058b1f99..d3720099ec09 100644 --- a/components/ILIAS/Cron/classes/Setup/class.ilCronJobsRegisteredObjective.php +++ b/components/ILIAS/Cron/classes/Setup/class.ilCronJobsRegisteredObjective.php @@ -23,37 +23,25 @@ class ilCronjobsRegisteredObjective implements Setup\Objective { public function __construct( - private array $cronjobs + private readonly array $cronjobs ) { } - /** - * @inheritdoc - */ public function getHash(): string { return hash("sha256", self::class); } - /** - * @inheritdoc - */ public function getLabel(): string { return "CronJobs are registered."; } - /** - * @inheritdoc - */ public function isNotable(): bool { return true; } - /** - * @inheritdoc - */ public function getPreconditions(Setup\Environment $environment): array { return [ @@ -63,9 +51,6 @@ public function getPreconditions(Setup\Environment $environment): array ]; } - /** - * @inheritdoc - */ public function achieve(Setup\Environment $environment): Setup\Environment { $db = $environment->getResource(Setup\Environment::RESOURCE_DATABASE); @@ -107,9 +92,6 @@ public function achieve(Setup\Environment $environment): Setup\Environment return $environment; } - /** - * @inheritdoc - */ public function isApplicable(Setup\Environment $environment): bool { return true; diff --git a/components/ILIAS/Cron/classes/class.ilCronJobRepositoryImpl.php b/components/ILIAS/Cron/classes/class.ilCronJobRepositoryImpl.php index 3ade4c3c771d..50fb4bccf59c 100755 --- a/components/ILIAS/Cron/classes/class.ilCronJobRepositoryImpl.php +++ b/components/ILIAS/Cron/classes/class.ilCronJobRepositoryImpl.php @@ -123,7 +123,7 @@ public function registerJob( public function unregisterAllJobs(): void { - $query = 'TRUNCATE cron_job;'; + $query = 'DELETE FROM cron_job'; $res = $this->db->manipulate($query); } diff --git a/components/ILIAS/Cron/interfaces/interface.ilCronJobRepository.php b/components/ILIAS/Cron/interfaces/interface.ilCronJobRepository.php index 28e9db193648..c54769f18f99 100755 --- a/components/ILIAS/Cron/interfaces/interface.ilCronJobRepository.php +++ b/components/ILIAS/Cron/interfaces/interface.ilCronJobRepository.php @@ -41,6 +41,8 @@ public function registerJob(string $a_component, string $a_id, string $a_class, public function unregisterJob(string $a_component, array $a_xml_job_ids): void; + public function unregisterAllJobs(): void; + public function createDefaultEntry(ilCronJob $job, string $component, string $class, ?string $path): void; /** @@ -67,4 +69,5 @@ public function activateJob(ilCronJob $job, DateTimeImmutable $when, ilObjUser $ public function deactivateJob(ilCronJob $job, DateTimeImmutable $when, ilObjUser $actor, bool $wasManuallyExecuted = false): void; public function findAll(): ilCronJobCollection; + } diff --git a/components/ILIAS/Cron/src/CronRegistry.php b/components/ILIAS/Cron/src/CronRegistry.php index 49ed81acce6b..8e8d4622c433 100644 --- a/components/ILIAS/Cron/src/CronRegistry.php +++ b/components/ILIAS/Cron/src/CronRegistry.php @@ -26,7 +26,7 @@ class CronRegistry implements Registry * @param ilCronJob[] $jobs */ public function __construct( - private array $jobs + private readonly array $jobs ) { }