Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/release_9' into release_9
Browse files Browse the repository at this point in the history
  • Loading branch information
mjansenDatabay committed Apr 15, 2024
2 parents 86492c4 + 43e47d0 commit 3dcfeee
Show file tree
Hide file tree
Showing 60 changed files with 1,034 additions and 896 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ public function initForm(
$desc = new ilTextAreaInputGUI($lng->txt("description"), "desc");
$desc->setCols(70);
$desc->setRows(15);
$desc->setMaxNumOfChars(1000);
$form_gui->addItem($desc);

$file = new ilFileInputGUI($lng->txt("book_additional_info_file"), "file");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,17 @@ public function step_16(): void
$this->db->addPrimaryKey("cmix_del_object", array("obj_id", "type_id", "activity_id"));
}
}
public function step_17(): void
{
if (!$this->db->tableColumnExists('cmix_del_user', 'obj_id')) {
$this->db->addTableColumn('cmix_del_user', 'obj_id', array(
'type' => 'integer',
'length' => 4,
'notnull' => true
));
$this->db->manipulate('DELETE FROM cmix_del_user');
$this->db->dropPrimaryKey('cmix_del_user');
$this->db->addPrimaryKey('cmix_del_user', array('usr_id','obj_id'));
}
}
}
69 changes: 50 additions & 19 deletions Modules/CmiXapi/classes/class.ilCmiXapiAppEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,32 @@ public static function handleEvent(string $component, string $event, array $para

private static function onServiceUserDeleteUser(array $parameter): void
{
/* nicht testbar aktuell
$usr_id = $parameter['usr_id'];
$model = ilCmiXapiDelModel::init();

// null or array with objIds, if are going to need more
$xapiObjUser = $model->getXapiObjIdForUser($usr_id);
if(!is_null($xapiObjUser)) {
// add user as deleted
$model->setXapiUserAsDeleted($usr_id);
for ((int) $i = 0; $i < count($xapiObjUser); $i++) {
$xapiObject = $model->getXapiObjectData($xapiObjUser[$i]);
if(!is_null($xapiObject)) {
if ((int) $xapiObject['delete_data'] != 0) {
if((int) $xapiObject['delete_data'] < 10) {
//remove only ident
$model->removeCmixUsersForObjectAndUser($xapiObjUser[$i], $usr_id);
} else {
// add obj as deleted
$model->setXapiObjAsDeletedForUser($xapiObjUser[$i], $xapiObject['lrs_type_id'], $xapiObject['activity_id'], $usr_id);
}
}
}
}
}
*/

// if(!is_null($xapiObjUser)) {
// // add user as deleted
// $model->setXapiUserAsDeleted($usr_id);
// }
}

private static function onServiceObjectDeleteOrToTrash(array $parameter): void
Expand Down Expand Up @@ -111,26 +126,42 @@ private static function onServiceObjectDeleteOrToTrash(array $parameter): void

private static function removeMembers(string $src_type, array $parameter): void
{
global $DIC;
$tree = $DIC->repositoryTree();

$usr_id = $parameter['usr_id'];
$id = $parameter['obj_id'];
$crs_id = $parameter['obj_id'];
if (
$src_type === 'grp' || $src_type === 'crs'
) {
$ref_ids = ilObject::_getAllReferences($id);
$id = array_shift($ref_ids);
}
//stimmt so nicht: brauche array mit IDs
if (ilObject::_lookupType($id, true) !== "cmix") {
return;
}
$crs_ref_ids = ilObject::_getAllReferences($crs_id);
$idc = array_shift($crs_ref_ids);

// $model = ilCmiXapiDelModel::init();
// $objId = (int) $parameter['obj_id'];
// $xapiObject = $model->getXapiObjectData($objId);
// if( !is_null($xapiObject) ) {
// // add obj as deleted
// $model->setXapiObjAsDeleted($objId, $xapiObject['lrs_type_id'], $xapiObject['activity_id']);
// }
//Todo check Verknüpfungen?
$ref_ids = $tree->getSubTreeIds($idc);
for ((int) $i = 0; $i < count($ref_ids); $i++) {
if (ilObject::_lookupType($ref_ids[$i], true) == "cmix") {
$objId = ilObject::_lookupObjectId($ref_ids[$i]);
$model = ilCmiXapiDelModel::init();
$xapiObject = $model->getXapiObjectData($objId);
if(!is_null($xapiObject)) {
$xapiObjUser = $model->getXapiObjIdForUser($usr_id);
if(!is_null($xapiObjUser)) {
// add user as deleted
if ((int) $xapiObject['delete_data'] != 0) {
if ((int) $xapiObject['delete_data'] < 10) {
//remove only ident
$model->removeCmixUsersForObjectAndUser($objId, $usr_id);
} else {
// add obj as deleted
$model->setXapiObjAsDeletedForUser($objId, $xapiObject['lrs_type_id'], $xapiObject['activity_id'], $usr_id);
}
}
}
}
}
}
}
}


