ILIAS  trunk Revision v11.0_alpha-1702-gfd3ecb7f852
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilCmiXapiDelCron.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 
33 {
34  public const JOB_ID = 'xapi_deletion_cron';
35 
37 
39 
40  protected ilLogger $log;
41 
42  private \ILIAS\DI\Container $dic;
43 
44  public function __construct()
45  {
46  global $DIC; /* @var \ILIAS\DI\Container $DIC */
47  $this->dic = $DIC;
48 
49  $DIC->language()->loadLanguageModule('cmix');
50 
51  $this->log = ilLoggerFactory::getLogger('cmix');
52 
53  $settings = new ilSetting(self::JOB_ID);
54  $lrsTypeId = $settings->get('lrs_type_id', '0');
55 
56  if ($lrsTypeId) {
57  $this->lrsType = new ilCmiXapiLrsType((int) $lrsTypeId);
58  } else {
59  $this->lrsType = null;
60  }
61 
62  $this->model = ilCmiXapiDelModel::init();
63  }
64 
65  public function getId(): string
66  {
67  return self::JOB_ID;
68  }
69 
70  public function getTitle(): string
71  {
72  return $this->dic->language()->txt("cron_xapi_del");
73  }
74 
75  public function getDescription(): string
76  {
77  return $this->dic->language()->txt("cron_xapi_del_desc");
78  }
79 
83  public function hasAutoActivation(): bool
84  {
85  return false;
86  }
87 
91  public function hasFlexibleSchedule(): bool
92  {
93  return true;
94  }
95 
97  {
98  return JobScheduleType::DAILY;
99  }
100 
101  public function getDefaultScheduleValue(): int
102  {
103  return 1;
104  }
105 
106  protected function hasLrsType()
107  {
108  return $this->getLrsType() !== null;
109  }
110 
111  protected function getLrsType()
112  {
113  return $this->lrsType;
114  }
115 
116  public function run(): JobResult
117  {
118  global $DIC;
119  $cronResult = new JobResult();
120  $this->log->debug('run');
121 
122  // LRS - Ist Client gelöscht?
123  // LRS - Wenn Client gelöscht dann nix machen
124  // LRS - Wenn Client gelöscht wirklich alle Daten weg?
125  // Wenn Objekt gelöscht warum wird es nochmal bei Nutzer aufgeführt (Tabelle gucken)
126  // xxx Löschen wenn nut Lernerfahrung anzeigen dann nur anzeigen nicht löschen = kein Datenadmin
127 
128  /*
129  Fall 1:
130  * Objekt deleted (in Tabelle xapidel_object eingetragen mit Feld updated=null)
131  => xapidel_object aktualisieren mit updated
132  => hole alle Daten zu Users aus xxcf_users und die Daten zum lrs und activity_id aus xapidel_object inkl. xxcf_data_types
133  => Löschvorgang an LRS-typ schicken
134  => wenn's geklappt hat: Zeile aus xxcf_users löschen
135  => wenn's für alle user geklappt hat: Zeile aus xxcf_data_settings löschen
136  => wenn ggf. auch user gelöscht wurde und der user nur dieses objekt bearbeitet hat, dann lösche auch Zeile in xpidel_user
137 
138 
139  Fall 2:
140  * User deleted (in Tabelle xapidel_user eingetragen mit Feld updated=null)
141  * Objekt noch vorhanden (kein Eintrag in Tabelle xapidel_object)
142  => xapidel_user aktualisieren mit updated
143  => hole alle Daten zum User aus xxcf_users und die Daten zum lrs und activity_id aus xxcf_settings inkl. xxcf_data_types
144  => Löschvorgang an LRS-typ schicken
145  => wenn's geklappt hat: Zeile aus xxcf_users löschen
146  => wenn's für alle Objekte, die der User genutzt hat, gelöscht wurde: Zeile in xapidel_user löschen
147 
148  Fall 3:
149  * User deleted (in Tabelle xapidel_user eingetragen mit Feld updated=null)
150  * Objekt auch deleted (Eintrag in Tabelle xapidel_object mit updated=null)
151  => xapidel_user aktualisieren mit updated
152  => xapidel_object aktualisieren mit updated
153  => hole alle Daten zum User aus xxcf_users und die Daten zum lrs und activity_id aus xapidel_object inkl. xxcf_data_types
154  => Löschvorgang an LRS-typ schicken
155  => wenn's geklappt hat: Zeile aus xxcf_users löschen
156  => wenn's für alle Objekte, die der User genutzt hat, gelöscht wurde: Zeile in xapidel_user löschen
157  => Zeile in Tabelle xapidel_object löschen
158 
159 
160 
161  */
162 
163 
164  //user deleted
165  //SELECT distinct LRS credentials for all objs - ACHTUNG Plugin-Version beachten!
166  //SELECT usr_id FROM xapidel_user
167  //usr_ids=..
168  //SELECT obj_id, user_cred WHERE user_id in (usr_ids)
169  //delete in lrs - wenn nicht in separate log-tabelle schreiben
170  //delete xxcf_users WHERE obj_id and user_cred
171  //if numrows for usr_id =0 DELETE FROM xapidel_user WHERE usr_id=%s
172 
173  //Hinweis auf negative Auswirkungen von lrs-typ-Änderungen für Lösch vorgänge
174 
175  //object deleted
176  //SELECT activity_id, lrs_cred FROM xapidel_obj, xxcf_data_types WHERE xxcf_data_types.type_id = xapidel_obj.type_d //ACHTUNG: endpoint_use egal, lrs_type_id genutzt?
177 
178 
179  //lrs_type_id deleted???
180 
181  /*
182  if( !$this->hasLrsType() )
183  {
184  ilLoggerFactory::getRootLogger()->alert('No lrs type configured!');
185  $cronResult->setStatus(ilCronJobResult::STATUS_INVALID_CONFIGURATION);
186  return $cronResult;
187  }
188  */
189  // $lpChangesQueue = new ilxapidelChangesQueue();
190  // $lpChangesQueue->load();
191 
192  // $statementListBuilder = new ilxapidelXapiStatementListBuilder(ilLoggerFactory::getRootLogger(), $this->getLrsType());
193  // $statementList = $statementListBuilder->buildStatementsList($lpChangesQueue);
194  /*
195  $lrsRequest = new ilxapidelXapiRequest(
196  ilLoggerFactory::getRootLogger(),
197  $this->getLrsType()->getLrsEndpointStatementsLink(),
198  $this->getLrsType()->getLrsKey(),
199  $this->getLrsType()->getLrsSecret()
200  );
201 
202  if( $lrsRequest->send($statementList) )
203  {
204  if( $lpChangesQueue->hasEntries() )
205  {
206  $lpChangesQueue->delete();
207  $cronResult->setStatus(ilCronJobResult::STATUS_OK);
208  }
209  else
210  {
211  $cronResult->setStatus(ilCronJobResult::STATUS_NO_ACTION);
212  }
213  }
214  else
215  {
216  $cronResult->setStatus(ilCronJobResult::STATUS_FAIL);
217  }
218  */
219 
220  // Fall 1:
221  // check deleted objects where updated = NULL
222 
223  $newDeletedObjects = $this->model->getNewDeletedXapiObjects();
224  //ilLoggerFactory::getRootLogger()->alert(var_export($newDeletedObjects,TRUE));
225 
226  $deletedObjectData = array();
227  $allDone = true;
228  foreach ($newDeletedObjects as $deletedObject) {
229  $this->log->debug("delete for " . (string) $deletedObject['obj_id']);
230  // set object to updated
231  $this->model->setXapiObjAsUpdated($deletedObject['obj_id']);
232  // delete data
233  $deleteRequest = new ilCmiXapiStatementsDeleteRequest(
234  (int) $deletedObject['obj_id'],
235  (int) $deletedObject['type_id'],
236  (string) $deletedObject['activity_id'],
237  null,
239  );
240  $done = $deleteRequest->delete();
241  // entry in xxcf_users is already deleted from ilXapiCmi5StatementsDeleteRequest
242  // delete in obj_id from xxcf_data_settings
243  if ($done) {
244  $this->log->debug("deleted data for object: " . (string) $deletedObject['obj_id']);
245  $deletedObjectData[] = $deletedObject['obj_id'];
246  $this->model->deleteXapiObjectEntry($deletedObject['obj_id']);
247  } else {
248  $this->log->debug("error: delete data for object: " . (string) $deletedObject['obj_id']);
249  $this->model->resetUpdatedXapiObj($deletedObject['obj_id']);
250  $allDone = false;
251  }
252  }
253 
254  // Fall 2:
255  // check deleted users where updated = NULL
256  $newDeletedUsers = $this->model->getNewDeletedUsers();
257  foreach ($newDeletedUsers as $deletedUser) {
258  $usrId = $deletedUser['usr_id'];
259  // set user to updated
260  $this->model->setUserAsUpdated($usrId);
261  // get all objects of deleted user
262  $xapiObjects = $this->model->getXapiObjectsByUser($usrId);
263  $usrObjectsDone = true;
264  foreach ($xapiObjects as $xapiObject) {
265  $objId = $xapiObject['obj_id'];
266  // check if all object data already successfully deleted in previous step within this run, because object was also deleted
267  if (in_array($objId, $deletedObjectData)) {
268  $this->log->debug("nothing to do, because of complete object data deletion in previous step");
269  continue;
270  }
271  $deleteRequest = new ilCmiXapiStatementsDeleteRequest(
272  (int) $xapiObject['obj_id'],
273  (int) $xapiObject['lrs_type_id'],
274  (string) $xapiObject['activity_id'],
275  $usrId,
277  );
278  $done = $deleteRequest->delete();
279  // entry in xxcf_users is already deleted from ilXapiCmi5StatementsDeleteRequest
280  if ($done) {
281  $this->log->debug("deleted object " . (string) $objId . " data for user " . (string) $usrId);
282  } else {
283  $this->log->debug("error deleting object " . (string) $objId . " data for user " . (string) $usrId);
284  $usrObjectsDone = false;
285  }
286  } // EOF foreach ($xapiObjects as $xapiObject)
287 
288  if ($usrObjectsDone) {
289  $this->model->deleteUserEntry($usrId);
290  } else {
291  $this->model->resetUpdatedXapiUser($usrId);
292  $allDone = false;
293  }
294  }
295 
296  // Fall 3 wird noch gebraucht?
297 
298  // maybe more detailled success/fail messages?
299 
300  if ($allDone) {
301  $cronResult->setStatus(JobResult::STATUS_OK);
302  } else {
303  $cronResult->setStatus(JobResult::STATUS_FAIL);
304  }
305  return $cronResult;
306  }
307 }
static getLogger(string $a_component_id)
Get component logger.
hasAutoActivation()
@inheritdoc
$objId
Definition: xapitoken.php:57
Class ilCmiXapiStatementsDeleteRequest.
Class ilCmiXapiDelCron.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
hasFlexibleSchedule()
@inheritdoc
ilCmiXapiDelModel $model
global $DIC
Definition: shib_login.php:22
Class ilCmiXapiDelModel.
ILIAS DI Container $dic
ilCmiXapiLrsType $lrsType