ILIAS  release_8 Revision v8.24
ilOerHarvester Class Reference

Cron job for definition for oer harvesting. More...

+ Collaboration diagram for ilOerHarvester:

Public Member Functions

 __construct (ilCronJobResult $result)
 
 run ()
 

Protected Member Functions

 collect ()
 Collect all obj_ids with copyright settings which are collectable. More...
 
 filter (array $a_collectable_obj_ids)
 
 harvest (array $a_collectable_obj_ids)
 
 harvestObject (ilObject $object)
 
 deleteObject (int $a_ref_id)
 
 deleteDeprecated ()
 

Protected Attributes

ilTree $tree
 

Private Attributes

ilLogger $logger
 
ilCronJobResult $cronresult
 
ilOerHarvesterSettings $settings
 

Detailed Description

Cron job for definition for oer harvesting.

Author
Stefan Meyer smeye.nosp@m.r.il.nosp@m.ias@g.nosp@m.mx.d.nosp@m.e

Definition at line 13 of file class.ilOerHarvester.php.

Constructor & Destructor Documentation

◆ __construct()

ilOerHarvester::__construct ( ilCronJobResult  $result)

Definition at line 23 of file class.ilOerHarvester.php.

24 {
25 global $DIC;
26
27 $this->tree = $DIC->repositoryTree();
28 $this->logger = $DIC->logger()->meta();
29 $this->cronresult = $result;
31 }
global $DIC
Definition: feed.php:28

References $DIC, ilOerHarvesterSettings\getInstance(), ILIAS\Repository\logger(), and ILIAS\Repository\settings().

+ Here is the call graph for this function:

Member Function Documentation

◆ collect()

ilOerHarvester::collect ( )
protected

Collect all obj_ids with copyright settings which are collectable.

Returns
int[]

Definition at line 64 of file class.ilOerHarvester.php.

64 : array
65 {
66 $collectable_types = $this->settings->getHarvestingTypes();
67 $copyright_ids = $this->settings->getCopyRightTemplatesInLomFormat();
68
69 $collectable_obj_ids = ilMDRights::lookupRightsByTypeAndCopyright(
70 $collectable_types,
71 $copyright_ids
72 );
73
74 $this->logger->debug('Found ' . count($collectable_types) . ' collectable objects.');
75 $this->logger->dump($collectable_obj_ids, ilLogLevel::DEBUG);
76
77 return $collectable_obj_ids;
78 }
static lookupRightsByTypeAndCopyright(array $a_types, array $a_copyright)

References ilLogLevel\DEBUG, ILIAS\Repository\logger(), ilMDRights\lookupRightsByTypeAndCopyright(), and ILIAS\Repository\settings().

Referenced by run().

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

◆ deleteDeprecated()

ilOerHarvester::deleteDeprecated ( )
protected

Definition at line 175 of file class.ilOerHarvester.php.

