ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 33 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 45 of file Harvester.php.

55 {
56 $this->settings = $settings;
57 $this->object_handler = $object_handler;
58 $this->export_handler = $export_handler;
59 $this->status_repository = $status_repository;
60 $this->exposed_record_repository = $exposed_record_repository;
61 $this->copyright_search_factory = $copyright_search_factory;
62 $this->lom_repository = $lom_repository;
63 $this->xml_writer = $xml_writer;
64 $this->logger = $logger;
65 }
ExposedRecordRepository $exposed_record_repository
Definition: Harvester.php:39
CopyrightSearchFactory $copyright_search_factory
Definition: Harvester.php:40

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().

+ 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 293 of file Harvester.php.

293 : string
294 {
295 return 'il__' . $type . '_' . $obj_id;
296 }

◆ 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 133 of file Harvester.php.

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

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

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

+ 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 102 of file Harvester.php.

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

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

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

+ 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 165 of file Harvester.php.

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

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

+ Here is the caller graph for this function:

◆ logDebug()

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

Definition at line 283 of file Harvester.php.

283 : void
284 {
285 $this->logger->debug($message);
286 }
$message
Definition: xapiexit.php:31

References ILIAS\Repository\logger().

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

+ 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 288 of file Harvester.php.

288 : void
289 {
290 $this->logger->error($message);
291 }

References ILIAS\Repository\logger().

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

+ 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 67 of file Harvester.php.

67 : Result
68 {
69 try {
70 $messages = [];
71
72 $harvestable_obj_ids = $this->findHarvestableObjectIDs();
73 $currently_harvested_obj_ids = iterator_to_array($this->status_repository->getAllHarvestedObjIDs());
74
75 $deletion_count = $this->deleteDeprecatedReferences(
76 $harvestable_obj_ids,
77 $currently_harvested_obj_ids
78 );
79 $messages[] = 'Deleted ' . $deletion_count . ' deprecated references.';
80 $harvest_count = $this->harvestObjects(
81 $harvestable_obj_ids,
82 $currently_harvested_obj_ids
83 );
84 $messages[] = 'Created ' . $harvest_count . ' new references.';
85 $exposure_count = $this->updateExposedRecords(
86 $harvestable_obj_ids
87 );
88 $messages[] = 'Created, updated, or deleted ' . $exposure_count . ' exposed records.';
89
90 if ($deletion_count !== 0 || $harvest_count !== 0 || $exposure_count !== 0) {
91 $result = $result->withStatus(\ILIAS\Cron\Job\JobResult::STATUS_OK);
92 } else {
93 $result = $result->withStatus(\ILIAS\Cron\Job\JobResult::STATUS_NO_ACTION);
94 }
95 return $result->withMessage(implode('<br>', $messages));
96 } catch (\Exception $e) {
97 return $result->withStatus(\ILIAS\Cron\Job\JobResult::STATUS_FAIL)
98 ->withMessage($e->getMessage());
99 }
100 }
harvestObjects(array $harvestable_obj_ids, array $currently_harvested_obj_ids)
Returns number of harvested objects.
Definition: Harvester.php:165
deleteDeprecatedReferences(array $harvestable_obj_ids, array $currently_harvested_obj_ids)
Returns number of deletions.
Definition: Harvester.php:133
updateExposedRecords(array $harvestable_obj_ids,)
Returns number of changed exposed records.
Definition: Harvester.php:216
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
$messages
Definition: xapiexit.php:21

References Vendor\Package\$e, $messages, ILIAS\MetaData\OERHarvester\Harvester\deleteDeprecatedReferences(), ILIAS\MetaData\OERHarvester\Harvester\findHarvestableObjectIDs(), ILIAS\MetaData\OERHarvester\Harvester\harvestObjects(), and ILIAS\MetaData\OERHarvester\Harvester\updateExposedRecords().

+ 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 216 of file Harvester.php.

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

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

+ 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 40 of file Harvester.php.

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

◆ $export_handler

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

Definition at line 37 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 39 of file Harvester.php.

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

◆ $logger

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

Definition at line 43 of file Harvester.php.

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

◆ $lom_repository

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

Definition at line 41 of file Harvester.php.

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

◆ $object_handler

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

Definition at line 36 of file Harvester.php.

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

◆ $settings

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

Definition at line 35 of file Harvester.php.

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

◆ $status_repository

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

Definition at line 38 of file Harvester.php.

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

◆ $xml_writer

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

Definition at line 42 of file Harvester.php.

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


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