Fix IMP_Mailbox_List factory
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 5 Oct 2010 17:16:45 +0000 (11:16 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 5 Oct 2010 22:21:12 +0000 (16:21 -0600)
12 files changed:
imp/lib/Ajax/Application.php
imp/lib/Application.php
imp/lib/Injector/Binder/MailboxList.php [deleted file]
imp/lib/Injector/Factory/MailboxList.php
imp/lib/Mailbox/List/Track.php
imp/lib/Views/ListMessages.php
imp/mailbox-mimp.php
imp/mailbox.php
imp/message-mimp.php
imp/message.php
imp/rss.php
imp/thread.php

index c07533c..79238f5 100644 (file)
@@ -749,7 +749,7 @@ class IMP_Ajax_Application extends Horde_Core_Ajax_Application
                 $result->ViewPort = $this->_viewPortData(true);
             } else {
                 $result->ViewPort = new stdClass;
-                $result->ViewPort->updatecacheid = $GLOBALS['injector']->getInstance('IMP_Mailbox_List')->getList($this->_vars->view)->getCacheID($this->_vars->view);
+                $result->ViewPort->updatecacheid = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_MailboxList')->create($this->_vars->view)->getCacheID($this->_vars->view);
                 $result->ViewPort->view = $this->_vars->view;
             }
             return $result;
@@ -943,7 +943,7 @@ class IMP_Ajax_Application extends Horde_Core_Ajax_Application
                 $result = $this->_checkUidvalidity($result);
             } elseif (!$change) {
                 /* Only update cacheid info if it changed. */
-                $cacheid = $GLOBALS['injector']->getInstance('IMP_Mailbox_List')->getList($this->_vars->view)->getCacheID($this->_vars->view);
+                $cacheid = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_MailboxList')->create($this->_vars->view)->getCacheID($this->_vars->view);
                 if ($cacheid != $this->_vars->cacheid) {
                     $result->ViewPort = new stdClass;
                     $result->ViewPort->updatecacheid = $cacheid;
@@ -1929,7 +1929,7 @@ class IMP_Ajax_Application extends Horde_Core_Ajax_Application
             $result->ViewPort = $this->_viewPortData(true);
         } else {
             $result->ViewPort = new stdClass;
-            $result->ViewPort->updatecacheid = $GLOBALS['injector']->getInstance('IMP_Mailbox_List')->getList($this->_vars->view)->getCacheID($this->_vars->view);
+            $result->ViewPort->updatecacheid = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_MailboxList')->create($this->_vars->view)->getCacheID($this->_vars->view);
             $result->ViewPort->view = $this->_vars->view;
         }
 
@@ -1978,7 +1978,7 @@ class IMP_Ajax_Application extends Horde_Core_Ajax_Application
             }
         }
 
-        return ($GLOBALS['injector']->getInstance('IMP_Mailbox_List')->getList($this->_vars->view)->getCacheID($this->_vars->view) != $this->_vars->cacheid);
+        return ($GLOBALS['injector']->getInstance('IMP_Injector_Factory_MailboxList')->create($this->_vars->view)->getCacheID($this->_vars->view) != $this->_vars->cacheid);
     }
 
     /**
index 0ffd7d4..cc1b843 100644 (file)
@@ -96,7 +96,6 @@ class IMP_Application extends Horde_Registry_Application
             'IMP_Identity' => new IMP_Injector_Binder_Identity(),
             'IMP_Imap_Tree' => new IMP_Injector_Binder_Imaptree(),
             'IMP_Mail' => new IMP_Injector_Binder_Mail(),
-            'IMP_Mailbox_List' => new IMP_Injector_Binder_MailboxList(),
             'IMP_Quota' => new IMP_Injector_Binder_Quota(),
             'IMP_Search' => new IMP_Injector_Binder_Search(),
             'IMP_Sentmail' => new IMP_Injector_Binder_Sentmail()
diff --git a/imp/lib/Injector/Binder/MailboxList.php b/imp/lib/Injector/Binder/MailboxList.php
deleted file mode 100644 (file)
index b8b329c..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-<?php
-/**
- * Binder for IMP_Mailbox_List::.
- *
- * Copyright 2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (GPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
- *
- * @author   Michael Slusarz <slusarz@horde.org>
- * @category Horde
- * @license  http://www.fsf.org/copyleft/gpl.html GPL
- * @package  IMP
- */
-class IMP_Injector_Binder_MailboxList implements Horde_Injector_Binder
-{
-    /**
-     */
-    public function create(Horde_Injector $injector)
-    {
-        return new IMP_Injector_Factory_MailboxList($injector);
-    }
-
-    /**
-     */
-    public function equals(Horde_Injector_Binder $binder)
-    {
-        return false;
-    }
-
-}
index 56fc629..62abbf8 100644 (file)
@@ -32,10 +32,7 @@ class IMP_Injector_Factory_MailboxList
      *
      * @var array
      */
