Deleted sessions no longer in the DB

Deleted sessions no longer in the DB

by Scott Karren -
Number of replies: 5

I have been building some SQL queries that allow me to view the sessions for a given date/time, location, venue, etc.  I wanted to see if I could list the number of sessions that had been deleted as well, but I found that when you delete a session from Moodle it deletes it from the DB as well.  Is this by design?  If it is, it is a departure from what I have seen in other areas of Moodle which if an item is deleted it is removed from view but remains in the DB with the deleted field marked.  Should this be the case with the Face-to-Face module?

Scott Karren

Average of ratings: -
In reply to Scott Karren

Re: Deleted sessions no longer in the DB

by François Marier -
You're right Scott. It is currently the case that if you delete a Face-to-face session, it's completely gone, along with associated session dates and signups.

Others have suggested this feature before but we never got around to doing it. Feel free to create an issue for it on the Moodle Tracker. I think that it would be good to keep a record of old sessions.

Cheers,
Francois
In reply to François Marier

Re: Deleted sessions no longer in the DB

by Scott Karren -
Done,


CONTRIB-1107

Scott Karren
In reply to Scott Karren

Re: Deleted sessions no longer in the DB

by Scott Karren -
I think this could actually be done very easily. See the comments I added to contrib-1107 and let me know what you thing.

Scott Karren
In reply to Scott Karren

Re: Deleted sessions no longer in the DB

by Scott Karren -
So, I have been working on modifying the facetoface_delete_session function to not actually delete the sessions but to update the session, and session date data and delete the submission data.

I have been able to modify the code to update the session data and delete the submission data, but I am struggling with updating the session date data. I am hoping that someone here can help me a bit in solidifying the code.

I have pasted my modified code below, if someone could take a look at it and give me some pointers I would greatly appreciate it.

function facetoface_delete_session($formdata) {

global $CFG;

$session = facetoface_get_session($formdata->s);
$facetoface = get_record('facetoface', 'id', $session->facetoface);
$sessiondate = get_records('facetoface_sessions_dates', 'sessionid', $session);

// Cancel user signups (and notify users)
$signedupusers = get_records_sql("SELECT DISTINCT userid
FROM {$CFG->prefix}facetoface_submissions
WHERE sessionid = $formdata->s AND
timecancelled = 0");
if ($signedupusers and count($signedupusers) > 0) {
foreach ($signedupusers as $user) {
if (facetoface_user_cancel($session, $user->userid)) {
facetoface_send_cancellation_notice($facetoface, $session, $user->userid);
}
else {
return false; // Cannot rollback since we notified users already
}
}
}

begin_sql();

// Remove entries from the teacher calendars
if (!delete_records_select('event', "modulename = 'facetoface' AND
eventtype = 'facetofacesession' AND
instance = $facetoface->id AND
description LIKE '%attendees.php?s=$session->id%'")) {
rollback_sql();
return false;
}

//Mark a session as 'deleted'
$updatesession = new object();
$updatesession->id = $formdata->s;
$updatesession->deleted = 1;
$updatesession->timedeleted = time();

//Mark session date as 'deleted'
$updatesessiondate = new object();
$updatesessiondate->id = $sessiondate;
$updatesessiondate->deleted = 1;
$updatesessiondate->timedeleted =time();


if (!update_record('facetoface_sessions',$updatesession)) {
rollback_sql();
return false;
}
// if (!update_record('facetoface_sessions_dates',$updatesessiondate)) {
// rollback_sql();
// return false;
// }
foreach ($updatesessiondate as $date) {
if (!update_record('facetoface_sessions_dates',$date)) {
rollback_sql();
return false;
}
}
// // Delete session details
// if (!delete_records('facetoface_sessions', 'id', $formdata->s)) {
// rollback_sql();
// return false;
// }
// if (!delete_records('facetoface_sessions_dates', 'sessionid', $formdata->s)) {
// rollback_sql();
// return false;
// }
if (!delete_records('facetoface_submissions', 'sessionid', $formdata->s)) {
rollback_sql();
return false;
}

commit_sql();
return true;
}

Scott Karren
In reply to Scott Karren

Re: Deleted sessions no longer in the DB

by Scott Karren -
Anyone want to take a stab at this? I would appreciate any suggestions.

Scott