0012478: Email: update cache error repeating when folder is missing
authorPhilipp Schüle <p.schuele@metaways.de>
Thu, 29 Dec 2016 15:19:05 +0000 (16:19 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Tue, 14 Feb 2017 09:37:10 +0000 (10:37 +0100)
* remove folder from folder cache if it has no children

https://forge.tine20.org/view.php?id=12478

Change-Id: I4ea6067bc33b7ac93fb823bcf5103b6acdf88e2c
Reviewed-on: http://gerrit.tine20.com/customers/4025
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Felamimail/Frontend/JsonTest.php
tine20/Felamimail/Controller/Cache/Message.php
tine20/Felamimail/Frontend/ActiveSync.php

index 2a5576a..3d39a85 100644 (file)
@@ -7,7 +7,7 @@ use Sabre\DAV;
  *
  * @package     Felamimail
  * @license     http://www.gnu.org/licenses/agpl.html
- * @copyright   Copyright (c) 2009-2014 Metaways Infosystems GmbH (http://www.metaways.de)
+ * @copyright   Copyright (c) 2009-2017 Metaways Infosystems GmbH (http://www.metaways.de)
  * @author      Philipp Schüle <p.schuele@metaways.de>
  */
 
index c8d1d8b..80f1d93 100644 (file)
@@ -264,7 +264,7 @@ class Felamimail_Controller_Cache_Message extends Felamimail_Controller_Message
         
         $this->_availableUpdateTime = $_time;
        
-        try { 
+        try {
             $this->_expungeCacheFolder($folder, $imap);
         } catch (Felamimail_Exception_IMAPFolderNotFound $feifnf) {
             return $folder;
@@ -321,18 +321,22 @@ class Felamimail_Controller_Cache_Message extends Felamimail_Controller_Message
         try {
             $_imap->expunge(Felamimail_Model_Folder::encodeFolderName($_folder->globalname));
         } catch (Zend_Mail_Storage_Exception $zmse) {
-            Tinebase_Exception::log($zmse);
-            
-            if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ 
-                . ' Marking folder as not selectable: ' . print_r($_folder->toArray(), true));
-            
-            // mark folder as not selectable + finish cache update
-            $_folder->is_selectable = 0;
+            if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__
+                . ' ' . $zmse);
+
             $_folder->cache_status = Felamimail_Model_Folder::CACHE_STATUS_COMPLETE;
-            $_folder = Felamimail_Controller_Folder::getInstance()->update($_folder);
-            
-            // @todo check if folder is really deleted?
-            //Felamimail_Controller_Cache_Folder::getInstance()->delete($_folder->getId());
+            $_folder->is_selectable = 0;
+
+            if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__
+                . ' Finish cache update and mark folder as not selectable: ' . print_r($_folder->toArray(), true));
+
+            if (! $_folder->has_children) {
+                if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__
+                    . ' Removing folder from database');
+                Felamimail_Controller_Cache_Folder::getInstance()->delete($_folder->getId());
+            } else {
+                $_folder = Felamimail_Controller_Folder::getInstance()->update($_folder);
+            }
             
             throw new Felamimail_Exception_IMAPFolderNotFound('Folder not found / is not selectable: ' . $_folder->globalname);
         }
index 66836e2..85e811b 100644 (file)
@@ -688,7 +688,12 @@ class Felamimail_Frontend_ActiveSync extends ActiveSync_Frontend_Abstract implem
     protected function _inspectGetCountOfChanges(Syncroton_Backend_IContent $contentBackend, Syncroton_Model_IFolder $folder, Syncroton_Model_ISyncState $syncState)
     {
         if (strpos($folder->serverId, $this->_fakePrefix) === false) {
-            Felamimail_Controller_Cache_Message::getInstance()->updateCache($folder->serverId, 10);
+            try {
+                Felamimail_Controller_Cache_Message::getInstance()->updateCache($folder->serverId, 10);
+            } catch (Tinebase_Exception_NotFound $tenf) {
+                if (Tinebase_Core::isLogLevel(Zend_Log::WARN)) Tinebase_Core::getLogger()->warn(
+                    __METHOD__ . '::' . __LINE__ . " Could not update folder cache: " . $tenf);
+            }
         }
     }