From e854d97851bd417460b4e00394ceea64db419c7a Mon Sep 17 00:00:00 2001 From: Elmar Ludwig <elmar.ludwig@uni-osnabrueck.de> Date: Fri, 13 Oct 2023 20:05:27 +0000 Subject: [PATCH] move object_user_visits cleanup into garbage_collector, fixes #3113 Closes #3113 Merge request studip/studip!2278 --- .../5.5.1_tic_3113_remove_cronjob.php | 34 +++++++++++ lib/cronjobs/clean_object_user_visits.php | 60 ------------------- lib/cronjobs/garbage_collector.class.php | 9 +++ 3 files changed, 43 insertions(+), 60 deletions(-) create mode 100644 db/migrations/5.5.1_tic_3113_remove_cronjob.php delete mode 100644 lib/cronjobs/clean_object_user_visits.php diff --git a/db/migrations/5.5.1_tic_3113_remove_cronjob.php b/db/migrations/5.5.1_tic_3113_remove_cronjob.php new file mode 100644 index 00000000000..d883f2ee9ef --- /dev/null +++ b/db/migrations/5.5.1_tic_3113_remove_cronjob.php @@ -0,0 +1,34 @@ +<?php + +class Tic3113RemoveCronjob extends Migration +{ + public function description() + { + return 'Removes the cleanup cronjob for the table "object_user_visits"'; + } + + public function up() + { + $query = 'DELETE `cronjobs_tasks`, `cronjobs_schedules`, `cronjobs_logs` + FROM `cronjobs_tasks` + LEFT JOIN `cronjobs_schedules` USING (`task_id`) + LEFT JOIN `cronjobs_logs` USING (`schedule_id`) + WHERE `filename` = :filename'; + + DBManager::get()->execute($query, [ + ':filename' => 'lib/cronjobs/clean_object_user_visits.php' + ]); + } + + public function down() + { + $query = 'INSERT INTO `cronjobs_tasks` (`task_id`, `filename`, `class`) + VALUES (:task_id, :filename, :class)'; + + DBManager::get()->execute($query, [ + ':task_id' => '7cb4134a91bd985263fd570c7560ad72', + ':filename' => 'lib/cronjobs/clean_object_user_visits.php', + ':class' => 'CleanObjectUserVisits', + ]); + } +} diff --git a/lib/cronjobs/clean_object_user_visits.php b/lib/cronjobs/clean_object_user_visits.php deleted file mode 100644 index 80376b78cdc..00000000000 --- a/lib/cronjobs/clean_object_user_visits.php +++ /dev/null @@ -1,60 +0,0 @@ -<?php -/** - * clean_object_user_visits.php. - * - * Core cronjob that removes old entries from the table "object_user_visits". - * - * @author Jan-Hendrik Willms <tleilax+studip@gmail.com> - * @license GPL2 or any later version - * @since 3.3 - */ - -class CleanObjectUserVisits extends CronJob -{ - /** - * Return the name of this cronjob. - * - * @return String containing the name - */ - public static function getName() - { - return _('Entfernt alte Einträge aus der Tabelle "object_user_visits"'); - } - - /** - * Returns the description for this cronjob. - * - * @return String containing the description - */ - public static function getDescription() - { - return _('Um die Tabelle "object_user_visits" schmal zu halten, werden alte Einträge nach einem definierten Zeitraum entfernt.'); - } - - /** - * Returns the defined configuration parameters for this cronjob. - * - * @return Array with defined parameters - */ - public static function getParameters() - { - return []; - } - - /** - * Executes the cronjob. - * - * @param mixed $last_result Result returned from the last execution - * @param Array $parameters Defined parameters - */ - public function execute($last_result, $parameters = []) - { - if (Config::get()->NEW_INDICATOR_THRESHOLD) { - $query = "DELETE FROM `object_user_visits` - WHERE GREATEST(`visitdate`, `last_visitdate`) < UNIX_TIMESTAMP(NOW() - INTERVAL :expires DAY)"; - $statement = DBManager::get()->prepare($query); - $statement->bindValue(':expires', (int) Config::get()->NEW_INDICATOR_THRESHOLD, PDO::PARAM_INT); - $statement->execute(); - } - } -} diff --git a/lib/cronjobs/garbage_collector.class.php b/lib/cronjobs/garbage_collector.class.php index 7adb0cd38f8..1d060068705 100644 --- a/lib/cronjobs/garbage_collector.class.php +++ b/lib/cronjobs/garbage_collector.class.php @@ -148,6 +148,15 @@ class GarbageCollectorJob extends CronJob Studip\Activity\Activity::doGarbageCollect(); + // remove old entries from the table "object_user_visits". + if (Config::get()->NEW_INDICATOR_THRESHOLD) { + $query = "DELETE FROM `object_user_visits` + WHERE GREATEST(`visitdate`, `last_visitdate`) < UNIX_TIMESTAMP(NOW() - INTERVAL :expires DAY)"; + $statement = DBManager::get()->prepare($query); + $statement->bindValue(':expires', (int) Config::get()->NEW_INDICATOR_THRESHOLD, PDO::PARAM_INT); + $statement->execute(); + } + // clean db cache $cache = new StudipDbCache(); $cache->purge(); -- GitLab