175 : int
176 {
177 $num_deleted = 0;
180
181 // blocked items are always deleted
182 $status = new ilOerHarvesterObjectStatus($obj_id);
183 if ($status->isBlocked()) {
184 $this->logger->debug('Deleting blocked object ressource.');
185 $this->deleteObject($ref_id);
186 $num_deleted++;
187 continue;
188 }
189
190 $copyright = ilMDRights::_lookupDescription($obj_id, $obj_id);
191 $is_valid = false;
192 foreach ($this->settings->getCopyRightTemplatesInLomFormat() as $cp) {
193 if (strcmp($copyright, $cp) === 0) {
194 $is_valid = true;
195 }
196 }
197
198 if (!$is_valid) {
199 $this->logger->debug('Deleting deprecated object with ref_id: ' . $ref_id);
200 $this->deleteObject($ref_id);
201 $num_deleted++;
202 }
203 }
204 return $num_deleted;
205 }
static _lookupDescription(int $a_rbac_id, int $a_obj_id)
static _lookupObjId(int $ref_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
deleteObject(int $a_ref_id)
$ref_id
Definition: ltiauth.php:67

References $ref_id, ilMDRights\_lookupDescription(), ilObject\_lookupObjId(), deleteObject(), ILIAS\Repository\logger(), ilOerHarvesterObjectStatus\lookupHarvested(), and ILIAS\Repository\settings().

Referenced by run().

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

◆ deleteObject()

ilOerHarvester::deleteObject ( int  $a_ref_id)
protected

Definition at line 157 of file class.ilOerHarvester.php.

157 : bool
158 {
159 $object = ilObjectFactory::getInstanceByRefId($a_ref_id, false);
160
161 if (!$object instanceof ilObject) {
162 $this->logger->warning('Found invalid reference: ' . $a_ref_id);
163 return false;
164 }
165 $this->logger->debug('Deleting reference...');
166 $object->delete();
167
168 $status = new ilOerHarvesterObjectStatus(
170 );
171 $status->delete();
172 return true;
173 }
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

References ilObjectFactory\getInstanceByRefId(), ILIAS\Repository\logger(), and ilOerHarvesterObjectStatus\lookupObjIdByHarvestingId().

Referenced by deleteDeprecated().

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

◆ filter()

ilOerHarvester::filter ( array  $a_collectable_obj_ids)
protected
Parameters
int[]$a_collectable_obj_ids
Returns
int[]

Definition at line 84 of file class.ilOerHarvester.php.

84 : array
85 {
86 $filtered = [];
87 foreach ($a_collectable_obj_ids as $obj_id) {
88 $status = new ilOerHarvesterObjectStatus($obj_id);
89 if ($status->isCreated()) {
90 $this->logger->debug('Object already created: ' . $obj_id);
91 continue;
92 }
93 if ($status->isBlocked()) {
94 $this->logger->debug('Object creation is blocked: ' . $obj_id);
95 continue;
96 }
97
98 $exists = false;
99 foreach (ilObject::_getAllReferences($obj_id) as $ref_id => $tmp) {
100 if (!$this->tree->isDeleted($ref_id)) {
101 $exists = true;
102 }
103 }
104 if (!$exists) {
105 $this->logger->notice('Ignoring deleted object: ' . $obj_id);
106 continue;
107 }
108 $filtered[] = $obj_id;
109 }
110
111 $this->logger->debug('Result after filtering.');
112 $this->logger->dump($filtered, ilLogLevel::DEBUG);
113
114 return $filtered;
115 }
static _getAllReferences(int $id)
get all reference ids for object ID

References $ref_id, ilObject\_getAllReferences(), ilLogLevel\DEBUG, and ILIAS\Repository\logger().

Referenced by run().

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

◆ harvest()

ilOerHarvester::harvest ( array  $a_collectable_obj_ids)
protected
Parameters
int[]$a_collectable_obj_ids

Definition at line 120 of file class.ilOerHarvester.php.

120 : int
121 {
122 $num = 0;
123 foreach ($a_collectable_obj_ids as $obj_id) {
124 $ref_ids = ilObject::_getAllReferences($obj_id);
125 $ref_id = end($ref_ids);
126
128
129 if (!$object instanceof ilObject) {
130 $this->logger->warning('Found invalid reference: ' . $ref_id);
131 }
132 $this->logger->debug('Creating new reference for object: ' . $obj_id);
133 $this->harvestObject($object);
134 $num++;
135 }
136 return $num;
137 }
harvestObject(ilObject $object)

References $ref_id, ilObject\_getAllReferences(), ilObjectFactory\getInstanceByRefId(), harvestObject(), and ILIAS\Repository\logger().

Referenced by run().

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

◆ harvestObject()

ilOerHarvester::harvestObject ( ilObject  $object)
protected

Definition at line 139 of file class.ilOerHarvester.php.

139 : bool
140 {
141 $this->logger->debug('Create new reference');
142 $new_ref_id = $object->createReference();
143 $this->logger->debug('Put in tree');
144 $object->putInTree($this->settings->getTarget());
145 $this->logger->debug('Set pernissions');
146 $object->setPermissions($this->settings->getTarget());
147
148 $this->logger->debug('Set status');
149 $status = new ilOerHarvesterObjectStatus($object->getId());
150 $status->setHarvestRefId($new_ref_id);
151 $status->setBlocked(false);
152 $status->save();
153
154 return true;
155 }
setPermissions(int $parent_ref_id)
createReference()
creates reference for object
putInTree(int $parent_ref_id)
maybe this method should be in tree object!?

References ilObject\createReference(), ilObject\getId(), ILIAS\Repository\logger(), ilObject\putInTree(), ilObject\setPermissions(), and ILIAS\Repository\settings().

Referenced by harvest().

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

◆ run()

ilOerHarvester::run ( )

Definition at line 33 of file class.ilOerHarvester.php.

34 {
35 try {
36 $obj_ids = $this->collect();
37 $obj_ids = $this->filter($obj_ids);
38 $num = $this->harvest($obj_ids);
39
40 $message = 'Created ' . $num . ' new objects. <br />';
41
42 $deleted = $this->deleteDeprecated();
43
44 $message .= 'Deleted ' . $deleted . ' deprecated objects.';
45
46 if (!$deleted && !$num) {
47 $this->cronresult->setStatus(ilCronJobResult::STATUS_NO_ACTION);
48 } else {
49 $this->cronresult->setStatus(ilCronJobResult::STATUS_OK);
50 }
51 $this->cronresult->setMessage($message);
52 return $this->cronresult;
53 } catch (Exception $e) {
54 $this->cronresult->setStatus(ilCronJobResult::STATUS_FAIL);
55 $this->cronresult->setMessage($e->getMessage());
56 return $this->cronresult;
57 }
58 }
ilCronJobResult $cronresult
harvest(array $a_collectable_obj_ids)
collect()
Collect all obj_ids with copyright settings which are collectable.
filter(array $a_collectable_obj_ids)
$message
Definition: xapiexit.php:32

References $cronresult, Vendor\Package\$e, $message, collect(), deleteDeprecated(), filter(), harvest(), ilCronJobResult\setStatus(), ilCronJobResult\STATUS_FAIL, ilCronJobResult\STATUS_NO_ACTION, and ilCronJobResult\STATUS_OK.

+ Here is the call graph for this function:

Field Documentation

◆ $cronresult

ilCronJobResult ilOerHarvester::$cronresult
private

Definition at line 17 of file class.ilOerHarvester.php.

Referenced by run().

◆ $logger

ilLogger ilOerHarvester::$logger
private

Definition at line 15 of file class.ilOerHarvester.php.

◆ $settings

ilOerHarvesterSettings ilOerHarvester::$settings
private

Definition at line 19 of file class.ilOerHarvester.php.

◆ $tree

ilTree ilOerHarvester::$tree
protected

Definition at line 21 of file class.ilOerHarvester.php.


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