ILIAS  trunk Revision v12.0_alpha-1221-g4e438232683
ILIAS\MetaData\OERHarvester\CronJob\AutomaticPublisher Class Reference
+ Collaboration diagram for ILIAS\MetaData\OERHarvester\CronJob\AutomaticPublisher:

Public Member Functions

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

Protected Member Functions

 findHarvestableObjectIDs ()
 
 withdrawDeprecatedObjects (array $harvestable_obj_ids, array $currently_harvested_obj_ids)
 Returns number of deletions. More...
 
 publishObjects (array $harvestable_obj_ids, array $currently_harvested_obj_ids)
 Returns number of published/submitted objects. More...
 
 updatePublishedObjects ()
 Returns number of changed published records. More...
 
 cleanUpDeletedRecords ()
 
 logDebug (string $message)
 
 logError (string $message)
 

Detailed Description

Definition at line 35 of file AutomaticPublisher.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\MetaData\OERHarvester\CronJob\AutomaticPublisher::__construct ( protected PublisherInterface  $publisher,
protected SettingsInterface  $settings,
protected ObjectHandler  $object_handler,
protected StatusRepository  $status_repository,
protected ExposedRecordRepository  $exposed_record_repository,
protected CopyrightSearchFactory  $copyright_search_factory,
protected LOMRepository  $lom_repository,
protected SimpleDCXMLWriter  $xml_writer,
protected ilLogger  $logger 
)

Definition at line 37 of file AutomaticPublisher.php.

47 {
48 }

Member Function Documentation

◆ cleanUpDeletedRecords()

ILIAS\MetaData\OERHarvester\CronJob\AutomaticPublisher::cleanUpDeletedRecords ( )
protected

Definition at line 221 of file AutomaticPublisher.php.

221 : void
222 {
223 $this->exposed_record_repository->deleteRecordsMarkedAsDeletedOlderThan(
224 new \DateInterval('P30D')
225 );
226 }

◆ findHarvestableObjectIDs()

ILIAS\MetaData\OERHarvester\CronJob\AutomaticPublisher::findHarvestableObjectIDs ( )
protected

Definition at line 88 of file AutomaticPublisher.php.

88 : array
89 {
90 $searcher = $this->copyright_search_factory->get()
91 ->withRestrictionToRepositoryObjects(true);
92 foreach ($this->settings->getObjectTypesSelectedForPublishing() as $type) {
93 $searcher = $searcher->withAdditionalTypeFilter($type);
94 }
95 $search_results = [];
96 foreach ($searcher->search(
97 $this->lom_repository,
98 ...$this->settings->getCopyrightEntryIDsSelectedForPublishing()
99 ) as $ressource_id) {
100 $search_results[] = $ressource_id->objID();
101 }
102
103 $unblocked = $this->status_repository->filterOutBlockedObjects(...$search_results);
104 $results = [];
105 foreach ($unblocked as $obj_id) {
106 if ($this->object_handler->isObjectDeleted($obj_id)) {
107 continue;
108 }
109 $results[] = $obj_id;
110 }
111 return $results;
112 }
$results

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

Referenced by ILIAS\MetaData\OERHarvester\CronJob\AutomaticPublisher\run().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ logDebug()

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

Definition at line 228 of file AutomaticPublisher.php.

228 : void
229 {
230 $this->logger->debug($message);
231 }

References ILIAS\Repository\logger().

Referenced by ILIAS\MetaData\OERHarvester\CronJob\AutomaticPublisher\withdrawDeprecatedObjects().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ logError()

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

Definition at line 233 of file AutomaticPublisher.php.

233 : void
234 {
235 $this->logger->error($message);
236 }

References ILIAS\Repository\logger().

Referenced by ILIAS\MetaData\OERHarvester\CronJob\AutomaticPublisher\withdrawDeprecatedObjects().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ publishObjects()

ILIAS\MetaData\OERHarvester\CronJob\AutomaticPublisher::publishObjects ( array  $harvestable_obj_ids,
array  $currently_harvested_obj_ids 
)
protected

Returns number of published/submitted objects.

Parameters
int[]$harvestable_obj_ids
int[]$currently_harvested_obj_ids

Definition at line 152 of file AutomaticPublisher.php.

155 : int {
156 $count = 0;
157
158 foreach ($harvestable_obj_ids as $obj_id) {
159 if (in_array($obj_id, $currently_harvested_obj_ids)) {
160 continue;
161 }
162
163 $this->logDebug('Publishing object with obj_id: ' . $obj_id);
164 try {
165 if ($this->settings->isEditorialStepEnabled()) {
166 $this->publisher->submit($obj_id);
167 } else {
168 $type = $this->object_handler->getTypeOfObject($obj_id);
169 $this->publisher->publish($obj_id, $type);
170 }
171 } catch (\Exception $e) {
172 $this->logError(
173 'Error when publishing object with obj_id ' .
174 $obj_id . ': ' . $e->getMessage()
175 );
176 continue;
177 }
178
179 $count++;
180 }
181 return $count;
182 }

References Vendor\Package\$e, and ILIAS\Repository\settings().

Referenced by ILIAS\MetaData\OERHarvester\CronJob\AutomaticPublisher\run().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ run()

ILIAS\MetaData\OERHarvester\CronJob\AutomaticPublisher::run ( Result  $result)

Definition at line 50 of file AutomaticPublisher.php.

