From 609c5e9da9bb52c317eea1abbd424cca181caad9 Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Mon, 11 Jul 2011 06:51:42 -0400
Subject: [PATCH] Session object can be null if db/memcache is not available
---
program/include/rcmail.php | 21 +++++++++++++++++++--
1 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/program/include/rcmail.php b/program/include/rcmail.php
index e94e205..72f0efa 100644
--- a/program/include/rcmail.php
+++ b/program/include/rcmail.php
@@ -124,6 +124,7 @@
private $address_books = array();
private $caches = array();
private $action_map = array();
+ private $shutdown_functions = array();
/**
@@ -507,7 +508,7 @@
$this->output->set_env('comm_path', $this->comm_path);
$this->output->set_charset(RCMAIL_CHARSET);
- // add some basic label to client
+ // add some basic labels to client
$this->output->add_label('loading', 'servererror');
return $this->output;
@@ -1142,6 +1143,9 @@
*/
public function shutdown()
{
+ foreach ($this->shutdown_functions as $function)
+ call_user_func($function);
+
if (is_object($this->smtp))
$this->smtp->disconnect();
@@ -1161,7 +1165,7 @@
$this->imap->close();
// before closing the database connection, write session data
- if ($_SERVER['REMOTE_ADDR']) {
+ if ($_SERVER['REMOTE_ADDR'] && is_object($this->session)) {
$this->session->cleanup();
session_write_close();
}
@@ -1183,6 +1187,19 @@
/**
+ * Registers shutdown function to be executed on shutdown.
+ * The functions will be executed before destroying any
+ * objects like smtp, imap, session, etc.
+ *
+ * @param callback Function callback
+ */
+ public function add_shutdown_function($function)
+ {
+ $this->shutdown_functions[] = $function;
+ }
+
+
+ /**
* Generate a unique token to be used in a form request
*
* @return string The request token
--
Gitblit v1.9.1