better session control for felamimail/emailadmin, to control the loading of preferences for the setting of vacations by date by async job (user was not changed (since session was reused), when several users wanted to change their vacation message by date via async job at the same day)

This commit is contained in:
Klaus Leithoff 2010-02-16 17:01:52 +00:00
parent ec4778f6bc
commit df4a507959
5 changed files with 137 additions and 21 deletions

View File

@ -214,7 +214,16 @@
),
);
if ($_restoreSesssion && !(is_array($this->sessionData) && (count($this->sessionData)>0)) ) $this->restoreSessionData();
if ($_restoreSesssion && !(is_array($this->sessionData) && (count($this->sessionData)>0)) )
{
$this->restoreSessionData();
}
if ($_restoreSesssion===false && (is_array($this->sessionData) && (count($this->sessionData)>0)) )
{
// make sure session data will be created new
$this->sessionData = array();
self::saveSessionData();
}
#_debug_array($this->sessionData);
if($_profileID >= 0)
{
@ -222,8 +231,18 @@
$this->profileData = $this->getProfile($_profileID);
$this->imapClass =& CreateObject('emailadmin.'.$this->IMAPServerType[$this->profileData['imapType']]['classname']);
$this->smtpClass =& CreateObject('emailadmin.'.$this->SMTPServerType[$this->profileData['smtpType']]['classname']);
// try autoloading class, if that fails include it from emailadmin
if (!class_exists($class = $this->IMAPServerType[$this->profileData['imapType']]['classname']))
{
include_once(EGW_INCLUDE_ROOT.'/emailadmin/inc/class.'.$class.'.inc.php');
}
$this->imapClass = new $class;
if (!class_exists($class = $this->SMTPServerType[$this->profileData['smtpType']]['classname']))
{
include_once(EGW_INCLUDE_ROOT.'/emailadmin/inc/class.'.$class.'.inc.php');
}
$this->smtpClass = new $class;
}
}
@ -578,10 +597,24 @@
function restoreSessionData()
{
$GLOBALS['egw_info']['flags']['autoload'] = array(__CLASS__,'autoload');
//echo function_backtrace()."<br>";
//unserializing the sessiondata, since they are serialized for objects sake
$this->sessionData = (array) unserialize($GLOBALS['egw']->session->appsession('session_data','emailadmin'));
#$this->userSessionData = $GLOBALS['egw']->session->appsession('user_session_data','emailadmin');
}
/**
* Autoload classes from emailadmin, 'til they get autoloading conform names
*
* @param string $class
*/
static function autoload($class)
{
if (file_exists($file=EGW_INCLUDE_ROOT.'/emailadmin/inc/class.'.$class.'.inc.php'))
{
include_once($file);
}
}
function saveSMTPForwarding($_accountID, $_forwardingAddress, $_keepLocalCopy)

View File

