Move the triggering functionality into a decorator.
authorGunnar Wrobel <p@rdus.de>
Wed, 24 Mar 2010 10:40:45 +0000 (11:40 +0100)
committerGunnar Wrobel <wrobel@temple.(none)>
Wed, 24 Mar 2010 10:41:26 +0000 (11:41 +0100)
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Base.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Decorator/Base.php [new file with mode: 0644]
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Decorator/Trigger.php [new file with mode: 0644]
framework/Kolab_Storage/package.xml

index b44d930..7b7ecf3 100644 (file)
@@ -6,7 +6,9 @@
  *
  * @category Kolab
  * @package  Kolab_Storage
+ * @author   Stuart Binge <omicron@mighty.co.za>
  * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @author   Thomas Jarosch <thomas.jarosch@intra2net.com>
  * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
  * @link     http://pear.horde.org/index.php?package=Kolab_Storage
  */
  * See the enclosed file COPYING for license information (LGPL). If you
  * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  *
- * @author  Stuart Binge <omicron@mighty.co.za>
- * @author  Gunnar Wrobel <wrobel@pardus.de>
- * @author  Thomas Jarosch <thomas.jarosch@intra2net.com>
- * @package Kolab_Storage
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Stuart Binge <omicron@mighty.co.za>
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @author   Thomas Jarosch <thomas.jarosch@intra2net.com>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
  */
 interface Horde_Kolab_Storage_Folder
 {
+    /**
+     * Saves the folder.
+     *
+     * @param array $attributes An array of folder attributes. You can
+     *                          set any attribute but there are a few
+     *                          special ones like 'type', 'default',
+     *                          'owner' and 'desc'.
+     *
+     * @return NULL
+     */
+    public function save($attributes = null);
+
+    /**
+     * Delete the specified message from this folder.
+     *
+     * @param  string  $id      IMAP id of the message to be deleted.
+     * @param  boolean $trigger Should the folder be triggered?
+     *
+     * @return NULL
+     */
+    public function deleteMessage($id, $trigger = true);
+
+    /**
+     * Move the specified message to the specified folder.
+     *
+     * @param string $id     IMAP id of the message to be moved.
+     * @param string $folder Name of the receiving folder.
+     *
+     * @return boolean True if successful.
+     */
+    public function moveMessage($id, $folder);
+
+    /**
+     * Move the specified message to the specified share.
+     *
+     * @param string $id    IMAP id of the message to be moved.
+     * @param string $share Name of the receiving share.
+     *
+     * @return NULL
+     */
+    public function moveMessageToShare($id, $share);
+
+    /**
+     * Save an object in this folder.
+     *
+     * @param array  $object       The array that holds the data of the object.
+     * @param int    $data_version The format handler version.
+     * @param string $object_type  The type of the kolab object.
+     * @param string $id           The IMAP id of the old object if it
+     *                             existed before
+     * @param array  $old_object   The array that holds the current data of the
+     *                             object.
+     *
+     * @return boolean True on success.
+     */
+    public function saveObject(&$object, $data_version, $object_type, $id = null,
+                               &$old_object = null);
+
+    /**
+     * Return the IMAP ACL of this folder.
+     *
+     * @return array An array with IMAP ACL.
+     */
+    public function getACL();
+
+    /**
+     * Set the ACL of this folder.
+     *
+     * @param $user The user for whom the ACL should be set.
+     * @param $acl  The new ACL value.
+     *
+     * @return NULL
+     */
+    public function setACL($user, $acl);
+
+    /**
+     * Delete the ACL for a user on this folder.
+     *
+     * @param $user The user for whom the ACL should be deleted.
+     *
+     * @return NULL
+     */
+    public function deleteACL($user);
+
 }
index a8b2dc5..4bab4ac 100644 (file)
@@ -276,9 +276,9 @@ implements Horde_Kolab_Storage_Folder
      *                          special ones like 'type', 'default',
      *                          'owner' and 'desc'.
      *
-     * @return boolean|PEAR_Error True on success.
+     * @return NULL
      */
