ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ILIAS\MetaData\OERHarvester\Harvester Class Reference
+ Collaboration diagram for ILIAS\MetaData\OERHarvester\Harvester:

Public Member Functions

 __construct (SettingsInterface $settings, ObjectHandler $object_handler, ExportHandler $export_handler, StatusRepository $status_repository, ExposedRecordRepository $exposed_record_repository, CopyrightSearchFactory $copyright_search_factory, LOMRepository $lom_repository, SimpleDCXMLWriter $xml_writer, \ilLogger $logger)
 
 run (Result $result)
 

Protected Member Functions

 findHarvestableObjectIDs ()
 
 deleteDeprecatedReferences (array $harvestable_obj_ids, array $currently_harvested_obj_ids)
 Returns number of deletions. More...
 
 harvestObjects (array $harvestable_obj_ids, array $currently_harvested_obj_ids)
 Returns number of harvested objects. More...
 
 updateExposedRecords (array $harvestable_obj_ids,)
 Returns number of changed exposed records. More...
 
 logDebug (string $message)
 
 logError (string $message)
 
 buildIdentifier (int $obj_id, string $type)
 

Protected Attributes

SettingsInterface $settings
 
ObjectHandler $object_handler
 
ExportHandler $export_handler
 
StatusRepository $status_repository
 
ExposedRecordRepository $exposed_record_repository
 
CopyrightSearchFactory $copyright_search_factory
 
LOMRepository $lom_repository
 
SimpleDCXMLWriter $xml_writer
 
ilLogger $logger
 

Detailed Description

Definition at line 34 of file Harvester.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\MetaData\OERHarvester\Harvester::__construct ( SettingsInterface  $settings,
ObjectHandler  $object_handler,
ExportHandler  $export_handler,
StatusRepository  $status_repository,
ExposedRecordRepository  $exposed_record_repository,
CopyrightSearchFactory  $copyright_search_factory,
LOMRepository  $lom_repository,
SimpleDCXMLWriter  $xml_writer,
\ilLogger  $logger 
)

Definition at line 46 of file Harvester.php.

References ILIAS\MetaData\OERHarvester\Harvester\$copyright_search_factory, ILIAS\MetaData\OERHarvester\Harvester\$export_handler, ILIAS\MetaData\OERHarvester\Harvester\$exposed_record_repository, ILIAS\MetaData\OERHarvester\Harvester\$logger, ILIAS\MetaData\OERHarvester\Harvester\$lom_repository, ILIAS\MetaData\OERHarvester\Harvester\$object_handler, ILIAS\MetaData\OERHarvester\Harvester\$settings, ILIAS\MetaData\OERHarvester\Harvester\$status_repository, ILIAS\MetaData\OERHarvester\Harvester\$xml_writer, ILIAS\Repository\logger(), and ILIAS\Repository\settings().

56  {
57  $this->settings = $settings;
58  $this->object_handler = $object_handler;
59  $this->export_handler = $export_handler;
60  $this->status_repository = $status_repository;
61  $this->exposed_record_repository = $exposed_record_repository;
62  $this->copyright_search_factory = $copyright_search_factory;
63  $this->lom_repository = $lom_repository;
64  $this->xml_writer = $xml_writer;
65  $this->logger = $logger;
66  }
ExposedRecordRepository $exposed_record_repository
Definition: Harvester.php:40
CopyrightSearchFactory $copyright_search_factory
Definition: Harvester.php:41
+ Here is the call graph for this function:

Member Function Documentation

◆ buildIdentifier()

ILIAS\MetaData\OERHarvester\Harvester::buildIdentifier ( int  $obj_id,
string  $type 
)
protected

Definition at line 294 of file Harvester.php.

Referenced by ILIAS\MetaData\OERHarvester\Harvester\updateExposedRecords().

294  : string
295  {
296  return 'il__' . $type . '_' . $obj_id;
297  }
+ Here is the caller graph for this function:

◆ deleteDeprecatedReferences()

ILIAS\MetaData\OERHarvester\Harvester::deleteDeprecatedReferences ( array  $harvestable_obj_ids,
array  $currently_harvested_obj_ids 
)
protected

Returns number of deletions.

Parameters
int[]$harvestable_obj_ids
int[]$currently_harvested_obj_ids

Definition at line 134 of file Harvester.php.

