ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLuceneIndexer.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
5
9
19{
20 protected int $timeout = 60;
21
22 protected ilLanguage $lng;
24
25 public function __construct()
26 {
27 global $DIC;
28
29 $this->lng = $DIC->language();
30 $this->setting = $DIC->settings();
31 }
32
33 public function getId(): string
34 {
35 return "src_lucene_indexer";
36 }
37
38 public function getTitle(): string
39 {
40 return $this->lng->txt("cron_lucene_index");
41 }
42
43 public function getDescription(): string
44 {
45 return $this->lng->txt("cron_lucene_index_info");
46 }
47
49 {
50 return JobScheduleType::DAILY;
51 }
52
53 public function getDefaultScheduleValue(): ?int
54 {
55 return null;
56 }
57
58 public function hasAutoActivation(): bool
59 {
60 return false;
61 }
62
63 public function hasFlexibleSchedule(): bool
64 {
65 return true;
66 }
67
68 public function run(): JobResult
69 {
70 $status = JobResult::STATUS_NO_ACTION;
71 $error_message = null;
72
73 try {
74 ilRpcClientFactory::factory('RPCIndexHandler', 60)->index(
75 CLIENT_ID . '_' . $this->setting->get('inst_id', "0"),
76 true
77 );
78 } catch (Exception $e) {
79 $error_message = $e->getMessage();
80
81 if ($e instanceof ilRpcClientException && $e->getCode() == 28) {
82 ilLoggerFactory::getLogger('src')->info('Connection timed out after ' . $this->timeout . ' seconds. ' .
83 'Indexing will continoue without a proper return message. View ilServer log if you think there are problems while indexing.');
84 $error_message = null;
85 }
86 }
87
88 $result = new JobResult();
89 if ($error_message) {
90 // #16035 - currently no way to discern the severity of the exception
91 $result->setMessage($error_message);
92 $status = JobResult::STATUS_FAIL;
93 } else {
94 $status = JobResult::STATUS_OK;
95 }
96 $result->setStatus($status);
97 return $result;
98 }
99
100
106 public static function updateLuceneIndex(array $a_obj_ids): bool
107 {
108 global $DIC;
109
110 $ilSetting = $DIC['ilSetting'];
111 if (!ilSearchSettings::getInstance()->isLuceneUserSearchEnabled()) {
112 return false;
113 }
114
115 try {
116 ilLoggerFactory::getLogger('src')->info('Lucene update index call BEGIN --- ');
117
118 ilRpcClientFactory::factory('RPCIndexHandler', 1)->indexObjects(
119 CLIENT_ID . '_' . $ilSetting->get('inst_id', "0"),
120 $a_obj_ids
121 );
122 ilLoggerFactory::getLogger('src')->info('Lucene update index call --- END');
123 } catch (Exception $e) {
124 $error_message = $e->getMessage();
125 ilLoggerFactory::getLogger('src')->error($error_message);
126 return false;
127 }
128
129 return true;
130 }
131}
language handling
static getLogger(string $a_component_id)
Get component logger.
static updateLuceneIndex(array $a_obj_ids)
Update lucene index.
hasAutoActivation()
Is to be activated on "installation", does only work for ILIAS core cron jobs.
Class ilRpcClientException.
static factory(string $a_package, int $a_timeout=0)
Creates an ilRpcClient instance to our ilServer.
ILIAS Setting Class.
const CLIENT_ID
Definition: constants.php:41
global $ilSetting
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26