Fix cleaning of tracked visits in DailyCleanUpCronjob
authorTim Düsterhus <duesterhus@woltlab.com>
Tue, 26 Apr 2022 12:44:27 +0000 (14:44 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Tue, 26 Apr 2022 12:44:27 +0000 (14:44 +0200)
This part of the cronjob never was functional, because stored visitTime was
compared to the lifetime which could only ever match near the start of the unix
epoch.

Fix this by correctly subtracting the lifetime from the current timestamp. I've
opted to use 120 days as the cleanup lifetime, as this allows one to adjust the
DEFAULT_LIFETIME gracefully.

wcfsetup/install/files/lib/system/cronjob/DailyCleanUpCronjob.class.php

index d6bf033e6ce62a2467027b032e025e8fbd77b942..ba0d4e99bc60f10cfcbf3612651f7944c7b5c000 100644 (file)
@@ -81,17 +81,18 @@ class DailyCleanUpCronjob extends AbstractCronjob
         WCF::getDB()->beginTransaction();
         $objectTypes = ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.visitTracker.objectType');
         foreach ($objectTypes as $objectType) {
-            // get lifetime
-            $lifetime = ($objectType->lifetime ?: VisitTracker::DEFAULT_LIFETIME);
+            $visitLifetime = 120 * 86400;
+            \assert($visitLifetime > VisitTracker::DEFAULT_LIFETIME);
+            $lifetime = \max($objectType->lifetime ?: 0, $visitLifetime);
 
             // delete data
             $statement1->execute([
                 $objectType->objectTypeID,
-                $lifetime,
+                TIME_NOW - $lifetime,
             ]);
             $statement2->execute([
                 $objectType->objectTypeID,
-                $lifetime,
+                TIME_NOW - $lifetime,
             ]);
         }
         WCF::getDB()->commitTransaction();