References Vendor\Package\$e, $ref_id, ILIAS\MetaData\OERHarvester\Harvester\logDebug(), and ILIAS\MetaData\OERHarvester\Harvester\logError().

Referenced by ILIAS\MetaData\OERHarvester\Harvester\run().

137  : int {
138  $count = 0;
139  foreach ($currently_harvested_obj_ids as $obj_id) {
140  if (in_array($obj_id, $harvestable_obj_ids)) {
141  continue;
142  }
143 
144  $ref_id = $this->status_repository->getHarvestRefID($obj_id);
145  $this->logDebug('Deleting deprecated object with ref_id: ' . $ref_id);
146  try {
147  $this->object_handler->deleteReference($ref_id);
148  } catch (\Exception $e) {
149  $this->logError(
150  'Error when deleting harvested reference with ref_id ' .
151  $ref_id . ': ' . $e->getMessage()
152  );
153  continue;
154  }
155  $this->status_repository->deleteHarvestRefID($obj_id);
156  $count++;
157  }
158  return $count;
159  }
$ref_id
Definition: ltiauth.php:66
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findHarvestableObjectIDs()

ILIAS\MetaData\OERHarvester\Harvester::findHarvestableObjectIDs ( )
protected

Definition at line 103 of file Harvester.php.

References $results, and ILIAS\Repository\settings().

Referenced by ILIAS\MetaData\OERHarvester\Harvester\run().

103  : array
104  {
105  $searcher = $this->copyright_search_factory->get()
106  ->withRestrictionToRepositoryObjects(true);
107  foreach ($this->settings->getObjectTypesSelectedForHarvesting() as $type) {
108  $searcher = $searcher->withAdditionalTypeFilter($type);
109  }
110  $search_results = [];
111  foreach ($searcher->search(
112  $this->lom_repository,
113  ...$this->settings->getCopyrightEntryIDsSelectedForHarvesting()
114  ) as $ressource_id) {
115  $search_results[] = $ressource_id->objID();
116  }
117 
118  $unblocked = $this->status_repository->filterOutBlockedObjects(...$search_results);
119  $results = [];
120  foreach ($unblocked as $obj_id) {
121  if ($this->object_handler->isObjectDeleted($obj_id)) {
122  continue;
123  }
124  $results[] = $obj_id;
125  }
126  return $results;
127  }
$results
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ harvestObjects()

ILIAS\MetaData\OERHarvester\Harvester::harvestObjects ( array  $harvestable_obj_ids,
array  $currently_harvested_obj_ids 
)
protected

Returns number of harvested objects.

Parameters
int[]$harvestable_obj_ids
int[]$currently_harvested_obj_ids

Definition at line 166 of file Harvester.php.

References Vendor\Package\$e, ILIAS\MetaData\OERHarvester\Harvester\logDebug(), ILIAS\MetaData\OERHarvester\Harvester\logError(), and ILIAS\Repository\settings().

Referenced by ILIAS\MetaData\OERHarvester\Harvester\run().

