From b958240a9442553116b642733c6fc5a7815de2f4 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Mon, 2 Sep 2013 12:14:08 +0000 Subject: [PATCH] * 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 --- etemplate/inc/class.bo_tracking.inc.php | 117 +++++++++++++----------- phpgwapi/inc/class.egw_link.inc.php | 2 +- phpgwapi/inc/class.solink.inc.php | 9 +- 3 files changed, 64 insertions(+), 64 deletions(-) diff --git a/etemplate/inc/class.bo_tracking.inc.php b/etemplate/inc/class.bo_tracking.inc.php index 8f8758929e..5663013b04 100644 --- a/etemplate/inc/class.bo_tracking.inc.php +++ b/etemplate/inc/class.bo_tracking.inc.php @@ -6,7 +6,7 @@ * @author Ralf Becker * @package etemplate * @subpackage api - * @copyright (c) 2007-12 by Ralf Becker + * @copyright (c) 2007-13 by Ralf Becker * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License * @version $Id$ */ @@ -145,13 +145,6 @@ abstract class bo_tracking */ 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) * @@ -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; return !count($this->errors); } @@ -675,6 +651,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 @@ -689,7 +668,8 @@ abstract class bo_tracking //error_log(__METHOD__."(,,'$email',$user_or_lang,$check,$assignment_changed,$deleted)"); 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 { @@ -698,17 +678,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 @@ -722,28 +698,57 @@ abstract class bo_tracking 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(); - // 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'])) + if ($GLOBALS['egw_info']['user']['preferences']['common']['lang'] != translation::$userlang) { - $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 - 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 { @@ -751,10 +756,10 @@ abstract class bo_tracking $notification->set_receivers(array($receiver)); $notification->set_message($body_cache['text']); $notification->set_message($body_cache['html']); - $notification->set_sender($this->get_sender($data,$old,true,$receiver)); - $notification->set_subject($this->get_subject($data,$old,$deleted,$receiver)); - $notification->set_links(array($this->get_notification_link($data,$old,$receiver))); - if (($attachments = $this->get_attachments($data,$old,$receiver)) && is_array($attachments)) + $notification->set_sender($sender); + $notification->set_subject($subject); + $notification->set_links(array($link)); + if ($attachments && is_array($attachments)) { $notification->set_attachments($attachments); } @@ -765,7 +770,9 @@ abstract class bo_tracking $this->errors[] = $exception->getMessage(); return false; } - } else { + } + else + { error_log('tracking: cannot send any notifications because notifications is not installed'); } diff --git a/phpgwapi/inc/class.egw_link.inc.php b/phpgwapi/inc/class.egw_link.inc.php index 4766128f3c..b5372283a3 100644 --- a/phpgwapi/inc/class.egw_link.inc.php +++ b/phpgwapi/inc/class.egw_link.inc.php @@ -1420,7 +1420,7 @@ class egw_link extends solink static function file_access($app,$id,$required=EGW_ACL_READ,$rel_path=null,$user=null) { // 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 if (!self::get_registry($app,'file_access_user') || !($method = self::get_registry($app,'file_access'))) diff --git a/phpgwapi/inc/class.solink.inc.php b/phpgwapi/inc/class.solink.inc.php index d36038f1db..e466cd3d32 100644 --- a/phpgwapi/inc/class.solink.inc.php +++ b/phpgwapi/inc/class.solink.inc.php @@ -38,12 +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; /** * True if call to get_links or get_3links exceeded limit (contains not all rows) */ @@ -83,7 +77,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, @@ -464,7 +458,6 @@ class solink static function init_static( ) { self::$db = $GLOBALS['egw']->db; - self::$user =& $GLOBALS['egw_info']['user']['account_id']; } } solink::init_static();