Destructor fixes.
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 8 Oct 2009 22:15:21 +0000 (16:15 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 8 Oct 2009 22:15:21 +0000 (16:15 -0600)
Destructors have no access to the session - need to do these tasks in a
function registered via register_shutdown_function().

imp/lib/Compose.php
imp/lib/Imap.php
imp/lib/Imap/Tree.php
imp/lib/Mailbox.php
ingo/lib/Storage.php
ingo/lib/Storage/Prefs.php
ingo/lib/Storage/Sql.php

index ae9e759..9b442c3 100644 (file)
@@ -119,13 +119,14 @@ class IMP_Compose
     protected function __construct($cacheid)
     {
         $this->_cacheid = $cacheid;
+        register_shutdown_function(array($this, 'shutdown'));
     }
 
     /**
      * Store a serialized version of ourself in the current session on
      * shutdown.
      */
-    public function __destruct()
+    public function shutdown()
     {
         if ($this->_modified) {
             $this->_modified = false;
index ba13826..adda112 100644 (file)
@@ -51,12 +51,14 @@ class IMP_Imap
 
         /* Rebuild the Horde_Imap_Client object. */
         $this->_loadImapObject();
+
+        register_shutdown_function(array($this, 'shutdown'));
     }
 
     /**
      * Save the Horde_Imap_Client object on session shutdown.
      */
-    public function __destruct()
+    public function shutdown()
     {
         /* Only need to serialize object once a session. When we do
          * serialize, make sure we login in order to ensure we have done the
index 1703737..456a472 100644 (file)
@@ -243,6 +243,7 @@ class IMP_Imap_Tree
         }
 
         $this->init();
+        $this->__wakeup();
     }
 
     /**
@@ -255,9 +256,17 @@ class IMP_Imap_Tree
     }
 
     /**
+     * Tasks to do on wakeup.
+     */
+    public function __wakeup()
+    {
+        register_shutdown_function(array($this, 'shutdown'));
+    }
+
+    /**
      * Store a serialized version of ourself in the current session.
      */
-    public function __destruct()
+    public function shutdown()
     {
         /* We only need to store the object if using Horde_Cache and the tree
          * has changed. */
index 2bbcdb6..42ddcf9 100644 (file)
@@ -107,6 +107,8 @@ class IMP_Mailbox
             }
             $this->setIndex($uid);
         }
+
+        register_shutdown_function(array($this, 'shutdown'));
     }
 
     /**
@@ -115,7 +117,7 @@ class IMP_Mailbox
      * list, and to ensure messages aren't marked as missing in search
      * mailboxes (e.g. if search is dependent on unseen flag).
      */
-    public function __destruct()
+    public function shutdown()
     {
         if (!is_null($this->_arrayIndex)) {
             /* Casting $_sorted to integers saves a significant amount of
index 0ffd753..995a7e2 100644 (file)
@@ -96,9 +96,17 @@ class Ingo_Storage
     }
 
     /**
-     * Destructor.
+     * Constructor.
      */
-    public function __destruct()
+    public function __construct()
+    {
+        register_shutdown_function(array($this, 'shutdown'));
+    }
+
+    /**
+     * Shutdown function.
+     */
+    public function shutdown()
     {
         $cache = Horde_SessionObjects::singleton();
 
index be3547e..a6a6331 100644 (file)
@@ -20,6 +20,7 @@ class Ingo_Storage_Prefs extends Ingo_Storage
     public function __construct($params = array())
     {
         $this->_params = $params;
+        parent::__construct();
     }
 
     /**
index 1800dbe..07d68bf 100644 (file)
@@ -119,6 +119,8 @@ class Ingo_Storage_Sql extends Ingo_Storage
             /* Default to the same DB handle for the writer too. */
             $this->_db =& $this->_write_db;
         }
+
+        parent::__construct();
     }
 
     /**