diff --git a/lib/cronjobs/garbage_collector.class.php b/lib/cronjobs/garbage_collector.class.php index 7adb0cd38f8bfaf2ee564a2c06005924bbc5b7d8..eff3d6db839e9ee5fc627993e78d501287e9648c 100644 --- a/lib/cronjobs/garbage_collector.class.php +++ b/lib/cronjobs/garbage_collector.class.php @@ -148,6 +148,13 @@ class GarbageCollectorJob extends CronJob 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 $cache = new StudipDbCache(); $cache->purge(); diff --git a/lib/models/Course.class.php b/lib/models/Course.class.php index 4c471ea64e47dc212d2794872417d8898a4f4409..bbfa9835ccd18623e3f019922acafe90ac5aed47 100644 --- a/lib/models/Course.class.php +++ b/lib/models/Course.class.php @@ -271,6 +271,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); diff --git a/lib/models/User.class.php b/lib/models/User.class.php index 99a06ef09d541fe368a440366fc3cef5fa09efec..aa6f5feca679da570b9b9ff9232245309b84801f 100644 --- a/lib/models/User.class.php +++ b/lib/models/User.class.php @@ -206,6 +206,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'; @@ -1485,6 +1486,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')) {