Skip to content
Snippets Groups Projects
Commit 52485663 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms Committed by 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 4aa0c654
No related branches found
No related tags found
No related merge requests found
...@@ -148,6 +148,13 @@ class GarbageCollectorJob extends CronJob ...@@ -148,6 +148,13 @@ class GarbageCollectorJob extends CronJob
Studip\Activity\Activity::doGarbageCollect(); Studip\Activity\Activity::doGarbageCollect();
// 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 // clean db cache
$cache = new StudipDbCache(); $cache = new StudipDbCache();
$cache->purge(); $cache->purge();
......
...@@ -271,6 +271,10 @@ class Course extends SimpleORMap implements Range, PrivacyObject, StudipItem, Fe ...@@ -271,6 +271,10 @@ class Course extends SimpleORMap implements Range, PrivacyObject, StudipItem, Fe
"UPDATE `seminare` SET `parent_course` = NULL WHERE `parent_course` = :course", "UPDATE `seminare` SET `parent_course` = NULL WHERE `parent_course` = :course",
['course' => $course->id] ['course' => $course->id]
); );
DBManager::get()->execute(
"DELETE FROM `forum_visits` WHERE `seminar_id` = ?",
[$course->id]
);
}; };
parent::configure($config); parent::configure($config);
......
...@@ -206,6 +206,7 @@ class User extends AuthUserMd5 implements Range, PrivacyObject ...@@ -206,6 +206,7 @@ class User extends AuthUserMd5 implements Range, PrivacyObject
}; };
$config['registered_callbacks']['after_delete'][] = 'cbRemoveFeedback'; $config['registered_callbacks']['after_delete'][] = 'cbRemoveFeedback';
$config['registered_callbacks']['after_delete'][] = 'cbRemoveForumVisits';
$config['registered_callbacks']['before_store'][] = 'cbClearCaches'; $config['registered_callbacks']['before_store'][] = 'cbClearCaches';
$config['registered_callbacks']['before_store'][] = 'cbStudipLog'; $config['registered_callbacks']['before_store'][] = 'cbStudipLog';
...@@ -1485,6 +1486,17 @@ class User extends AuthUserMd5 implements Range, PrivacyObject ...@@ -1485,6 +1486,17 @@ class User extends AuthUserMd5 implements Range, PrivacyObject
FeedbackEntry::deleteBySQL('user_id = ?', [$this->id]); 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() public function cbClearCaches()
{ {
if ($this->isFieldDirty('perms')) { 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