Skip to content
Snippets Groups Projects
Commit a7bd8c98 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms
Browse files

clean up forum visits and ensure entries are deleted when either a user or a...

Closes #2738

Merge request studip/studip!1856
parent 8a725a08
No related branches found
No related tags found
No related merge requests found
......@@ -157,6 +157,13 @@ class GarbageCollectorJob extends CronJob
$statement->execute();
}
// Remove outdated entries from forum_visits
$query = "DELETE FROM `forum_visits`
WHERE GREATEST(`visitdate`, `last_visitdate`) < UNIX_TIMESTAMP() - :threshold";
DBManager::get()->execute($query, [
':threshold' => ForumVisit::LAST_VISIT_MAX,
]);
// clean db cache
$cache = new StudipDbCache();
$cache->purge();
......
......@@ -278,6 +278,10 @@ class Course extends SimpleORMap implements Range, PrivacyObject, StudipItem, Fe
"UPDATE `seminare` SET `parent_course` = NULL WHERE `parent_course` = :course",
['course' => $course->id]
);
DBManager::get()->execute(
"DELETE FROM `forum_visits` WHERE `seminar_id` = ?",
[$course->id]
);
};
parent::configure($config);
......
......@@ -211,6 +211,7 @@ class User extends AuthUserMd5 implements Range, PrivacyObject
};
$config['registered_callbacks']['after_delete'][] = 'cbRemoveFeedback';
$config['registered_callbacks']['after_delete'][] = 'cbRemoveForumVisits';
$config['registered_callbacks']['before_store'][] = 'cbClearCaches';
$config['registered_callbacks']['before_store'][] = 'cbStudipLog';
......@@ -1490,6 +1491,17 @@ class User extends AuthUserMd5 implements Range, PrivacyObject
FeedbackEntry::deleteBySQL('user_id = ?', [$this->id]);
}
/**
* This callback is called after deleting a User.
* It removes forum visit entries that are associated with the User.
*/
public function cbRemoveForumVisits()
{
$query = "DELETE FROM `forum_visits`
WHERE `user_id` = ?";
DBManager::get()->execute($query, [$this->id]);
}
public function cbClearCaches()
{
if ($this->isFieldDirty('perms')) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment