From 96e82a733ca0afd72efc025f52674ff71325413c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Thu, 8 Nov 2012 22:29:48 +0100 Subject: [PATCH] Fix error in case the database is not available --- .../files/lib/system/SingletonFactory.class.php | 11 +++++++++++ wcfsetup/install/files/lib/system/WCF.class.php | 9 ++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/wcfsetup/install/files/lib/system/SingletonFactory.class.php b/wcfsetup/install/files/lib/system/SingletonFactory.class.php index cb592a7e80..27a26f92ee 100644 --- a/wcfsetup/install/files/lib/system/SingletonFactory.class.php +++ b/wcfsetup/install/files/lib/system/SingletonFactory.class.php @@ -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]); + } } diff --git a/wcfsetup/install/files/lib/system/WCF.class.php b/wcfsetup/install/files/lib/system/WCF.class.php index e100988299..775492cd1e 100644 --- a/wcfsetup/install/files/lib/system/WCF.class.php +++ b/wcfsetup/install/files/lib/system/WCF.class.php @@ -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(); } -- 2.20.1