Expand Down
114 changes: 22 additions & 92 deletions Modules/CmiXapi/classes/class.ilCmiXapiDelCron.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,65 +154,6 @@ public function run(): ilCronJobResult
=> wenn's für alle Objekte, die der User genutzt hat, gelöscht wurde: Zeile in xapidel_user löschen
=> Zeile in Tabelle xapidel_object löschen
*/


//user deleted
//SELECT distinct LRS credentials for all objs - ACHTUNG Plugin-Version beachten!
//SELECT usr_id FROM xapidel_user
//usr_ids=..
//SELECT obj_id, user_cred WHERE user_id in (usr_ids)
//delete in lrs - wenn nicht in separate log-tabelle schreiben
//delete xxcf_users WHERE obj_id and user_cred
//if numrows for usr_id =0 DELETE FROM xapidel_user WHERE usr_id=%s

//Hinweis auf negative Auswirkungen von lrs-typ-Änderungen für Lösch vorgänge

//object deleted
//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?

//lrs_type_id deleted???
/*
if( !$this->hasLrsType() )
{
ilLoggerFactory::getRootLogger()->alert('No lrs type configured!');
$cronResult->setStatus(ilCronJobResult::STATUS_INVALID_CONFIGURATION);
return $cronResult;
}
*/
// $lpChangesQueue = new ilxapidelChangesQueue();
// $lpChangesQueue->load();

// $statementListBuilder = new ilxapidelXapiStatementListBuilder(ilLoggerFactory::getRootLogger(), $this->getLrsType());
// $statementList = $statementListBuilder->buildStatementsList($lpChangesQueue);
/*
$lrsRequest = new ilxapidelXapiRequest(
ilLoggerFactory::getRootLogger(),
$this->getLrsType()->getLrsEndpointStatementsLink(),
$this->getLrsType()->getLrsKey(),
$this->getLrsType()->getLrsSecret()
);
if( $lrsRequest->send($statementList) )
{
if( $lpChangesQueue->hasEntries() )
{
$lpChangesQueue->delete();
$cronResult->setStatus(ilCronJobResult::STATUS_OK);
}
else
{
$cronResult->setStatus(ilCronJobResult::STATUS_NO_ACTION);
}
}
else
{
$cronResult->setStatus(ilCronJobResult::STATUS_FAIL);
}
*/

// Fall 1:
Expand Down Expand Up @@ -254,46 +195,35 @@ public function run(): ilCronJobResult
$newDeletedUsers = $this->model->getNewDeletedUsers();
foreach ($newDeletedUsers as $deletedUser) {
$usrId = $deletedUser['usr_id'];
$objId = $deletedUser['obj_id'];
// set user to updated
$this->model->setUserAsUpdated($usrId);
// get all objects of deleted user
$xapiObjects = $this->model->getXapiObjectsByUser($usrId);
$usrObjectsDone = true;
foreach ($xapiObjects as $xapiObject) {
$objId = $xapiObject['obj_id'];
// check if all object data already successfully deleted in previous step within this run, because object was also deleted
if (in_array($objId, $deletedObjectData)) {
$this->log->debug("nothing to do, because of complete object data deletion in previous step");
continue;
}
$deleteRequest = new ilCmiXapiStatementsDeleteRequest(
(int) $xapiObject['obj_id'],
(int) $xapiObject['lrs_type_id'],
(string) $xapiObject['activity_id'],
$usrId,
ilCmiXapiStatementsDeleteRequest::DELETE_SCOPE_OWN
);
$done = $deleteRequest->delete();
// entry in xxcf_users is already deleted from ilXapiCmi5StatementsDeleteRequest
if ($done) {
$this->log->debug("deleted object " . (string) $objId . " data for user " . (string) $usrId);
} else {
$this->log->debug("error deleting object " . (string) $objId . " data for user " . (string) $usrId);
$usrObjectsDone = false;
}
} // EOF foreach ($xapiObjects as $xapiObject)

if ($usrObjectsDone) {
$this->model->deleteUserEntry($usrId);
$xapiObject = $this->model->getXapiObjectData($objId);
// check if all object data already successfully deleted in previous step within this run, because object was also deleted
if (in_array($objId, $deletedObjectData)) {
$this->log->debug("nothing to do, because of complete object data deletion in previous step");
continue;
}
$deleteRequest = new ilCmiXapiStatementsDeleteRequest(
(int) $objId,
(int) $xapiObject['lrs_type_id'],
(string) $xapiObject['activity_id'],
$usrId,
ilCmiXapiStatementsDeleteRequest::DELETE_SCOPE_OWN
);
$done = $deleteRequest->delete();
// entry in xxcf_users is already deleted from ilXapiCmi5StatementsDeleteRequest
if ($done) {
$this->model->deleteUserEntry($usrId, $objId);
$this->log->debug("deleted object " . (string) $objId . " data for user " . (string) $usrId);
} else {
$this->model->resetUpdatedXapiUser($usrId);
$this->log->debug("error deleting object " . (string) $objId . " data for user " . (string) $usrId);
$this->model->resetUpdatedXapiUser($usrId, $objId);
$allDone = false;
}
}

// Fall 3 wird noch gebraucht?
// maybe more detailled success/fail messages?
// Fall 3 wird noch gebraucht? NEIN

if ($allDone) {
$cronResult->setStatus(ilCronJobResult::STATUS_OK);
Expand Down
66 changes: 52 additions & 14 deletions Modules/CmiXapi/classes/class.ilCmiXapiDelModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,13 @@ public function setUserAsUpdated(int $usrId)
]);
}

