ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
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 
7 
17 {
18  protected int $timeout = 60;
19 
20  protected ilLanguage $lng;
21  protected ilSetting $setting;
22 
23  public function __construct()
24  {
25  global $DIC;
26 
27  $this->lng = $DIC->language();
28  $this->setting = $DIC->settings();
29  }
30 
31  public function getId(): string
32  {
33  return "src_lucene_indexer";
34  }
35 
36  public function getTitle(): string
37  {
38  return $this->lng->txt("cron_lucene_index");
39  }
40 
41  public function getDescription(): string
42  {
43  return $this->lng->txt("cron_lucene_index_info");
44  }
45 
47  {
48  return CronJobScheduleType::SCHEDULE_TYPE_DAILY;
49  }
50 
51  public function getDefaultScheduleValue(): ?int
52  {
53  return null;
54  }
55 
56  public function hasAutoActivation(): bool
57  {
58  return false;
59  }
60 
61  public function hasFlexibleSchedule(): bool
62  {
63  return true;
64  }
65 
66  public function run(): ilCronJobResult
67  {
69  $error_message = null;
70 
71  try {
72  ilRpcClientFactory::factory('RPCIndexHandler', 60)->index(
73  CLIENT_ID . '_' . $this->setting->get('inst_id', "0"),
74  true
75  );
76  } catch (Exception $e) {
77  $error_message = $e->getMessage();
78 
79  if ($e instanceof ilRpcClientException && $e->getCode() == 28) {
80  ilLoggerFactory::getLogger('src')->info('Connection timed out after ' . $this->timeout . ' seconds. ' .
81  'Indexing will continoue without a proper return message. View ilServer log if you think there are problems while indexing.');
82  $error_message = null;
83  }
84  }
85 
86  $result = new ilCronJobResult();
87  if ($error_message) {
88  // #16035 - currently no way to discern the severity of the exception
89  $result->setMessage($error_message);
91  } else {
93  }
94  $result->setStatus($status);
95  return $result;
96  }
97 
98 
104  public static function updateLuceneIndex(array $a_obj_ids): bool
105  {
106  global $DIC;
107 
108  $ilSetting = $DIC['ilSetting'];
109  if (!ilSearchSettings::getInstance()->isLuceneUserSearchEnabled()) {
110  return false;
111  }
112 
113  try {
114  ilLoggerFactory::getLogger('src')->info('Lucene update index call BEGIN --- ');
115 
116  ilRpcClientFactory::factory('RPCIndexHandler', 1)->indexObjects(
117  CLIENT_ID . '_' . $ilSetting->get('inst_id', "0"),
118  $a_obj_ids
119  );
120  ilLoggerFactory::getLogger('src')->info('Lucene update index call --- END');
121  } catch (Exception $e) {
122  $error_message = $e->getMessage();
123  ilLoggerFactory::getLogger('src')->error($error_message);
124  return false;
125  }
126 
127  return true;
128  }
129 }
static getLogger(string $a_component_id)
Get component logger.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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.
final const STATUS_NO_ACTION
const CLIENT_ID
Definition: constants.php:41
global $DIC
Definition: shib_login.php:25
Class ilRpcClientException.
global $ilSetting
Definition: privfeed.php:32