1919declare (strict_types=1 );
2020
2121use ILIAS \Cron \Schedule \CronJobScheduleType ;
22+ use ILIAS \Cron \Registry ;
2223
2324class ilCronJobRepositoryImpl implements ilCronJobRepository
2425{
2526 private const TYPE_PLUGINS = 'Plugins ' ;
2627
2728 public function __construct (
29+ private readonly Registry $ registry ,
2830 private readonly ilDBInterface $ db ,
2931 private readonly ilSetting $ setting ,
3032 private readonly ilLogger $ logger ,
3133 private readonly ilComponentRepository $ componentRepository ,
3234 private readonly ilComponentFactory $ componentFactory ,
33- private readonly ILIAS \Language \Language $ lng
35+ private readonly ILIAS \Language \Language $ lng ,
36+ private readonly ILIAS \Logging \LoggerFactory $ logger_factory
3437 ) {
3538 }
3639
3740 public function getJobInstanceById (string $ id ): ?ilCronJob
3841 {
39- // plugin
40- if (str_starts_with ($ id , 'pl__ ' )) {
41- $ parts = explode ('__ ' , $ id );
42- $ pl_name = $ parts [1 ];
43- $ job_id = $ parts [2 ];
44-
45- foreach ($ this ->componentRepository ->getPlugins () as $ pl ) {
46- if ($ pl ->getName () !== $ pl_name || !$ pl ->isActive ()) {
47- continue ;
48- }
49-
50- $ plugin = $ this ->componentFactory ->getPlugin ($ pl ->getId ());
51- if (!$ plugin instanceof ilCronJobProvider) {
52- continue ;
53- }
54-
55- try {
56- $ job = $ plugin ->getCronJobInstance ($ job_id );
57-
58- // should never happen but who knows...
59- $ jobs_data = $ this ->getCronJobData ($ job_id );
60- if ($ jobs_data === []) {
61- // as job is not 'imported' from xml
62- $ this ->createDefaultEntry ($ job , $ pl_name , self ::TYPE_PLUGINS , '' );
63- }
6442
65- return $ job ;
66- } catch (OutOfBoundsException ) {
67- // Maybe a job was removed from plugin, renamed etc.
68- }
69- break ;
70- }
71- } else {
72- $ jobs_data = $ this ->getCronJobData ($ id );
73- if ($ jobs_data !== [] && $ jobs_data [0 ]['job_id ' ] === $ id ) {
74- return $ this ->getJobInstance (
75- $ jobs_data [0 ]['job_id ' ],
76- $ jobs_data [0 ]['component ' ],
77- $ jobs_data [0 ]['class ' ]
78- );
79- }
43+ $ jobs_data = $ this ->getCronJobData ($ id );
44+ if ($ jobs_data !== [] && $ jobs_data [0 ]['job_id ' ] === $ id ) {
45+ return $ this ->getJobInstance (
46+ $ jobs_data [0 ]['job_id ' ],
47+ $ jobs_data [0 ]['component ' ],
48+ $ jobs_data [0 ]['class ' ]
49+ );
8050 }
8151
8252 $ this ->logger ->info ('CRON - job ' . $ id . ' seems invalid or is inactive ' );
@@ -87,19 +57,15 @@ public function getJobInstanceById(string $id): ?ilCronJob
8757 public function getJobInstance (
8858 string $ a_id ,
8959 string $ a_component ,
90- string $ a_class ,
91- bool $ isCreationContext = false
60+ string $ a_class
9261 ): ?ilCronJob {
62+
9363 if (class_exists ($ a_class )) {
94- if ($ isCreationContext ) {
95- $ refl = new ReflectionClass ($ a_class );
96- $ job = $ refl ->newInstanceWithoutConstructor ();
97- } else {
98- $ job = new $ a_class (
99- $ a_component ,
100- $ this ->lng
101- );
102- }
64+ $ job = new $ a_class (
65+ $ a_component ,
66+ $ this ->lng ,
67+ $ this ->logger_factory
68+ );
10369
10470 if ($ job instanceof ilCronJob && $ job ->getId () === $ a_id ) {
10571 return $ job ;
@@ -151,7 +117,8 @@ public function registerJob(
151117 return ;
152118 }
153119
154- $ job = $ this ->getJobInstance ($ a_id , $ a_component , $ a_class , true );
120+ //$job = $this->getJobInstance($a_id, $a_component, $a_class, true);
121+ $ job = $ this ->getJobInstance ($ a_id , $ a_component , $ a_class );
155122 if ($ job ) {
156123 $ this ->createDefaultEntry ($ job , $ a_component , $ a_class , $ a_path );
157124 }
@@ -401,21 +368,11 @@ public function findAll(): ilCronJobCollection
401368 {
402369 $ collection = new ilCronJobEntities ();
403370
404- foreach ($ this ->getCronJobData () as $ item ) {
405- $ job = $ this ->getJobInstance (
406- $ item ['job_id ' ],
407- $ item ['component ' ],
408- $ item ['class ' ]
409- );
410- if ($ job ) {
411- $ collection ->add (new ilCronJobEntity ($ job , $ item ));
412- }
371+ foreach ($ this ->registry ->getAllJobs () as $ job ) {
372+ $ job_data = $ this ->getCronJobData ($ job ->getId ());
373+ $ entity = new ilCronJobEntity ($ job , array_shift ($ job_data ));
374+ $ collection ->add ($ entity );
413375 }
414-
415- foreach ($ this ->getPluginJobs () as $ item ) {
416- $ collection ->add (new ilCronJobEntity ($ item [0 ], $ item [1 ], true ));
417- }
418-
419376 return $ collection ;
420377 }
421378}
0 commit comments