169  : int {
170  $count = 0;
171 
172  $target_ref_id = $this->settings->getContainerRefIDForHarvesting();
173  if (!$target_ref_id) {
174  return 0;
175  }
176 
177  foreach ($harvestable_obj_ids as $obj_id) {
178  if (in_array($obj_id, $currently_harvested_obj_ids)) {
179  continue;
180  }
181 
182  $this->logDebug('Creating new reference for object with obj_id: ' . $obj_id);
183  try {
184  $new_ref_id = $this->object_handler->referenceObjectInTargetContainer(
185  $obj_id,
186  $target_ref_id
187  );
188  } catch (\Exception $e) {
189  $this->logError(
190  'Error when creating reference for object with obj_id ' .
191  $obj_id . ': ' . $e->getMessage()
192  );
193  continue;
194  }
195  $this->status_repository->setHarvestRefID($obj_id, $new_ref_id);
196 
197  try {
198  if (!$this->export_handler->hasPublicAccessExport($obj_id)) {
199  $this->export_handler->createPublicAccessExport($obj_id);
200  }
201  } catch (\Exception $e) {
202  $this->logError(
203  'Error when creating export for object with obj_id ' .
204  $obj_id . ': ' . $e->getMessage()
205  );
206  }
207 
208  $count++;
209  }
210  return $count;
211  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ logDebug()

ILIAS\MetaData\OERHarvester\Harvester::logDebug ( string  $message)
protected

Definition at line 284 of file Harvester.php.

References ILIAS\Repository\logger().

Referenced by ILIAS\MetaData\OERHarvester\Harvester\deleteDeprecatedReferences(), ILIAS\MetaData\OERHarvester\Harvester\harvestObjects(), and ILIAS\MetaData\OERHarvester\Harvester\updateExposedRecords().

284  : void
285  {
286  $this->logger->debug($message);
287  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ logError()

ILIAS\MetaData\OERHarvester\Harvester::logError ( string  $message)
protected

Definition at line 289 of file Harvester.php.

References ILIAS\Repository\logger().

Referenced by ILIAS\MetaData\OERHarvester\Harvester\deleteDeprecatedReferences(), and ILIAS\MetaData\OERHarvester\Harvester\harvestObjects().

289  : void
290  {
291  $this->logger->error($message);
292  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ run()

ILIAS\MetaData\OERHarvester\Harvester::run ( Result  $result)

Definition at line 68 of file Harvester.php.

References Vendor\Package\$e, ILIAS\MetaData\OERHarvester\Harvester\deleteDeprecatedReferences(), ILIAS\MetaData\OERHarvester\Harvester\findHarvestableObjectIDs(), ILIAS\MetaData\OERHarvester\Harvester\harvestObjects(), ilCronJobResult\STATUS_FAIL, ilCronJobResult\STATUS_NO_ACTION, ilCronJobResult\STATUS_OK, and ILIAS\MetaData\OERHarvester\Harvester\updateExposedRecords().

68  : Result
69  {
70  try {
71  $messages = [];
72 
73  $harvestable_obj_ids = $this->findHarvestableObjectIDs();
74  $currently_harvested_obj_ids = iterator_to_array($this->status_repository->getAllHarvestedObjIDs());
75 
76  $deletion_count = $this->deleteDeprecatedReferences(
77  $harvestable_obj_ids,
78  $currently_harvested_obj_ids
79  );
80  $messages[] = 'Deleted ' . $deletion_count . ' deprecated references.';
81  $harvest_count = $this->harvestObjects(
82  $harvestable_obj_ids,
83  $currently_harvested_obj_ids
84  );
85  $messages[] = 'Created ' . $harvest_count . ' new references.';
86  $exposure_count = $this->updateExposedRecords(
87  $harvestable_obj_ids
88  );
89  $messages[] = 'Created, updated, or deleted ' . $exposure_count . ' exposed records.';
90 
91  if ($deletion_count !== 0 || $harvest_count !== 0 || $exposure_count !== 0) {
92  $result = $result->withStatus(\ilCronJobResult::STATUS_OK);
93  } else {
94  $result = $result->withStatus(\ilCronJobResult::STATUS_NO_ACTION);
95  }
96  return $result->withMessage(implode('<br>', $messages));
97  } catch (\Exception $e) {
98  return $result->withStatus(\ilCronJobResult::STATUS_FAIL)
99  ->withMessage($e->getMessage());
100  }
101  }
deleteDeprecatedReferences(array $harvestable_obj_ids, array $currently_harvested_obj_ids)
Returns number of deletions.
Definition: Harvester.php:134
final const STATUS_NO_ACTION
harvestObjects(array $harvestable_obj_ids, array $currently_harvested_obj_ids)
Returns number of harvested objects.
Definition: Harvester.php:166
updateExposedRecords(array $harvestable_obj_ids,)
Returns number of changed exposed records.
Definition: Harvester.php:217
+ Here is the call graph for this function:

◆ updateExposedRecords()

ILIAS\MetaData\OERHarvester\Harvester::updateExposedRecords ( array  $harvestable_obj_ids)
protected

Returns number of changed exposed records.

Parameters
int[]$harvestable_obj_ids

Definition at line 217 of file Harvester.php.

References $ref_id, ILIAS\MetaData\OERHarvester\Harvester\buildIdentifier(), ILIAS\MetaData\OERHarvester\Harvester\logDebug(), and ILIAS\Repository\settings().

Referenced by ILIAS\MetaData\OERHarvester\Harvester\run().

219  : int {
220  $count = 0;
221 
222  $source_ref_id = $this->settings->getContainerRefIDForExposing();
223  if (!$source_ref_id) {
224  return 0;
225  }
226 
227  $already_exposed = [];
228  foreach ($this->exposed_record_repository->getRecords() as $record) {
229  $obj_id = $record->infos()->objID();
230  $already_exposed[] = $obj_id;
231 
232  $ref_id = $this->object_handler->getObjectReferenceIDInContainer($obj_id, $source_ref_id);
233 
234  if (!in_array($obj_id, $harvestable_obj_ids) || is_null($ref_id)) {
235  $this->logDebug('Deleting exposed record for object with obj_id: ' . $obj_id);
236  $this->exposed_record_repository->deleteRecord($obj_id);
237  $count++;
238  continue;
239  }
240 
241  $simple_dc_xml = $this->xml_writer->writeSimpleDCMetaData(
242  $obj_id,
243  $ref_id,
244  $this->object_handler->getTypeOfReferencedObject($ref_id)
245  );
246 
247  if ($simple_dc_xml->saveXML() !== $record->metadata()->saveXML()) {
248  $this->logDebug('Updating exposed record for object with obj_id: ' . $obj_id);
249  $this->exposed_record_repository->updateRecord($obj_id, $simple_dc_xml);
250  $count++;
251  }
252  }
253 
254  foreach ($harvestable_obj_ids as $obj_id) {
255  if (in_array($obj_id, $already_exposed)) {
256  continue;
257  }
258 
259  $ref_id = $this->object_handler->getObjectReferenceIDInContainer($obj_id, $source_ref_id);
260  if (is_null($ref_id)) {
261  continue;
262  }
263 
264  $type = $this->object_handler->getTypeOfReferencedObject($ref_id);
265 
266  $simple_dc_xml = $this->xml_writer->writeSimpleDCMetaData(
267  $obj_id,
268  $ref_id,
269  $type
270  );
271 
272  $this->logDebug('Creating exposed record for object with obj_id: ' . $obj_id);
273  $this->exposed_record_repository->createRecord(
274  $obj_id,
275  $this->buildIdentifier($obj_id, $type),
276  $simple_dc_xml
277  );
278  $count++;
279  }
280 
281  return $count;
282  }
buildIdentifier(int $obj_id, string $type)
Definition: Harvester.php:294
$ref_id
Definition: ltiauth.php:66
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $copyright_search_factory

CopyrightSearchFactory ILIAS\MetaData\OERHarvester\Harvester::$copyright_search_factory
protected

Definition at line 41 of file Harvester.php.

Referenced by ILIAS\MetaData\OERHarvester\Harvester\__construct().

◆ $export_handler

ExportHandler ILIAS\MetaData\OERHarvester\Harvester::$export_handler
protected

Definition at line 38 of file Harvester.php.

Referenced by ILIAS\MetaData\OERHarvester\Harvester\__construct().

◆ $exposed_record_repository

ExposedRecordRepository ILIAS\MetaData\OERHarvester\Harvester::$exposed_record_repository
protected

Definition at line 40 of file Harvester.php.

Referenced by ILIAS\MetaData\OERHarvester\Harvester\__construct().

◆ $logger

ilLogger ILIAS\MetaData\OERHarvester\Harvester::$logger
protected

Definition at line 44 of file Harvester.php.

Referenced by ILIAS\MetaData\OERHarvester\Harvester\__construct().

◆ $lom_repository

LOMRepository ILIAS\MetaData\OERHarvester\Harvester::$lom_repository
protected

Definition at line 42 of file Harvester.php.

Referenced by ILIAS\MetaData\OERHarvester\Harvester\__construct().

◆ $object_handler

ObjectHandler ILIAS\MetaData\OERHarvester\Harvester::$object_handler
protected

Definition at line 37 of file Harvester.php.

Referenced by ILIAS\MetaData\OERHarvester\Harvester\__construct().

◆ $settings

SettingsInterface ILIAS\MetaData\OERHarvester\Harvester::$settings
protected

Definition at line 36 of file Harvester.php.

Referenced by ILIAS\MetaData\OERHarvester\Harvester\__construct().

◆ $status_repository

StatusRepository ILIAS\MetaData\OERHarvester\Harvester::$status_repository
protected

Definition at line 39 of file Harvester.php.

Referenced by ILIAS\MetaData\OERHarvester\Harvester\__construct().

◆ $xml_writer

SimpleDCXMLWriter ILIAS\MetaData\OERHarvester\Harvester::$xml_writer
protected

Definition at line 43 of file Harvester.php.

Referenced by ILIAS\MetaData\OERHarvester\Harvester\__construct().


The documentation for this class was generated from the following file: