* EMail/all apps: fixed notifications caused EMail to loose connection to IMAP server

- temporary switch of user-enviroment as not fully restored and caused email connection of notified user being tried
- bo_tracking::send_notification does not all switching and is save to used without do_notifications
- references to $GLOBALS[egw_info][user] are now removed, because they also stopped correctly switching user enviroments for notifications
This commit is contained in:
Ralf Becker 2013-09-02 12:14:08 +00:00
parent 97c1c1e75d
commit b958240a94
3 changed files with 64 additions and 64 deletions

View File

@ -6,7 +6,7 @@
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de> * @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @package etemplate * @package etemplate
* @subpackage api * @subpackage api
* @copyright (c) 2007-12 by Ralf Becker <RalfBecker-AT-outdoor-training.de> * @copyright (c) 2007-13 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @version $Id$ * @version $Id$
*/ */
@ -145,13 +145,6 @@ abstract class bo_tracking
*/ */
var $user; var $user;
/**
* Saved user preferences, if send_notifications need to set an other language
*
* @access private
* @var array
*/
var $save_prefs;
/** /**
* Datetime format of the currently notified user (send_notificaton) * Datetime format of the currently notified user (send_notificaton)
* *
@ -632,23 +625,6 @@ abstract class bo_tracking
} }
} }
} }
// restore the user enviroment
if ($this->save_prefs)
{
$GLOBALS['egw_info']['user'] = $this->save_prefs;
// need to call preferences constructor and read_repository, to set user timezone again
$GLOBALS['egw']->preferences->__construct($GLOBALS['egw_info']['user']['account_id']);
$GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->read_repository(false); // no session prefs!
unset($this->save_prefs);
// Re-load date/time preferences
egw_time::init();
}
if ($GLOBALS['egw_info']['user']['preferences']['common']['lang'] != translation::$userlang)
{
translation::init();
}
$email_notified = $email_sent; $email_notified = $email_sent;
return !count($this->errors); return !count($this->errors);
} }
@ -675,6 +651,9 @@ abstract class bo_tracking
* *
* Called by track() or externally for sending async notifications * Called by track() or externally for sending async notifications
* *
* Method changes $GLOBALS['egw_info']['user'], so everything called by it, eg. get_(subject|body|links|attachements),
* must NOT store something from user enviroment! By the end of the method, everything get changed back.
*
* @param array $data current entry * @param array $data current entry
* @param array $old=null old/last state of the entry or null for a new entry * @param array $old=null old/last state of the entry or null for a new entry
* @param string $email address to send the notification to * @param string $email address to send the notification to
@ -689,7 +668,8 @@ abstract class bo_tracking
//error_log(__METHOD__."(,,'$email',$user_or_lang,$check,$assignment_changed,$deleted)"); //error_log(__METHOD__."(,,'$email',$user_or_lang,$check,$assignment_changed,$deleted)");
if (!$email) return false; if (!$email) return false;
if (!$this->save_prefs) $this->save_prefs = $GLOBALS['egw_info']['user']; $save_user = $GLOBALS['egw_info']['user'];
$do_notify = true;
if (is_numeric($user_or_lang)) // user --> read everything from his prefs if (is_numeric($user_or_lang)) // user --> read everything from his prefs
{ {
@ -698,17 +678,13 @@ abstract class bo_tracking
$GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->read_repository(false); // no session prefs! $GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->read_repository(false); // no session prefs!
if ($check && $this->check2pref) $check = $this->check2pref[$check]; if ($check && $this->check2pref) $check = $this->check2pref[$check];
if ($check && !$GLOBALS['egw_info']['user']['preferences'][$this->app][$check])
if ($check && !$GLOBALS['egw_info']['user']['preferences'][$this->app][$check] || // no notification requested
// only notification about changed assignment requested
$check && $GLOBALS['egw_info']['user']['preferences'][$this->app][$check] === 'assignment' && !$assignment_changed ||
$this->user == $user_or_lang && !$this->notify_current_user) // no popup for own actions
{ {
return false; // no notification requested $do_notify = false; // no notification requested / necessary
}
if ($check && $GLOBALS['egw_info']['user']['preferences'][$this->app][$check] === 'assignment' && !$assignment_changed)
{
return false; // only notification about changed assignment requested
}
if($this->user == $user_or_lang && !$this->notify_current_user)
{
return false; // no popup for own actions
} }
} }
else else
@ -722,28 +698,57 @@ abstract class bo_tracking
translation::init(); translation::init();
} }
// Load date/time preferences into egw_time if ($do_notify)
{
// Load date/time preferences into egw_time
egw_time::init();
// Cache message body to not have to re-generate it every time
$lang = translation::$userlang;
$date_format = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'] .
$GLOBALS['egw_info']['user']['preferences']['common']['timeformat'];
// Cache text body
$body_cache =& $this->body_cache[$data[$this->id_field]][$lang][$date_format];
if(empty($data[$this->id_field]) || !isset($body_cache['text']))
{
$body_cache['text'] = $this->get_body(false,$data,$old,false,$receiver);
}
// Cache HTML body
if(empty($data[$this->id_field]) || !isset($body_cache['html']))
{
$body_cache['html'] = $this->get_body(true,$data,$old,false,$receiver);
}
// get rest of notification message
$sender = $this->get_sender($data,$old,true,$receiver);
$subject = $this->get_subject($data,$old,$deleted,$receiver);
$link = $this->get_notification_link($data,$old,$receiver);
$attachments = $this->get_attachments($data,$old,$receiver);
}
// restore user enviroment BEFORE calling notification class or returning
$GLOBALS['egw_info']['user'] = $save_user;
// need to call preferences constructor and read_repository, to set user timezone again
$GLOBALS['egw']->preferences->__construct($GLOBALS['egw_info']['user']['account_id']);
$GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->read_repository(false); // no session prefs!
// Re-load date/time preferences
egw_time::init(); egw_time::init();
// Cache message body to not have to re-generate it every time if ($GLOBALS['egw_info']['user']['preferences']['common']['lang'] != translation::$userlang)
$lang = translation::$userlang;
$date_format = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'] .
$GLOBALS['egw_info']['user']['preferences']['common']['timeformat'];
// Cache text body
$body_cache =& $this->body_cache[$data[$this->id_field]][$lang][$date_format];
if(empty($data[$this->id_field]) || !isset($body_cache['text']))
{ {
$body_cache['text'] = $this->get_body(false,$data,$old,false,$receiver); translation::init();
} }
// Cache HTML body
if(empty($data[$this->id_field]) || !isset($body_cache['html'])) if (!$do_notify)
{ {
$body_cache['html'] = $this->get_body(true,$data,$old,false,$receiver); return false;
} }
// send over notification_app // send over notification_app
if ($GLOBALS['egw_info']['apps']['notifications']['enabled']) { if ($GLOBALS['egw_info']['apps']['notifications']['enabled'])
{
// send via notification_app // send via notification_app
$receiver = is_numeric($user_or_lang) ? $user_or_lang : $email; $receiver = is_numeric($user_or_lang) ? $user_or_lang : $email;
try { try {
@ -751,10 +756,10 @@ abstract class bo_tracking
$notification->set_receivers(array($receiver)); $notification->set_receivers(array($receiver));
$notification->set_message($body_cache['text']); $notification->set_message($body_cache['text']);
$notification->set_message($body_cache['html']); $notification->set_message($body_cache['html']);
$notification->set_sender($this->get_sender($data,$old,true,$receiver)); $notification->set_sender($sender);
$notification->set_subject($this->get_subject($data,$old,$deleted,$receiver)); $notification->set_subject($subject);
$notification->set_links(array($this->get_notification_link($data,$old,$receiver))); $notification->set_links(array($link));
if (($attachments = $this->get_attachments($data,$old,$receiver)) && is_array($attachments)) if ($attachments && is_array($attachments))
{ {
$notification->set_attachments($attachments); $notification->set_attachments($attachments);
} }
@ -765,7 +770,9 @@ abstract class bo_tracking
$this->errors[] = $exception->getMessage(); $this->errors[] = $exception->getMessage();
return false; return false;
} }
} else { }
else
{
error_log('tracking: cannot send any notifications because notifications is not installed'); error_log('tracking: cannot send any notifications because notifications is not installed');
} }

View File

@ -1420,7 +1420,7 @@ class egw_link extends solink
static function file_access($app,$id,$required=EGW_ACL_READ,$rel_path=null,$user=null) static function file_access($app,$id,$required=EGW_ACL_READ,$rel_path=null,$user=null)
{ {
// are we called for an other user // are we called for an other user
if ($user && $user != self::$user) if ($user && $user != $GLOBALS['egw_info']['user']['account_id'])
{ {
// check if app supports file_access WITH 4th $user parameter --> return false if not // check if app supports file_access WITH 4th $user parameter --> return false if not
if (!self::get_registry($app,'file_access_user') || !($method = self::get_registry($app,'file_access'))) if (!self::get_registry($app,'file_access_user') || !($method = self::get_registry($app,'file_access')))

View File

@ -38,12 +38,6 @@ class solink
* @var egw_db * @var egw_db
*/ */
private static $db; private static $db;
/**
* Reference to current user from $GLOBALS['egw_info']['user']['account_id']
*
* @var int
*/
protected static $user;
/** /**
* True if call to get_links or get_3links exceeded limit (contains not all rows) * True if call to get_links or get_3links exceeded limit (contains not all rows)
*/ */
@ -83,7 +77,7 @@ class solink
} }
if (!$owner) if (!$owner)
{ {
$owner = self::$user; $owner = $GLOBALS['egw_info']['user']['account_id'];
} }
return self::$db->insert(self::TABLE,array( return self::$db->insert(self::TABLE,array(
'link_app1' => $app1, 'link_app1' => $app1,
@ -464,7 +458,6 @@ class solink
static function init_static( ) static function init_static( )
{ {
self::$db = $GLOBALS['egw']->db; self::$db = $GLOBALS['egw']->db;
self::$user =& $GLOBALS['egw_info']['user']['account_id'];
} }
} }
solink::init_static(); solink::init_static();