@ -62,17 +62,50 @@
*/
var $autoFolders = array('Drafts', 'Junk', 'Sent', 'Trash', 'Templates');
function bofelamimail($_displayCharset='iso-8859-1')
/**
* Autoload classes from emailadmin, 'til they get autoloading conform names
*
* @param string $class
*/
static function autoload($class)
{
$this->restoreSessionData();
if (file_exists($file=EGW_INCLUDE_ROOT.'/emailadmin/inc/class.'.$class.'.inc.php'))
{
include_once($file);
//error_log(__METHOD__."($class) included $file");
}
elseif (file_exists($file=EGW_INCLUDE_ROOT.'/felamimail/inc/class.'.$class.'.inc.php'))
{
include_once($file);
}
else
{
#error_log(__METHOD__."($class) failed!");
}
}
function bofelamimail($_displayCharset='iso-8859-1',$_restoreSession=true)
{
if ($_restoreSession)
{
//error_log(__METHOD__." Session restore ".function_backtrace());
$this->restoreSessionData();
}
else
{
$this->restoreSessionData();
$lv_mailbox = $this->sessionData['mailbox'];
$this->sessionData = array();
$this->forcePrefReload();
}
// FIXME: this->foldername seems to be unused
//$this->foldername = $this->sessionData['mailbox'];
$this->accountid = $GLOBALS['egw_info']['user']['account_id'];
$this->bopreferences =& CreateObject('felamimail.bopreferences');
$this->sofelamimail =& CreateObject('felamimail.sofelamimail');
self::$botranslation =& CreateObject('phpgwapi.translation');
$this->bopreferences = CreateObject('felamimail.bopreferences',$_restoreSession);
$this->sofelamimail = CreateObject('felamimail.sofelamimail');
self::$botranslation = CreateObject('phpgwapi.translation');
$this->mailPreferences = $this->bopreferences->getPreferences();
if ($this->mailPreferences) {
@ -95,7 +128,7 @@
// no filter active
$this->sessionData['activeFilter'] = "-1";
// default mailbox INBOX
$this->sessionData['mailbox'] = "INBOX";
$this->sessionData['mailbox'] = (($lv_mailbox && self::folderExists($lv_mailbox,true)) ? $lv_mailbox : "INBOX");
// default start message
$this->sessionData['startMessage'] = 1;
// default mailbox for preferences pages
@ -151,6 +184,13 @@
}
function forcePrefReload()
{
// unset the fm_preferences session object, to force the reload/rebuild
$GLOBALS['egw']->session->appsession('fm_preferences','felamimail',serialize(array()));
$GLOBALS['egw']->session->appsession('session_data','emailadmin',serialize(array()));
}
function setACL($_folderName, $_accountName, $_acl)
{
if ( PEAR::isError($this->icServer->setACL($_folderName, $_accountName, $_acl)) ) {
@ -2463,6 +2503,8 @@
function restoreSessionData()
{
$GLOBALS['egw_info']['flags']['autoload'] = array(__CLASS__,'autoload');
$this->sessionData = $GLOBALS['egw']->session->appsession('session_data','felamimail');
}

View File

@ -25,24 +25,64 @@
// stores the users profile
var $profileData;
var $sessionData;
var $boemailadmin;
function bopreferences()
function bopreferences($_restoreSession = true)
{
//error_log(__METHOD__." called ".print_r($_restoreSession,true).function_backtrace());
parent::sopreferences();
$this->boemailadmin = new emailadmin_bo();
if ( !(is_array($this->sessionData) && (count($this->sessionData)>0)) ) $this->restoreSessionData();
$this->boemailadmin = new emailadmin_bo(-1,$_restoreSession);
if ($_restoreSession && !(is_array($this->sessionData) && (count($this->sessionData)>0)) ) $this->restoreSessionData();
if ($_restoreSession===false && (is_array($this->sessionData) && (count($this->sessionData)>0)) )
{
//error_log(__METHOD__." Unset Session ".function_backtrace());
//make sure session data will be reset
$this->sessionData = array();
$this->profileData = array();
self::saveSessionData();
}
//error_log(__METHOD__.print_r($this->sessionData,true));
if (isset($this->sessionData['profileData']) && is_a($this->sessionData['profileData'],'ea_preferences')) {
$this->profileData = $this->sessionData['profileData'];
}
}
function restoreSessionData()
{
//error_log(__METHOD__." Session restore ".function_backtrace());
// set an own autoload function, search emailadmin for missing classes
$GLOBALS['egw_info']['flags']['autoload'] = array(__CLASS__,'autoload');
$this->sessionData = (array) unserialize($GLOBALS['egw']->session->appsession('fm_preferences','felamimail'));
}
/**
* Autoload classes from emailadmin, 'til they get autoloading conform names
*
* @param string $class
*/
static function autoload($class)
{
if (file_exists($file=EGW_INCLUDE_ROOT.'/emailadmin/inc/class.'.$class.'.inc.php'))
{
include_once($file);
//error_log(__METHOD__."($class) included $file");
}
elseif (file_exists($file=EGW_INCLUDE_ROOT.'/felamimail/inc/class.'.$class.'.inc.php'))
{
include_once($file);
}
else
{
#error_log(__METHOD__."($class) failed!");
}
}
function saveSessionData()
{
$GLOBALS['egw']->session->appsession('fm_preferences','felamimail',serialize($this->sessionData));
}
// get the first active user defined account
function getAccountData(&$_profileData, $_accountID=NULL)
{

View File

@ -150,7 +150,8 @@
function async_vacation($_vacation)
{
if ($this->debug) error_log(__CLASS__.'::'.__METHOD__.'('.print_r($_vacation,true).')');
$bopreferences =& CreateObject('felamimail.bopreferences');
$_restoreSession = false; // as in async, each call may be for a different user
$bopreferences = CreateObject('felamimail.bopreferences',$_restoreSession);
$mailPreferences = $bopreferences->getPreferences();
$icServer = $mailPreferences->getIncomingServer(0);

View File

@ -45,10 +45,10 @@
$this->timeCounter = microtime(true);
$this->displayCharset = $GLOBALS['egw']->translation->charset();
$this->bofelamimail =& CreateObject('felamimail.bofelamimail',$this->displayCharset);
$this->bofelamimail = CreateObject('felamimail.bofelamimail',$this->displayCharset,false);
$this->bofilter =& CreateObject('felamimail.bofilter');
$this->bopreferences =& CreateObject('felamimail.bopreferences');
$this->bofilter = CreateObject('felamimail.bofilter');
$this->bopreferences =& $this->bofelamimail->bopreferences; //CreateObject('felamimail.bopreferences');
$this->preferences = $this->bopreferences->getPreferences();
$this->botranslation =& CreateObject('phpgwapi.translation');