-    private $_instances = array(
-        'list' => array(),
-        'track' => array()
-    );
+    private $_instances = array();
 
     /**
      * Constructor.
@@ -48,54 +45,52 @@ class IMP_Injector_Factory_MailboxList
     }
 
     /**
-     * Return the IMP_Mailbox_List:: instance.
-     *
-     * @param string $mailbox  The mailbox name.
-     *
-     * @return IMP_Mailbox_List  The singleton mailbox instance.
-     * @throws IMP_Exception
-     */
-    public function getList($mailbox)
-    {
-        if (!isset($this->_instances['list'][$mailbox])) {
-            $this->_instances['list'][$mailbox] = new IMP_Mailbox_List($mailbox);
-        }
-
-        return $this->_instances['list'][$mailbox];
-    }
-
-    /**
-     * Return the IMP_Mailbox_List_Track:: instance.
+     * Return the mailbox list instance.
+     * For IMP/MIMP, returns an IMP_Mailbox_List_Track object.
+     * For DIMP, returns an IMP_Mailbox_List object.
      *
      * @param string $mailbox       The mailbox name.
      * @param IMP_Indices $indices  An indices object.
      *
-     *
-     * @return IMP_Mailbox_List_Track  The singleton mailbox instance.
+     * @return IMP_Mailbox_List  The singleton instance.
      * @throws IMP_Exception
      */
