mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-02-22 21:30:54 +01:00
* 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:
parent
242b62fb60
commit
f07e86026a
@ -6,7 +6,7 @@
|
||||
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @package etemplate
|
||||
* @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
|
||||
* @version $Id$
|
||||
*/
|
||||
@ -144,13 +144,6 @@ abstract class bo_tracking
|
||||
* @var int;
|
||||
*/
|
||||
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)
|
||||
*
|
||||
@ -486,20 +479,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);
|
||||
}
|
||||
if ($GLOBALS['egw_info']['user']['preferences']['common']['lang'] != translation::$userlang)
|
||||
{
|
||||
translation::init();
|
||||
}
|
||||
return !count($this->errors);
|
||||
}
|
||||
|
||||
@ -508,6 +487,9 @@ abstract class bo_tracking
|
||||
*
|
||||
* 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 $old=null old/last state of the entry or null for a new entry
|
||||
* @param string $email address to send the notification to
|
||||
@ -521,7 +503,8 @@ abstract class bo_tracking
|
||||
//error_log("bo_trackering::send_notification(,,'$email',$user_or_lang,$check)");
|
||||
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
|
||||
{
|
||||
@ -529,17 +512,13 @@ abstract class bo_tracking
|
||||
$GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->read_repository(false); // no session prefs!
|
||||
|
||||
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
|
||||
}
|
||||
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
|
||||
$do_notify = false; // no notification requested / necessary
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -553,27 +532,80 @@ abstract class bo_tracking
|
||||
translation::init();
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
if ($GLOBALS['egw_info']['user']['preferences']['common']['lang'] != translation::$userlang)
|
||||
{
|
||||
translation::init();
|
||||
}
|
||||
|
||||
if (!$do_notify)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// send over notification_app
|
||||
if ($GLOBALS['egw_info']['apps']['notifications']['enabled']) {
|
||||
if ($GLOBALS['egw_info']['apps']['notifications']['enabled'])
|
||||
{
|
||||
// send via notification_app
|
||||
$receiver = is_numeric($user_or_lang) ? $user_or_lang : $email;
|
||||
try {
|
||||
$notification = new notifications();
|
||||
$notification->set_receivers(array($receiver));
|
||||
$notification->set_message($this->get_body(false,$data,$old,false)); // set message as plaintext
|
||||
$notification->set_message($this->get_body(true,$data,$old,false)); // and html
|
||||
$notification->set_sender($this->get_sender($data,$old,true));
|
||||
$notification->set_subject($this->get_subject($data,$old));
|
||||
$notification->set_links(array($this->get_notification_link($data,$old)));
|
||||
$attachments = $this->get_attachments($data,$old);
|
||||
if(is_array($attachments)) { $notification->set_attachments($attachments); }
|
||||
$notification->set_message($body_cache['text']);
|
||||
$notification->set_message($body_cache['html']);
|
||||
$notification->set_sender($sender);
|
||||
$notification->set_subject($subject);
|
||||
$notification->set_links(array($link));
|
||||
if ($attachments && is_array($attachments))
|
||||
{
|
||||
$notification->set_attachments($attachments);
|
||||
}
|
||||
$notification->send();
|
||||
}
|
||||
catch (Exception $exception) {
|
||||
$this->errors[] = $exception->getMessage();
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
error_log('tracking: cannot send any notifications because notifications is not installed');
|
||||
}
|
||||
|
||||
|
@ -38,13 +38,6 @@ class solink
|
||||
* @var egw_db
|
||||
*/
|
||||
private static $db;
|
||||
/**
|
||||
* Reference to current user from $GLOBALS['egw_info']['user']['account_id']
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected static $user;
|
||||
|
||||
/**
|
||||
* creats a link between $app1,$id1 and $app2,$id2
|
||||
*
|
||||
@ -79,7 +72,7 @@ class solink
|
||||
}
|
||||
if (!$owner)
|
||||
{
|
||||
$owner = self::$user;
|
||||
$owner = $GLOBALS['egw_info']['user']['account_id'];
|
||||
}
|
||||
return self::$db->insert(self::TABLE,array(
|
||||
'link_app1' => $app1,
|
||||
@ -391,7 +384,6 @@ class solink
|
||||
static function init_static( )
|
||||
{
|
||||
self::$db = $GLOBALS['egw']->db;
|
||||
self::$user =& $GLOBALS['egw_info']['user']['account_id'];
|
||||
}
|
||||
}
|
||||
solink::init_static();
|
||||
|
Loading…
Reference in New Issue
Block a user