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