public function resetUpdatedXapiUser(int $usrId)
public function resetUpdatedXapiUser(int $usrId, int $objId)
{
$this->db->update(self::DB_DEL_USERS, [
'updated' => ['timestamp', null]
], [
'usr_id' => ['integer', $usrId]
'usr_id' => ['integer', $usrId],
'obj_id' => ['integer', $objId]
]);
}

Expand Down Expand Up @@ -145,12 +146,12 @@ public function getNewDeletedUsers()
return $data;
}

public function deleteUserEntry($usrId)
public function deleteUserEntry($usrId, $objId)
{
$this->db->manipulateF(
'DELETE FROM ' . self::DB_DEL_USERS . ' WHERE usr_id = %s',
['integer'],
[$usrId]
'DELETE FROM ' . self::DB_DEL_USERS . ' WHERE usr_id = %s AND obj_id = %s',
['integer', 'integer'],
[$usrId, $objId]
);
}

Expand Down Expand Up @@ -200,20 +201,48 @@ public function deleteXapiObjectEntry($objId)

public function setXapiObjAsDeleted(int $objId, int $typeId, string $actId): void
{
$values = [
'obj_id' => ['integer', $objId],
'type_id' => ['integer', $typeId],
'activity_id' => ['string', $actId],
'added' => ['timestamp', date('Y-m-d H:i:s')]
];
$this->db->insert(self::DB_DEL_OBJ, $values);

if(!$this->dic->cron()->manager()->isJobActive('xapi_deletion_cron')) {
$xapiDelete = new ilCmiXapiStatementsDeleteRequest($objId, $typeId, $actId, null, ilCmiXapiStatementsDeleteRequest::DELETE_SCOPE_ALL);
$xapiDelete->delete();
} else {
$values = [
'obj_id' => ['integer', $objId],
'type_id' => ['integer', $typeId],
'activity_id' => ['string', $actId],
'added' => ['timestamp', date('Y-m-d H:i:s')]
];
$this->db->insert(self::DB_DEL_OBJ, $values);
}
}

public function setXapiObjAsDeletedForUser(int $objId, int $typeId, string $actId, int $usrId): void
{
if(!$this->dic->cron()->manager()->isJobActive('xapi_deletion_cron')) {
$xapiDelete = new ilCmiXapiStatementsDeleteRequest($objId, $typeId, $actId, $usrId, ilCmiXapiStatementsDeleteRequest::DELETE_SCOPE_ALL);
$xapiDelete->delete();
} else {
$counter = 0;
$result = $this->db->queryF(
'SELECT count(*) as counter FROM ' . self::DB_DEL_USERS . ' WHERE usr_id = %s AND obj_id = %s',
['integer', 'integer'],
[$usrId, $objId]
);
while($row = $this->db->fetchAssoc($result)) {
$counter = $row['counter'];
}

if ($counter == 0) {
$values = [
'usr_id' => ['integer', $usrId],
'obj_id' => ['integer', $objId],
'added' => ['timestamp', date('Y-m-d H:i:s')]
];
$this->db->insert(self::DB_DEL_USERS, $values);
}
}
}


public function setXapiObjAsUpdated(int $objId)
{

Expand Down Expand Up @@ -242,7 +271,16 @@ public function removeCmixUsersForObject(int $objId): void
[$objId]
);
$this->log->debug('cmix_users deleted for objId=' . (string) $objId);
}

public function removeCmixUsersForObjectAndUser(int $objId, int $usrId): void
{
$this->db->manipulateF(
'DELETE FROM cmix_users WHERE obj_id = %s AND usr_id = %s',
['integer','integer'],
[$objId,$usrId]
);
$this->log->debug('cmix_user with usrId ' . (string) $usrId . ' deleted for objId=' . (string) $objId);
}

}
Loading

0 comments on commit 3dcfeee

Please sign in to comment.