-    public function getListTrack($mailbox, $indices = null)
+    public function create($mailbox, $indices = null)
     {
-        if (!isset($this->_instances['track'][$mailbox])) {
-            $ob = null;
-            if (isset($_SESSION['imp']['cache']['imp_mailbox'][$mailbox])) {
-                try {
-                    $ob = @unserialize($_SESSION['imp']['cache']['imp_mailbox'][$mailbox]);
-                } catch (Exception $e) {}
-            }
+        $mode = IMP::getViewMode();
+
+        if (!isset($this->_instances[$mailbox])) {
+            switch ($mode) {
+            case 'dimp':
+                $ob = new IMP_Mailbox_List($mailbox);
+                break;
+
+            case 'imp':
+            case 'mimp':
+                $ob = null;
+                if (isset($_SESSION['imp']['cache']['imp_mailbox'][$mailbox])) {
+                    try {
+                        $ob = @unserialize($_SESSION['imp']['cache']['imp_mailbox'][$mailbox]);
+                    } catch (Exception $e) {}
+                }
 
-            if (!$ob) {
-                $ob = new IMP_Mailbox_List_Track($mailbox);
+                if (!$ob) {
+                    $ob = new IMP_Mailbox_List_Track($mailbox);
+                }
+                break;
             }
 
-            $this->_instances['track'][$mailbox] = $ob;
+            $this->_instances[$mailbox] = $ob;
         }
 
-        if (!is_null($indices)) {
-            $this->_instances['track'][$mailbox]->setIndex($indices);
+        switch ($mode) {
+        case 'imp':
+        case 'mimp':
+            $this->_instances[$mailbox]->setIndex($indices);
+            break;
         }
 
-        return $this->_instances['track'][$mailbox];
+        return $this->_instances[$mailbox];
     }
 
     /**
@@ -103,13 +98,18 @@ class IMP_Injector_Factory_MailboxList
      */
     public function shutdown()
     {
-        /* Cache mailbox information if viewing in standard (IMP) message
-         * mode. Needed to keep navigation consistent when moving through the
-         * message list, and to ensure messages aren't marked as missing in
-         * search mailboxes (e.g. if search is dependent on unseen flag). */
-        foreach ($this->_instances['track'] as $key => $val) {
-            if ($val->changed) {
-                $_SESSION['imp']['cache']['imp_mailbox'][$key] = serialize($val);
+        switch (IMP::getViewMode()) {
+        case 'imp':
+        case 'mimp':
+            /* Cache mailbox information if viewing in standard (IMP) message
+             * mode. Needed to keep navigation consistent when moving through
+             * the message list, and to ensure messages aren't marked as
+             * missing in search mailboxes (e.g. if search is dependent on
+             * unseen flag). */
+            foreach ($this->_instances as $key => $val) {
+                if ($val->changed) {
+                    $_SESSION['imp']['cache']['imp_mailbox'][$key] = serialize($val);
+                }
             }
         }
     }
index 9ba5388..a829711 100644 (file)
@@ -98,7 +98,8 @@ class IMP_Mailbox_List_Track extends IMP_Mailbox_List
      *
      * @param mixed $data  If an integer, the number of messages to increase
      *                     array index by. If an indices object, sets array
-     *                     index to the index value.
+     *                     index to the index value. If null, rebuilds the
+     *                     internal index.
      */
     public function setIndex($data)
     {
@@ -109,7 +110,10 @@ class IMP_Mailbox_List_Track extends IMP_Mailbox_List
                 $this->_rebuild(true);
                 $this->_index = $this->getArrayIndex($uid, $mailbox);
             }
-        } elseif (!is_null($this->_index)) {
+        } elseif (is_null($this->_index)) {
+            $this->_index = null;
+            $this->_rebuild(true);
+        } else {
             $index = $this->_index += $data;
             if (isset($this->_sorted[$this->_index])) {
                 $this->_rebuild();
index 92cc980..a79918d 100644 (file)
@@ -108,7 +108,7 @@ class IMP_Views_ListMessages
         }
 
         /* Generate the sorted mailbox list now. */
-        $imp_mailbox = $GLOBALS['injector']->getInstance('IMP_Mailbox_List')->getList($mbox);
+        $imp_mailbox = $GLOBALS['injector']->getInstance('IMP_Injector_Factory_MailboxList')->create($mbox);
         $sorted_list = $imp_mailbox->getSortedList();
         $msgcount = count($sorted_list['s']);
 
index ce742e9..3c65cda 100644 (file)
@@ -127,7 +127,7 @@ case 'rs':
 }
 
 /* Build the list of messages in the mailbox. */
-$imp_mailbox = $injector->getInstance('IMP_Mailbox_List')->getList(IMP::$mailbox);
+$imp_mailbox = $injector->getInstance('IMP_Injector_Factory_MailboxList')->create(IMP::$mailbox);
 $pageOb = $imp_mailbox->buildMailboxPage($vars->p, $vars->s);
 
 /* Generate page title. */
index a2bbbfd..4f2d9ee 100644 (file)
@@ -225,7 +225,7 @@ if ($conf['user']['allow_folders']) {
 }
 
 /* Build the list of messages in the mailbox. */
-$imp_mailbox = $injector->getInstance('IMP_Mailbox_List')->getList(IMP::$mailbox);
+$imp_mailbox = $injector->getInstance('IMP_Injector_Factory_MailboxList')->create(IMP::$mailbox);
 $pageOb = $imp_mailbox->buildMailboxPage($vars->page, $start);
 $show_preview = $prefs->getValue('preview_enabled');
 
index 0f317b9..ad74c84 100644 (file)
@@ -29,7 +29,7 @@ Horde_Registry::appInit('imp', array(
 $vars = Horde_Variables::getDefaultVariables();
 
 /* Make sure we have a valid index. */
-$imp_mailbox = $injector->getInstance('IMP_Mailbox_List')->getListTrack(IMP::$mailbox, new IMP_Indices(IMP::$thismailbox, IMP::$uid));
+$imp_mailbox = $injector->getInstance('IMP_Injector_Factory_MailboxList')->create(IMP::$mailbox, new IMP_Indices(IMP::$thismailbox, IMP::$uid));
 if (!$imp_mailbox->isValidIndex()) {
     IMP::generateIMPUrl('mailbox-mimp.php', IMP::$mailbox)->add('a', 'm')->redirect();
 }
index 6dd13f6..4e9488a 100644 (file)
@@ -34,7 +34,7 @@ if (!($search_mbox = $injector->getInstance('IMP_Search')->isSearchMbox(IMP::$ma
 }
 
 /* Make sure we have a valid index. */
-$imp_mailbox = $injector->getInstance('IMP_Mailbox_List')->getListTrack(IMP::$mailbox, new IMP_Indices(IMP::$thismailbox, IMP::$uid));
+$imp_mailbox = $injector->getInstance('IMP_Injector_Factory_MailboxList')->create(IMP::$mailbox, new IMP_Indices(IMP::$thismailbox, IMP::$uid));
 if (!$imp_mailbox->isValidIndex()) {
     _returnToMailbox(null, 'message_missing');
     require IMP_BASE . '/mailbox.php';
index 88f49f7..a706306 100644 (file)
@@ -46,7 +46,7 @@ if (!empty($request)) {
     $new_mail = (isset($request_parts[1]) && ($request_parts[1] === 'new'));
 }
 
-$imp_mailbox = $injector->getInstance('IMP_Mailbox_List')->getList($mailbox);
+$imp_mailbox = $injector->getInstance('IMP_Injector_Factory_MailboxList')->create($mailbox);
 $imp_search = $injector->getInstance('IMP_Search');
 
 /* Obtain some information describing the mailbox state. */
index 01b40bc..ca52946 100644 (file)
@@ -28,7 +28,7 @@ $mode = $vars->mode
     : 'thread';
 
 $imp_imap = $injector->getInstance('IMP_Injector_Factory_Imap')->create();
-$imp_mailbox = $injector->getInstance('IMP_Mailbox_List')->getListTrack(IMP::$mailbox, new IMP_Indices(IMP::$thismailbox, IMP::$uid));
+$imp_mailbox = $injector->getInstance('IMP_Injector_Factory_MailboxList')->create(IMP::$mailbox, new IMP_Indices(IMP::$thismailbox, IMP::$uid));
 
 $error = false;
 if ($mode == 'thread') {