Fix garbage collection.
authorJan Schneider <jan@horde.org>
Wed, 22 Dec 2010 14:56:56 +0000 (15:56 +0100)
committerJan Schneider <jan@horde.org>
Wed, 22 Dec 2010 14:56:56 +0000 (15:56 +0100)
framework/Alarm/lib/Horde/Alarm.php
framework/Alarm/lib/Horde/Alarm/Sql.php
framework/Alarm/test/Horde/Alarm/SqlTest.php

index 6bc156e..2fec089 100644 (file)
@@ -553,12 +553,15 @@ abstract class Horde_Alarm
     /**
      * Garbage collects old alarms in the backend.
      *
+     * @param boolean $force  Force garbace collection? If false, GC happens
+     *                        with a 1% chance.
+     *
      * @throws Horde_Alarm_Exception
      */
-    public function gc()
+    public function gc($force = false)
     {
         /* A 1% chance we will run garbage collection during a call. */
-        if (rand(0, 99) == 0) {
+        if ($force || rand(0, 99) == 0) {
             $this->_gc();
         }
     }
index b151363..e5e9bd5 100644 (file)
@@ -370,7 +370,7 @@ class Horde_Alarm_Sql extends Horde_Alarm
     {
         $query = sprintf('DELETE FROM %s WHERE alarm_end IS NOT NULL AND alarm_end < ?', $this->_params['table']);
         $end = new Horde_Date(time());
-        $this->_db->delete($query, (string)$end->setTimezone('UTC'));
+        $this->_db->delete($query, array((string)$end->setTimezone('UTC')));
     }
 
     /**
index e05bca4..eb6e077 100644 (file)
@@ -59,7 +59,7 @@ class Horde_Alarm_SqlTest extends PHPUnit_Framework_TestCase
     {
         self::$alarm = new Horde_Alarm_Sql(array('db' => self::$db, 'charset' => 'UTF-8'));
         self::$alarm->initialize();
-        self::$alarm->gc();
+        self::$alarm->gc(true);
     }
 
     /**