ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilOerHarvester Class Reference

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

+ Collaboration diagram for ilOerHarvester:

Public Member Functions

 __construct (ilCronJobResult $result)
 ilOerHarvester constructor. More...
 
 run ()
 run harvester More...
 

Protected Member Functions

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

Private Attributes

 $logger = null
 
 $cronresult = null
 
 $settings = null
 

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 11 of file class.ilOerHarvester.php.

Constructor & Destructor Documentation

◆ __construct()

ilOerHarvester::__construct ( ilCronJobResult  $result)

ilOerHarvester constructor.

Parameters
\ilCronJobResult$result

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

References $DIC, $result, ilOerHarvesterSettings\getInstance(), and settings().

34  {
35  global $DIC;
36 
37  $this->logger = $DIC->logger()->meta();
38  $this->cronresult = $result;
40  }
settings()
Definition: settings.php:2
$result
global $DIC
Definition: saml.php:7
+ 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 77 of file class.ilOerHarvester.php.

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

Referenced by run().

78  {
79  $collectable_types = $this->settings->getHarvestingTypes();
80  $copyright_ids = $this->settings->getCopyRightTemplatesInLomFormat();
81 
82  $collectable_obj_ids = ilMDRights::lookupRightsByTypeAndCopyright(
83  $collectable_types,
84  $copyright_ids
85  );
86 
87  $this->logger->debug('Found ' . count($collectable_types) . ' collectable objects.');
88  $this->logger->dump($collectable_obj_ids, ilLogLevel::DEBUG);
89 
90  return $collectable_obj_ids;
91  }
settings()
Definition: settings.php:2
static lookupRightsByTypeAndCopyright(array $a_types, array $a_copyright)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deleteDeprecated()

ilOerHarvester::deleteDeprecated ( )
protected

Delete deprecated.

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

References ilMDRights\_lookupDescription(), ilObject\_lookupObjId(), deleteObject(), ilOerHarvesterObjectStatus\lookupHarvested(), and settings().

Referenced by run().

203  {
204  $num_deleted = 0;
205  foreach (ilOerHarvesterObjectStatus::lookupHarvested() as $ref_id) {
206  $obj_id = ilObject::_lookupObjId($ref_id);
207 
208  // blocked items are always deleted
209  $status = new ilOerHarvesterObjectStatus($obj_id);
210  if ($status->isBlocked()) {
211  $this->logger->debug('Deleting blocked object ressource.');
212  $this->deleteObject($ref_id);
213  $num_deleted++;
214  continue;
215  }
216 
217  $copyright = ilMDRights::_lookupDescription($obj_id, $obj_id);
218  $is_valid = false;
219  foreach ($this->settings->getCopyRightTemplatesInLomFormat() as $cp) {
220  if (strcmp($copyright, $cp) === 0) {
221  $is_valid = true;
222  }
223  }
224 
225  if (!$is_valid) {
226  $this->logger->debug('Deleting deprecated object with ref_id: ' . $ref_id);
227  $this->deleteObject($ref_id);
228  $num_deleted++;
229  }
230  }
231  return $num_deleted;
232  }
settings()
Definition: settings.php:2
static _lookupDescription($a_rbac_id, $a_obj_id)
Lookup description (copyright)
static _lookupObjId($a_id)
deleteObject($a_ref_id)
Delete object.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deleteObject()

ilOerHarvester::deleteObject (   $a_ref_id)
protected

Delete object.

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

References ilObjectFactory\getInstanceByRefId(), and ilOerHarvesterObjectStatus\lookupObjIdByHarvestingId().

Referenced by deleteDeprecated().

182  {
183  $object = ilObjectFactory::getInstanceByRefId($a_ref_id, false);
184 
185  if (!$object instanceof ilObject) {
186  $this->logger->warning('Found invalid reference: ' . $a_ref_id);
187  return false;
188  }
189  $this->logger->debug('Deleting reference...');
190  $object->delete();
191 
192 
193  $status = new ilOerHarvesterObjectStatus(
195  );
196  $status->delete();
197  }
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ filter()

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

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

References $DIC, $tree, ilObject\_getAllReferences(), and ilLogLevel\DEBUG.

Referenced by run().