50 : Result
51 {
52 try {
53 $messages = [];
54
55 $harvestable_obj_ids = $this->findHarvestableObjectIDs();
56 $currently_harvested_obj_ids = iterator_to_array($this->status_repository->getAllHarvestedObjIDs());
57
58 $deletion_count = $this->withdrawDeprecatedObjects(
59 $harvestable_obj_ids,
60 $currently_harvested_obj_ids
61 );
62 $messages[] = 'Withdrew ' . $deletion_count . ' deprecated objects.';
63
64 $exposure_count = $this->updatePublishedObjects();
65 $messages[] = 'Updated ' . $exposure_count . ' published objects.';
66
67 $harvest_count = 0;
68 if ($this->settings->isAutomaticPublishingEnabled()) {
69 $harvest_count = $this->publishObjects(
70 $harvestable_obj_ids,
71 $currently_harvested_obj_ids
72 );
73 $messages[] = 'Published or submitted for review ' . $harvest_count . ' new objects.';
74 }
75
76 if ($deletion_count !== 0 || $harvest_count !== 0 || $exposure_count !== 0) {
77 $result = $result->withStatus(JobResult::STATUS_OK);
78 } else {
79 $result = $result->withStatus(JobResult::STATUS_NO_ACTION);
80 }
81 return $result->withMessage(implode('<br>', $messages));
82 } catch (\Exception $e) {
83 return $result->withStatus(JobResult::STATUS_FAIL)
84 ->withMessage($e->getMessage());
85 }
86 }
final const int STATUS_FAIL
Definition: JobResult.php:30
final const int STATUS_NO_ACTION
Definition: JobResult.php:26
final const int STATUS_OK
Definition: JobResult.php:27
withdrawDeprecatedObjects(array $harvestable_obj_ids, array $currently_harvested_obj_ids)
Returns number of deletions.
updatePublishedObjects()
Returns number of changed published records.
publishObjects(array $harvestable_obj_ids, array $currently_harvested_obj_ids)
Returns number of published/submitted objects.
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Result.php:29

References Vendor\Package\$e, ILIAS\MetaData\OERHarvester\CronJob\AutomaticPublisher\findHarvestableObjectIDs(), ILIAS\MetaData\OERHarvester\CronJob\AutomaticPublisher\publishObjects(), ILIAS\Repository\settings(), ILIAS\Cron\Job\JobResult\STATUS_FAIL, ILIAS\Cron\Job\JobResult\STATUS_NO_ACTION, ILIAS\Cron\Job\JobResult\STATUS_OK, ILIAS\MetaData\OERHarvester\CronJob\AutomaticPublisher\updatePublishedObjects(), and ILIAS\MetaData\OERHarvester\CronJob\AutomaticPublisher\withdrawDeprecatedObjects().

+ Here is the call graph for this function:

◆ updatePublishedObjects()

ILIAS\MetaData\OERHarvester\CronJob\AutomaticPublisher::updatePublishedObjects ( )
protected

Returns number of changed published records.

Definition at line 187 of file AutomaticPublisher.php.

187 : int
188 {
189 $count = 0;
190
191 foreach ($this->exposed_record_repository->getRecords() as $record) {
192 $obj_id = $record->infos()->objID();
193 $ref_id = $this->status_repository->getHarvestRefID($obj_id);
194
195 if (!$ref_id && $record->infos()->isDeleted()) {
196 continue;
197 }
198
199 $simple_dc_xml = $this->xml_writer->writeSimpleDCMetaData(
200 $obj_id,
201 $ref_id,
202 $this->object_handler->getTypeOfObject($obj_id)
203 );
204
205 if (
206 $record->infos()->isDeleted() ||
207 $simple_dc_xml->saveXML() !== $record->metadata()->saveXML()
208 ) {
209 // TODO should also be done by the publisher
210 $this->logDebug('Updating exposed record for object with obj_id: ' . $obj_id);
211 $this->exposed_record_repository->updateRecord($obj_id, false, $simple_dc_xml);
212 $count++;
213 }
214 }
215
216 $this->cleanUpDeletedRecords();
217
218 return $count;
219 }
$ref_id
Definition: ltiauth.php:66

References $ref_id.

Referenced by ILIAS\MetaData\OERHarvester\CronJob\AutomaticPublisher\run().

+ Here is the caller graph for this function:

◆ withdrawDeprecatedObjects()

ILIAS\MetaData\OERHarvester\CronJob\AutomaticPublisher::withdrawDeprecatedObjects ( 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 119 of file AutomaticPublisher.php.

122 : int {
123 $count = 0;
124 foreach ($currently_harvested_obj_ids as $obj_id) {
125 if (
126 in_array($obj_id, $harvestable_obj_ids) &&
127 $this->object_handler->doesReferenceExist($this->status_repository->getHarvestRefID($obj_id))
128 ) {
129 continue;
130 }
131
132 $this->logDebug('Withdrawing deprecated object with obj: ' . $obj_id);
133 try {
134 $this->publisher->withdraw($obj_id);
135 } catch (\Exception $e) {
136 $this->logError(
137 'Error when withdrawing from publishing object with obj_id ' .
138 $obj_id . ': ' . $e->getMessage()
139 );
140 continue;
141 }
142 $count++;
143 }
144 return $count;
145 }

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

Referenced by ILIAS\MetaData\OERHarvester\CronJob\AutomaticPublisher\run().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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