Fix logging.
authorGunnar Wrobel <p@rdus.de>
Thu, 30 Dec 2010 10:48:44 +0000 (11:48 +0100)
committerGunnar Wrobel <p@rdus.de>
Tue, 4 Jan 2011 07:54:18 +0000 (08:54 +0100)
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Decorator/Log.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Decorator/Timer.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/List/Base.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/List/Decorator/Log.php
framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/Driver/Decorator/LogTest.php
framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/Driver/Decorator/TimerTest.php

index 1e6910c..896731c 100644 (file)
@@ -69,6 +69,29 @@ extends Horde_Kolab_Storage_Driver_Decorator_Base
     }
 
     /**
+     * Retrieves the specified annotation for the complete list of mailboxes.
+     *
+     * @param string $annotation The name of the annotation to retrieve.
+     *
+     * @return array An associative array combining the folder names as key with
+     *               the corresponding annotation value.
+     */
+    public function listAnnotation($annotation)
+    {
+        $this->_logger->info(
+            sprintf('Driver "%s": Listing annotation "%s".', $this->getDriverName(), $annotation)
+        );
+        $result = parent::listAnnotation($annotation);
+        $this->_logger->info(
+            sprintf(
+                'Driver "%s": List contained %s folder annotations.',
+                $this->getDriverName(),
+                count($result))
+        );
+        return $result;
+    }
+
+    /**
      * Does the given folder exist?
      *
      * @param string $folder The folder to check.
index 4362098..fed2966 100644 (file)
@@ -79,6 +79,27 @@ extends Horde_Kolab_Storage_Driver_Decorator_Base
     }
 
     /**
+     * Retrieves the specified annotation for the complete list of mailboxes.
+     *
+     * @param string $annotation The name of the annotation to retrieve.
+     *
+     * @return array An associative array combining the folder names as key with
+     *               the corresponding annotation value.
+     */
+    public function listAnnotation($annotation)
+    {
+        $this->_timer->push();
+        $result = parent::listAnnotation($annotation);
+        $this->_logger->info(
+            sprintf(
+                'REQUEST OUT IMAP: %s ms [listAnnotation]',
+                floor($this->_timer->pop() * 1000)
+            )
+        );
+        return $result;
+    }
+
+    /**
      * Does the given folder exist?
      *
      * @param string $folder The folder to check.
index 82cf680..7be624b 100644 (file)
@@ -111,9 +111,24 @@ implements Horde_Kolab_Storage_List
      */
     public function getQuery($name)
     {
+        return $this->getQueryWithParent($name, $this);
+    }
+
+    /**
+     * Return the specified query type based on the specified parent object.
+     *
+     * @param string                   $name   The query name.
+     * @param Horde_Kolab_Storage_List $parent The base for the query object.
+     *
+     * @return Horde_Kolab_Storage_Query A query handler.
+     *
+     * @throws Horde_Kolab_Storage_Exception In case the requested query is not supported.
+     */
+    public function getQueryWithParent($name, Horde_Kolab_Storage_List $parent)
+    {
         $class = 'Horde_Kolab_Storage_List_Query_' . $name;
         if (class_exists($class)) {
-            return new $class($this);
+            return new $class($parent);
         }
         throw new Horde_Kolab_Storage_Exception(sprintf('No such query "%s"!', $name));
     }
index 074d10d..7ed0e1a 100644 (file)
@@ -115,7 +115,7 @@ implements Horde_Kolab_Storage_List
      */
     public function getQuery($name)
     {
-        return $this->_list->getQuery($name);
+        return $this->_list->getQueryWithParent($name, $this);
     }
 
 }
\ No newline at end of file
index 1753035..881979a 100644 (file)
@@ -54,4 +54,24 @@ extends Horde_Kolab_Storage_TestCase
         $driver->getMailboxes();
         $this->assertLogContains('Driver "Horde_Kolab_Storage_Driver_Mock": List contained 2 folders.');
     }
+
+    public function testListAnnotationLogsEntry()
+    {
+        $driver = new Horde_Kolab_Storage_Driver_Decorator_Log(
+            $this->getNullMock(),
+            $this->getMockLogger()
+        );
+        $driver->listAnnotation('/shared/vendor/kolab/folder-type');
+        $this->assertLogCount(2);
+    }
+
+    public function testListAnnotationFolderCount()
+    {
+        $driver = new Horde_Kolab_Storage_Driver_Decorator_Log(
+            $this->getAnnotatedMock(),
+            $this->getMockLogger()
+        );
+        $driver->listAnnotation('/shared/vendor/kolab/folder-type');
+        $this->assertLogContains('Driver "Horde_Kolab_Storage_Driver_Mock": List contained 4 folder annotations.');
+    }
 }
index 7724bca..a6bf80b 100644 (file)
@@ -63,4 +63,26 @@ extends Horde_Kolab_Storage_TestCase
         $driver->getMailboxes();
         $this->assertLogRegExp('/REQUEST OUT IMAP:.*getMailboxes.*/');
     }
+
+    public function testListAnnotationLogsEntry()
+    {
+        $driver = new Horde_Kolab_Storage_Driver_Decorator_Timer(
+            $this->getNullMock(),
+            new Horde_Support_Timer(),
+            $this->getMockLogger()
+        );
+        $driver->listAnnotation('/shared/vendor/kolab/folder-type');
+        $this->assertLogCount(1);
+    }
+
+    public function testListAnnotationFolderCount()
+    {
+        $driver = new Horde_Kolab_Storage_Driver_Decorator_Timer(
+            $this->getTwoFolderMock(),
+            new Horde_Support_Timer(),
+            $this->getMockLogger()
+        );
+        $driver->listAnnotation('/shared/vendor/kolab/folder-type');
+        $this->assertLogRegExp('/REQUEST OUT IMAP:.*listAnnotation.*/');
+    }
 }