97  {
98  global $DIC;
99 
100  $tree = $DIC->repositoryTree();
101 
102  $filtered = [];
103  foreach ($a_collectable_obj_ids as $obj_id) {
104  $status = new ilOerHarvesterObjectStatus($obj_id);
105  if ($status->isCreated()) {
106  $this->logger->debug('Object already created: ' . $obj_id);
107  continue;
108  }
109  if ($status->isBlocked()) {
110  $this->logger->debug('Object creation is blocked: ' . $obj_id);
111  continue;
112  }
113 
114  $exists = false;
115  foreach (ilObject::_getAllReferences($obj_id) as $ref_id => $tmp) {
116  if (!$tree->isDeleted($ref_id)) {
117  $exists = true;
118  }
119  }
120  if (!$exists) {
121  $this->logger->notice('Ignoring deleted object: ' . $obj_id);
122  continue;
123  }
124  $filtered[] = $obj_id;
125  }
126 
127  $this->logger->debug('Result after filtering.');
128  $this->logger->dump($filtered, ilLogLevel::DEBUG);
129 
130  return $filtered;
131  }
global $DIC
Definition: saml.php:7
static _getAllReferences($a_id)
get all reference ids of object
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ harvest()

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

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

References ilObject\_getAllReferences(), ilObjectFactory\getInstanceByRefId(), and harvestObject().

Referenced by run().

138  {
139  $num = 0;
140  foreach ($a_collectable_obj_ids as $obj_id) {
141  $ref_ids = ilObject::_getAllReferences($obj_id);
142  $ref_id = end($ref_ids);
143 
144  $object = ilObjectFactory::getInstanceByRefId($ref_id, false);
145 
146  if (!$object instanceof ilObject) {
147  $this->logger->warning('Found invalid reference: ' . $ref_id);
148  }
149  $this->logger->debug('Creating new reference for object: ' . $obj_id);
150  $this->harvestObject($object);
151  $num++;
152  }
153  return $num;
154  }
static _getAllReferences($a_id)
get all reference ids of object
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
harvestObject(ilObject $object)
Harvest object.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ harvestObject()

ilOerHarvester::harvestObject ( ilObject  $object)
protected

Harvest object.

Parameters
$ref_id

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

References ilObject\createReference(), ilObject\getId(), ilObject\putInTree(), ilOerHarvesterObjectStatus\setHarvestRefId(), ilObject\setPermissions(), and settings().

Referenced by harvest().

161  {
162  $this->logger->debug('Create new reference');
163  $new_ref_id = $object->createReference();
164  $this->logger->debug('Put in tree');
165  $object->putInTree($this->settings->getTarget());
166  $this->logger->debug('Set pernissions');
167  $object->setPermissions($this->settings->getTarget());
168 
169  $this->logger->debug('Set status');
170  $status = new ilOerHarvesterObjectStatus($object->getId());
171  $status->setHarvestRefId($new_ref_id);
172  $status->setBlocked(false);
173  $status->save();
174 
175  return true;
176  }
settings()
Definition: settings.php:2
createReference()
creates reference for object
getId()
get object id public
putInTree($a_parent_ref)
maybe this method should be in tree object!?
setPermissions($a_parent_ref)
set permissions of object
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ run()

ilOerHarvester::run ( )

run harvester

Returns
ilCronJobResult

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

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

47  {
48  try {
49  $obj_ids = $this->collect();
50  $obj_ids = $this->filter($obj_ids);
51  $num = $this->harvest($obj_ids);
52 
53  $message = 'Created ' . $num . ' new objects. <br />';
54 
55  $deleted = $this->deleteDeprecated();
56 
57  $message .= 'Deleted ' . $deleted . ' deprecated objects.';
58 
59  if (!$deleted && !$num) {
60  $this->cronresult->setStatus(ilCronJobResult::STATUS_NO_ACTION);
61  } else {
62  $this->cronresult->setStatus(ilCronJobResult::STATUS_OK);
63  }
64  $this->cronresult->setMessage($message);
65  return $this->cronresult;
66  } catch (Exception $e) {
67  $this->cronresult->setStatus(ilCronJobResult::STATUS_FAIL);
68  $this->cronresult->setMessage($e->getMessage());
69  return $this->cronresult;
70  }
71  }
deleteDeprecated()
Delete deprecated.
harvest($a_collectable_obj_ids)
collect()
Collect all obj_ids with copyright settings which are collectable.
catch(Exception $e) $message
filter($a_collectable_obj_ids)
+ Here is the call graph for this function:

Field Documentation

◆ $cronresult

ilOerHarvester::$cronresult = null
private

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

Referenced by run().

◆ $logger

ilOerHarvester::$logger = null
private

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

◆ $settings

ilOerHarvester::$settings = null
private

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


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