Fix error in case the database is not available
authorTim Düsterhus <duesterhus@woltlab.com>
Thu, 8 Nov 2012 21:29:48 +0000 (22:29 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Thu, 8 Nov 2012 21:30:11 +0000 (22:30 +0100)
wcfsetup/install/files/lib/system/SingletonFactory.class.php
wcfsetup/install/files/lib/system/WCF.class.php

index cb592a7e80b7ab32d77300e58b4a8cb55271ddbf..27a26f92ee0c4754ea5fc10c8d887e676093f2ad 100644 (file)
@@ -58,4 +58,15 @@ abstract class SingletonFactory {
                
                return self::$__singletonObjects[$className];
        }
+
+       /**
+        * Returns whether this singleton is already initialized.
+        * 
+        * @return boolean
+        */
+       public static final function isSingletonInitialized() {
+               $className = get_called_class();
+               
+               return isset(self::$__singletonObjects[$className]);
+       }
 }
index e1009882998ac7fd921b6103ab6a35e91a463979..775492cd1ea4afcd3148b33a6f92d98e59c01cbd 100644 (file)
@@ -123,10 +123,13 @@ class WCF {
         * Replacement of the "__destruct()" method.
         * Seems that under specific conditions (windows) the destructor is not called automatically.
         * So we use the php register_shutdown_function to register an own destructor method.
-        * Flushs the output, updates the session and executes the shutdown queries.
+        * Flushs the output, closes caches and updates the session.
         */
        public static function destruct() {
-               // flush ouput
+               // database has to be initialized
+               if (!is_object(self::$dbObj)) return;
+               
+               // flush output
                if (ob_get_level() && ini_get('output_handler')) {
                        ob_flush();
                }
@@ -140,7 +143,7 @@ class WCF {
                }
                
                // close cache source
-               if (is_object(CacheHandler::getInstance()) && is_object(CacheHandler::getInstance()->getCacheSource())) {
+               if (CacheHandler::isSingletonInitialized() && is_object(CacheHandler::getInstance()) && is_object(CacheHandler::getInstance()->getCacheSource())) {
                        CacheHandler::getInstance()->getCacheSource()->close();
                }