/**
* 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 = [];
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();
}
}
}