-    function save($attributes = null)
+    public function save($attributes = null)
     {
         if (!isset($this->name)) {
             /* A new folder needs to be created */
@@ -348,21 +348,6 @@ implements Horde_Kolab_Storage_Folder
                 $result = $this->_connection->rename($this->name, $this->new_name);
                 $this->_storage->removeFromCache($this);
 
-                /**
-                 * Trigger the old folder on an empty IMAP folder.
-                 */
-                try {
-                    $this->_connection->create($this->name);
-                    $this->_connection->setAnnotation(self::ANNOT_FOLDER_TYPE,
-                                                      $this->_type,
-                                                      $this->name);
-                    $this->trigger($this->name);
-                    $this->_connection->delete($this->name);
-                } catch (Exception $e) {
-                    Horde::logMessage(sprintf('Failed handling the dummy folder: %s!',
-                                              $e->getMessage()), 'ERR');
-                }
-
                 $this->name     = $this->new_name;
                 $this->new_name = null;
                 $this->_title   = null;
@@ -434,13 +419,6 @@ implements Horde_Kolab_Storage_Folder
 
         $this->_storage->addToCache($this);
 
-        try {
-            $this->trigger();
-        } catch (Horde_Kolab_Storage_Exception $e) {
-            Horde::logMessage(sprintf('Failed triggering folder %s! Error was: %s',
-                                      $this->name, $e->getMessage()), 'ERR');
-        }
-
         return true;
     }
 
@@ -497,6 +475,8 @@ implements Horde_Kolab_Storage_Folder
      * @param string $name Name of the folder that should be triggered.
      *
      * @return string|PEAR_Error  The subpath of this folder.
+     *
+     * @todo Is this is only needed by triggering? Can it be removed/moved?
      */
     public function getSubpath($name = null)
     {
@@ -693,24 +673,13 @@ implements Horde_Kolab_Storage_Folder
      * @param  string  $id      IMAP id of the message to be deleted.
      * @param  boolean $trigger Should the folder be triggered?
      *
-     * @return boolean|PEAR_Error True if successful.
+     * @return NULL
      */
-    function deleteMessage($id, $trigger = true)
+    public function deleteMessage($id, $trigger = true)
     {
         // Select folder
         $this->_connection->deleteMessages($this->name, $id);
         $this->_connection->expunge($this->name);
-
-        if ($trigger) {
-            try {
-                $result = $this->trigger();
-            } catch (Horde_Kolab_Storage_Exception $e) {
-                Horde::logMessage(sprintf('Failed triggering folder %s! Error was: %s',
-                                          $this->name, $result->getMessage()), 'ERR');
-            }
-        }
-
-        return true;
     }
 
     /**
@@ -719,33 +688,13 @@ implements Horde_Kolab_Storage_Folder
      * @param string $id     IMAP id of the message to be moved.
      * @param string $folder Name of the receiving folder.
      *
-     * @return boolean|PEAR_Error True if successful.
+     * @return boolean True if successful.
      */
-    function moveMessage($id, $folder)
+    public function moveMessage($id, $folder)
     {
-        // Select folder
-        $result = $this->_connection->select($this->name);
-        if (is_a($result, 'PEAR_Error')) {
-            return $result;
-        }
-
-        $result = $this->_connection->moveMessage($this->name, $id, $folder);
-        if (is_a($result, 'PEAR_Error')) {
-            return $result;
-        }
-
-        $result = $this->_connection->expunge($this->name);
-        if (is_a($result, 'PEAR_Error')) {
-            return $result;
-        }
-
-        $result = $this->trigger();
-        if (is_a($result, 'PEAR_Error')) {
-            Horde::logMessage(sprintf('Failed triggering folder %s! Error was: %s',
-                                      $this->name, $result->getMessage()), 'ERR');
-        }
-
-        return true;
+        $this->_connection->select($this->name);
+        $this->_connection->moveMessage($this->name, $id, $folder);
+        $this->_connection->expunge($this->name);
     }
 
     /**
@@ -754,24 +703,14 @@ implements Horde_Kolab_Storage_Folder
      * @param string $id    IMAP id of the message to be moved.
      * @param string $share Name of the receiving share.
      *
-     * @return boolean|PEAR_Error True if successful.
+     * @return NULL
      */
-    function moveMessageToShare($id, $share)
+    public function moveMessageToShare($id, $share)
     {
         $folder = $this->_storage->getByShare($share, $this->getType());
-        if (is_a($folder, 'PEAR_Error')) {
-            return $folder;
-        }
         $folder->tainted = true;
 
         $success = $this->moveMessage($id, $folder->name);
-
-        $result = $this->trigger();
-        if (is_a($result, 'PEAR_Error')) {
-            Horde::logMessage(sprintf('Failed triggering folder %s! Error was: %s',
-                                      $this->name, $result->getMessage()), 'ERR');
-        }
-        return $success;
     }
 
     /**
@@ -810,7 +749,7 @@ implements Horde_Kolab_Storage_Folder
      *
      * @return boolean True on success.
      */
-    function saveObject(&$object, $data_version, $object_type, $id = null,
+    public function saveObject(&$object, $data_version, $object_type, $id = null,
                         &$old_object = null)
     {
         // Select folder
@@ -980,15 +919,6 @@ implements Horde_Kolab_Storage_Folder
         if ($id != null) {
             $this->_connection->expunge($this->name);
         }
-
-        try {
-            $this->trigger();
-        } catch (Horde_Kolab_Storage_Exception $e) {
-            Horde::logMessage(sprintf('Failed triggering folder %s! Error was: %s',
-                                      $this->name, $result->getMessage()), 'ERR');
-        }
-
-        return true;
     }
 
     /**
@@ -1101,84 +1031,6 @@ implements Horde_Kolab_Storage_Folder
     }
 
     /**
-     * Triggers any required updates after changes within the
-     * folder. This is currently only required for handling free/busy
-     * information with Kolab.
-     *
-     * @param string $name Name of the folder that should be triggered.
-     *
-     * @return boolean|PEAR_Error True if successfull.
-     */
-    function trigger($name = null)
-    {
-        $type =  $this->getType();
-        if (is_a($type, 'PEAR_Error')) {
-            return $type;
-        }
-
-        $owner = $this->getOwner();
-        if (is_a($owner, 'PEAR_Error')) {
-            return $owner;
-        }
-
-        $subpath = $this->getSubpath($name);
-        if (is_a($subpath, 'PEAR_Error')) {
-            return $subpath;
-        }
-
-        switch($type) {
-        case 'event':
-            $session = &Horde_Kolab_Session_Singleton::singleton();
-            $url = sprintf('%s/trigger/%s/%s.pfb',
-                           $session->freebusy_server, $owner, $subpath);
-            break;
-        default:
-            return true;
-        }
-
-        $result = $this->triggerUrl($url);
-        if (is_a($result, 'PEAR_Error')) {
-            return PEAR::raiseError(sprintf(_("Failed triggering folder %s. Error was: %s"),
-                                            $this->name, $result->getMessage()));
-        }
-        return $result;
-    }
-
-    /**
-     * Triggers a URL.
-     *
-     * @param string $url The URL to be triggered.
-     *
-     * @return boolean|PEAR_Error True if successfull.
-     */
-    function triggerUrl($url)
-    {
-        global $conf;
-
-        if (!empty($conf['kolab']['no_triggering'])) {
-            return true;
-        }
-
-        $options['method'] = 'GET';
-        $options['timeout'] = 5;
-        $options['allowRedirects'] = true;
-
-        if (isset($conf['http']['proxy']) && !empty($conf['http']['proxy']['proxy_host'])) {
-            $options = array_merge($options, $conf['http']['proxy']);
-        }
-
-        require_once 'HTTP/Request.php';
-        $http = new HTTP_Request($url, $options);
-        $http->setBasicAuth(Horde_Auth::getAuth(), Horde_Auth::getCredential('password'));
-        @$http->sendRequest();
-        if ($http->getResponseCode() != 200) {
-            return PEAR::raiseError(sprintf(_("Unable to trigger URL %s. Response: %s"),
-                                            $url, $http->getResponseCode()));
-        }
-        return true;
-    }
-
-    /**
      * Checks to see if a user has a given permission.
      *
      * @param string $userid       The userid of the user.
@@ -1254,24 +1106,24 @@ implements Horde_Kolab_Storage_Folder
     }
 
     /**
-     * Return the IMAP ACL of this folder.
+     * Return the ACL of this folder.
      *
-     * @return array|PEAR_Error  An array with IMAP ACL.
+     * @return array An array with ACL.
      */
-    function getACL()
+    public function getACL()
     {
         return $this->_connection->getACL($this->name);
     }
 
     /**
-     * Set the IMAP ACL of this folder.
+     * Set the ACL of this folder.
      *
      * @param $user The user for whom the ACL should be set.
      * @param $acl  The new ACL value.
      *
-     * @return boolean|PEAR_Error  True on success.
+     * @return NULL
      */
-    function setACL($user, $acl)
+    public function setACL($user, $acl)
     {
         $this->_connection->setACL($this->name, $user, $acl);
 
@@ -1279,24 +1131,16 @@ implements Horde_Kolab_Storage_Folder
             /** Refresh the cache after changing the permissions */
             $this->_perms->getPerm();
         }
-
-        $result = $this->trigger();
-        if (is_a($result, 'PEAR_Error')) {
-            Horde::logMessage(sprintf('Failed triggering folder %s! Error was: %s',
-                                      $this->name, $result->getMessage()), 'ERR');
-        }
-
-        return $result;
     }
 
     /**
-     * Delete the IMAP ACL for a user on this folder.
+     * Delete the ACL for a user on this folder.
      *
      * @param $user The user for whom the ACL should be deleted.
      *
-     * @return boolean|PEAR_Error  True on success.
+     * @return NULL
      */
-    function deleteACL($user)
+    public function deleteACL($user)
     {
         global $conf;
 
@@ -1305,14 +1149,6 @@ implements Horde_Kolab_Storage_Folder
         }
 
         $this->_connection->deleteACL($this->name, $user);
-
-        $result = $this->trigger();
-        if (is_a($result, 'PEAR_Error')) {
-            Horde::logMessage(sprintf('Failed triggering folder %s! Error was: %s',
-                                      $this->name, $result->getMessage()), 'ERR');
-        }
-
-        return $iresult;
     }
 
 
diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Decorator/Base.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Decorator/Base.php
new file mode 100644 (file)
index 0000000..11640f4
--- /dev/null
@@ -0,0 +1,154 @@
+<?php
+/**
+ * The basic decorator definition for Kolab folders.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * The basic decorator definition for Kolab folders.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @author  Gunnar Wrobel <wrobel@pardus.de>
+ * @package Kolab_Storage
+ */
+class Horde_Kolab_Storage_Folder_Decorator_Base
+implements Horde_Kolab_Storage_Folder
+{
+
+    /**
+     * The decorated folder.
+     *
+     * @var Horde_Kolab_Storage_Folder
+     */
+    protected $_folder;
+
+    /**
+     * Constructor
+     *
+     * @param Horde_Kolab_Storage_Folder $folder The folder to be decorated.
+     */
+    public function __construct(Horde_Kolab_Storage_Folder $folder)
+    {
+        $this->_folder = $folder;
+    }
+
+    /**
+     * Saves the folder.
+     *
+     * @param array $attributes An array of folder attributes. You can
+     *                          set any attribute but there are a few
+     *                          special ones like 'type', 'default',
+     *                          'owner' and 'desc'.
+     *
+     * @return NULL
+     */
+    public function save($attributes = null)
+    {
+        $this->_folder->save($attributes);
+    }
+
+    /**
+     * Delete the specified message from this folder.
+     *
+     * @param  string  $id      IMAP id of the message to be deleted.
+     * @param  boolean $trigger Should the folder be triggered?
+     *
+     * @return NULL
+     */
+    public function deleteMessage($id, $trigger = true)
+    {
+        $this->_folder->deleteMessage($id, $trigger);
+    }
+
+    /**
+     * Move the specified message to the specified folder.
+     *
+     * @param string $id     IMAP id of the message to be moved.
+     * @param string $folder Name of the receiving folder.
+     *
+     * @return boolean True if successful.
+     */
+    public function moveMessage($id, $folder)
+    {
+        $this->_folder->moveMessage($id, $folder);
+    }
+
+    /**
+     * Move the specified message to the specified share.
+     *
+     * @param string $id    IMAP id of the message to be moved.
+     * @param string $share Name of the receiving share.
+     *
+     * @return NULL
+     */
+    public function moveMessageToShare($id, $share)
+    {
+        $this->_folder->moveMessageToShare($id, $share);
+    }
+
+    /**
+     * Save an object in this folder.
+     *
+     * @param array  $object       The array that holds the data of the object.
+     * @param int    $data_version The format handler version.
+     * @param string $object_type  The type of the kolab object.
+     * @param string $id           The IMAP id of the old object if it
+     *                             existed before
+     * @param array  $old_object   The array that holds the current data of the
+     *                             object.
+     *
+     * @return boolean True on success.
+     */
+    public function saveObject(&$object, $data_version, $object_type, $id = null,
+                               &$old_object = null)
+    {
+        $this->_folder->saveObject($object, $data_version, $object_type, $id, $old_object = null);
+    }
+
+    /**
+     * Return the IMAP ACL of this folder.
+     *
+     * @return array An array with IMAP ACL.
+     */
+    public function getACL()
+    {
+        return $this->_folder->getACL();
+    }
+
+    /**
+     * Set the ACL of this folder.
+     *
+     * @param $user The user for whom the ACL should be set.
+     * @param $acl  The new ACL value.
+     *
+     * @return NULL
+     */
+    public function setACL($user, $acl)
+    {
+        $this->_folder->setACL($user, $acl);
+    }
+
+    /**
+     * Delete the ACL for a user on this folder.
+     *
+     * @param $user The user for whom the ACL should be deleted.
+     *
+     * @return NULL
+     */
+    public function deleteACL($user)
+    {
+        $this->_folder->deleteACL($user);
+    }
+
+}
diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Decorator/Trigger.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Decorator/Trigger.php
new file mode 100644 (file)
index 0000000..fa345fb
--- /dev/null
@@ -0,0 +1,267 @@
+<?php
+/**
+ * This decorator triggers a URL following certain actions on the folder.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * This decorator triggers a URL following certain actions on the folder.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @author  Gunnar Wrobel <wrobel@pardus.de>
+ * @package Kolab_Storage
+ */
+class Horde_Kolab_Storage_Folder_Decorator_Trigger
+extends Horde_Kolab_Storage_Folder_Decorator_Base
+{
+    /**
+     * Saves the folder.
+     *
+     * @param array $attributes An array of folder attributes. You can
+     *                          set any attribute but there are a few
+     *                          special ones like 'type', 'default',
+     *                          'owner' and 'desc'.
+     *
+     * @return NULL
+     */
+    public function save($attributes = null)
+    {
+        /**
+         * Trigger the old folder on an empty IMAP folder after renaming a folder!
+         */
+        try {
+            $this->_connection->create($this->name);
+            $this->_connection->setAnnotation(self::ANNOT_FOLDER_TYPE,
+                                              $this->_type,
+                                              $this->name);
+            $this->trigger($this->name);
+            $this->_connection->delete($this->name);
+        } catch (Exception $e) {
+            Horde::logMessage(sprintf('Failed handling the dummy folder: %s!',
+                                      $e->getMessage()), 'ERR');
+        }
+
+
+        /** Finally trigger the folder after saving.*/
+        try {
+            $this->trigger();
+        } catch (Horde_Kolab_Storage_Exception $e) {
+            Horde::logMessage(sprintf('Failed triggering folder %s! Error was: %s',
+                                      $this->name, $e->getMessage()), 'ERR');
+        }
+
+
+    }
+
+    /**
+     * Delete the specified message from this folder.
+     *
+     * @param  string  $id      IMAP id of the message to be deleted.
+     * @param  boolean $trigger Should the folder be triggered?
+     *
+     * @return NULL
+     */
+    public function deleteMessage($id, $trigger = true)
+    {
+        $this->_folder->deleteMessage($id, $trigger);
+
+        if ($trigger) {
+            try {
+                $result = $this->trigger();
+            } catch (Horde_Kolab_Storage_Exception $e) {
+                Horde::logMessage(sprintf('Failed triggering folder %s! Error was: %s',
+                                          $this->name, $result->getMessage()), 'ERR');
+            }
+        }
+    }
+
+    /**
+     * Move the specified message to the specified folder.
+     *
+     * @param string $id     IMAP id of the message to be moved.
+     * @param string $folder Name of the receiving folder.
+     *
+     * @return boolean True if successful.
+     */
+    public function moveMessage($id, $folder)
+    {
+        $this->_folder->moveMessage($id, $folder);
+
+        //@todo: shouldn't we trigger both folders here?
+
+        $result = $this->trigger();
+        if (is_a($result, 'PEAR_Error')) {
+            Horde::logMessage(sprintf('Failed triggering folder %s! Error was: %s',
+                                      $this->name, $result->getMessage()), 'ERR');
+        }
+
+        return true;
+    }
+
+    /**
+     * Move the specified message to the specified share.
+     *
+     * @param string $id    IMAP id of the message to be moved.
+     * @param string $share Name of the receiving share.
+     *
+     * @return NULL
+     */
+    public function moveMessageToShare($id, $share)
+    {
+        $this->_folder->moveMessageToShare($id, $share);
+
+        //@todo: shouldn't we trigger both folders here?
+        $result = $this->trigger();
+        if (is_a($result, 'PEAR_Error')) {
+            Horde::logMessage(sprintf('Failed triggering folder %s! Error was: %s',
+                                      $this->name, $result->getMessage()), 'ERR');
+        }
+        return $success;
+    }
+
+    /**
+     * Save an object in this folder.
+     *
+     * @param array  $object       The array that holds the data of the object.
+     * @param int    $data_version The format handler version.
+     * @param string $object_type  The type of the kolab object.
+     * @param string $id           The IMAP id of the old object if it
+     *                             existed before
+     * @param array  $old_object   The array that holds the current data of the
+     *                             object.
+     *
+     * @return boolean True on success.
+     */
+    public function saveObject(&$object, $data_version, $object_type, $id = null,
+                               &$old_object = null)
+    {
+        $this->_folder->saveObject($object, $data_version, $object_type, $id, $old_object);
+        try {
+            $this->trigger();
+        } catch (Horde_Kolab_Storage_Exception $e) {
+            Horde::logMessage(sprintf('Failed triggering folder %s! Error was: %s',
+                                      $this->name, $result->getMessage()), 'ERR');
+        }
+
+        return true;
+    }
+
+    /**
+     * Set the ACL of this folder.
+     *
+     * @param $user The user for whom the ACL should be set.
+     * @param $acl  The new ACL value.
+     *
+     * @return NULL
+     */
+    public function setACL($user, $acl)
+    {
+        $this->_folder->setACL($user, $acl);
+
+        $this->trigger();
+    }
+
+    /**
+     * Delete the ACL for a user on this folder.
+     *
+     * @param $user The user for whom the ACL should be deleted.
+     *
+     * @return NULL
+     */
+    public function deleteACL($user)
+    {
+        $this->_folder->deleteACL($user);
+
+        $this->trigger();
+    }
+
+    /**
+     * Triggers any required updates after changes within the
+     * folder. This is currently only required for handling free/busy
+     * information with Kolab.
+     *
+     * @param string $name Name of the folder that should be triggered.
+     *
+     * @return boolean|PEAR_Error True if successfull.
+     */
+    private function trigger($name = null)
+    {
+        $type =  $this->getType();
+        if (is_a($type, 'PEAR_Error')) {
+            return $type;
+        }
+
+        $owner = $this->getOwner();
+        if (is_a($owner, 'PEAR_Error')) {
+            return $owner;
+        }
+
+        $subpath = $this->getSubpath($name);
+        if (is_a($subpath, 'PEAR_Error')) {
+            return $subpath;
+        }
+
+        switch($type) {
+        case 'event':
+            $session = &Horde_Kolab_Session_Singleton::singleton();
+            $url = sprintf('%s/trigger/%s/%s.pfb',
+                           $session->freebusy_server, $owner, $subpath);
+            break;
+        default:
+            return true;
+        }
+
+        $result = $this->triggerUrl($url);
+        if (is_a($result, 'PEAR_Error')) {
+            return PEAR::raiseError(sprintf(_("Failed triggering folder %s. Error was: %s"),
+                                            $this->name, $result->getMessage()));
+        }
+        return $result;
+    }
+
+    /**
+     * Triggers a URL.
+     *
+     * @param string $url The URL to be triggered.
+     *
+     * @return boolean|PEAR_Error True if successfull.
+     */
+    private function triggerUrl($url)
+    {
+        global $conf;
+
+        if (!empty($conf['kolab']['no_triggering'])) {
+            return true;
+        }
+
+        $options['method'] = 'GET';
+        $options['timeout'] = 5;
+        $options['allowRedirects'] = true;
+
+        if (isset($conf['http']['proxy']) && !empty($conf['http']['proxy']['proxy_host'])) {
+            $options = array_merge($options, $conf['http']['proxy']);
+        }
+
+        require_once 'HTTP/Request.php';
+        $http = new HTTP_Request($url, $options);
+        $http->setBasicAuth(Horde_Auth::getAuth(), Horde_Auth::getCredential('password'));
+        @$http->sendRequest();
+        if ($http->getResponseCode() != 200) {
+            return PEAR::raiseError(sprintf(_("Unable to trigger URL %s. Response: %s"),
+                                            $url, $http->getResponseCode()));
+        }
+        return true;
+    }
+
+}
index d0df997..86297d7 100644 (file)
        <file name="Folder.php" role="php" />
        <dir name="Folder">
         <file name="Base.php" role="php" />
+        <dir name="Decorator">
+         <file name="Base.php" role="php" />
+         <file name="Trigger.php" role="php" />
+        </dir> <!-- /lib/Horde/Kolab/Storage/Folder/Decorator -->
        </dir> <!-- /lib/Horde/Kolab/Storage/Folder -->
        <file name="Namespace.php" role="php" />
        <dir name="Namespace">
    <install as="Horde/Kolab/Storage/Exception.php" name="lib/Horde/Kolab/Storage/Exception.php" />
    <install as="Horde/Kolab/Storage/Folder.php" name="lib/Horde/Kolab/Storage/Folder.php" />
    <install as="Horde/Kolab/Storage/Folder/Base.php" name="lib/Horde/Kolab/Storage/Folder/Base.php" />
+   <install as="Horde/Kolab/Storage/Folder/Decorator/Base.php" name="lib/Horde/Kolab/Storage/Folder/Decorator/Base.php" />
+   <install as="Horde/Kolab/Storage/Folder/Decorator/Trigger.php" name="lib/Horde/Kolab/Storage/Folder/Decorator/Trigger.php" />
    <install as="Horde/Kolab/Storage/Namespace.php" name="lib/Horde/Kolab/Storage/Namespace.php" />
    <install as="Horde/Kolab/Storage/Namespace/Config.php" name="lib/Horde/Kolab/Storage/Namespace/Config.php" />
    <install as="Horde/Kolab/Storage/Namespace/Element.php" name="lib/Horde/Kolab/Storage/Namespace/Element.php" />