Missing time check for ip address pruning
authorAlexander Ebert <ebert@woltlab.com>
Thu, 13 Dec 2018 13:59:16 +0000 (14:59 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 13 Dec 2018 13:59:16 +0000 (14:59 +0100)
See #2656

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

index 48f7c0da05388a252a74183b1b32e1f5512007a6..addbcd8f58c983d4e2306f9b2bd75460aa8f165f 100644 (file)
@@ -6,14 +6,20 @@ use wcf\system\WCF;
 /**
  * Prunes old ip addresses.
  * 
- * @author     Alexander Ebert
- * @copyright  2001-2018 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package    WoltLabSuite\Core\System\Cronjob
+ * @author      Alexander Ebert
+ * @copyright   2001-2018 WoltLab GmbH
+ * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package     WoltLabSuite\Core\System\Cronjob
+ * @since       3.2
  */
 class PruneIpAddressesCronjob extends AbstractCronjob {
        /**
-        * list of columns grouped by the corresponding table
+        * list of columns
+        * [
+        *   <tableName> => [
+        *      <ipAddressColumn> => <timestampColumn>
+        *   ]
+        * ]
         * @var string[][]
         */
        public $columns = [];
@@ -24,22 +30,21 @@ class PruneIpAddressesCronjob extends AbstractCronjob {
        public function execute(Cronjob $cronjob) {
                if (!PRUNE_IP_ADDRESS) return;
                
-               $this->columns['wcf'.WCF_N.'_user'][] = 'registrationIpAddress';
+               $this->columns['wcf'.WCF_N.'_user']['registrationIpAddress'] = 'registrationDate';
                
                parent::execute($cronjob);
                
-               foreach ($this->columns as $tableName => $columns) {
-                       $columnUpdate = '';
-                       foreach ($columns as $column) {
-                               if (!empty($columnUpdate)) $columnUpdate .= ',';
-                               $columnUpdate .= "{$column} = ''";
+               foreach ($this->columns as $tableName => $columnData) {
+                       foreach ($columnData as $ipAddressColumn => $timestampColumn) {
+                               $sql = "UPDATE  {$tableName}
+                                       SET     {$ipAddressColumn} = ?
+                                       WHERE   {$timestampColumn} <= ?";
+                               $statement = WCF::getDB()->prepareStatement($sql);
+                               $statement->execute([
+                                       '',
+                                       TIME_NOW - 86400 * PRUNE_IP_ADDRESS, // 86400 = 1 day
+                               ]);
                        }
-                       
-                       $sql = "UPDATE  {$tableName}
-                               SET     {$columnUpdate}";
-                       WCF::getDB()
-                               ->prepareStatement($sql)
-                               ->execute();
                }
        }
 }