Skip to content

Commit bdc6f31

Browse files
committed
Fix #60: Only do purging every once in a while
1 parent c5b9fb8 commit bdc6f31

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

bfstop.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,19 @@ public function onAfterInitialise()
320320
{
321321
return;
322322
}
323-
$this->mydb->purgeOldEntries((int)$this->params->get('deleteOld', 0));
323+
$purgeAge = (int)$this->params->get('deleteOld', 0);
324+
if ($purgeAge > 0)
325+
{
326+
$purgeInterval = 86400; // = 24*60*60 => one day
327+
$lastPurge = $this->params->get('lastPurge', 0);
328+
$now = time();
329+
if ($now > ($lastPurge + $purgeInterval))
330+
{
331+
$this->mydb->purgeOldEntries($purgeAge);
332+
$this->params->set('lastPurge', $now);
333+
$this->mydb->saveParams($this->params);
334+
}
335+
}
324336
$ipaddress = $this->getIPAddr();
325337
if ($this->mydb->isIPWhiteListed($ipaddress))
326338
{

helpers/db.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,15 +278,12 @@ public function successfulLogin($info)
278278
$this->setFailedLoginHandled($info, true);
279279
}
280280

281-
public function purgeOldEntries($olderThanWeeks)
281+
public function purgeOldEntries($purgeAgeWeeks)
282282
{
283-
if ($olderThanWeeks == 0)
284-
{
285-
return;
286-
}
283+
$this->logger->log("Purging entries older than $purgeAgeWeeks weeks", JLog::INFO);
287284
$deleteDate = 'DATE_SUB('.
288285
' NOW(), INTERVAL '.
289-
$this->db->quote($olderThanWeeks).
286+
$this->db->quote($purgeAgeWeeks).
290287
' WEEK)';
291288
$sql = 'DELETE FROM #__bfstop_failedlogin WHERE logtime < '.$deleteDate;
292289
$this->db->setQuery($sql);
@@ -310,4 +307,14 @@ public function purgeOldEntries($olderThanWeeks)
310307
$this->db->query();
311308
$this->myCheckDBError();
312309
}
310+
311+
public function saveParams($params)
312+
{
313+
$query = $this->db->getQuery(true);
314+
$query->update('#__extensions AS a');
315+
$query->set('a.params = '. $this->db->quote((string)$params) );
316+
$query->where('a.element = "bfstop"');
317+
$this->db->setQuery($query);
318+
$this->db->query();
319+
}
313320
}

helpers/notify.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function __construct($logger, $db, $emailAddress, $userID, $userGroup, $groupNot
2525
}
2626
if (count($this->notifyAddresses) == 0)
2727
{
28-
$this->logger->log('No notification address specified!', JLog::INFO);
28+
$this->logger->log('No notification address specified!', JLog::DEBUG);
2929
}
3030
}
3131

0 commit comments

Comments
 (0)