From 6dbca2c1c51b5d665159d968f84285ab5e34756f Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Mon, 7 May 2007 08:27:50 +0000 Subject: [PATCH] "fix for bug #583: SQL error when deleting account and transfering ownership" --- calendar/inc/class.socal.inc.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/calendar/inc/class.socal.inc.php b/calendar/inc/class.socal.inc.php index b64f290fad..f87916439d 100644 --- a/calendar/inc/class.socal.inc.php +++ b/calendar/inc/class.socal.inc.php @@ -68,8 +68,16 @@ class socal /** * internal copy of the global db-object + * + * @var egw_db */ var $db; + /** + * instance of the async object + * + * @var asyncservice + */ + var $async; /** * Constructor of the socal class @@ -1087,6 +1095,23 @@ ORDER BY cal_user_type, cal_usre_id else { $this->db->update($this->cal_table,array('cal_owner' => $new_user),array('cal_owner' => $old_user),__LINE__,__FILE__); + // delete participation of old user, if new user is already a participant + $this->db->select($this->user_table,'cal_id',array( // MySQL does NOT allow to run this as delete! + 'cal_user_type' => 'u', + 'cal_user_id' => $old_user, + "cal_id IN (SELECT cal_id FROM $this->user_table other WHERE other.cal_id=cal_id AND other.cal_user_id=".(int)$new_user." AND cal_user_type='u')", + ),__LINE__,__FILE__); + $ids = array(); + while(($row = $this->db->row(true))) + { + $ids[] = $row['cal_id']; + } + if ($ids) $this->db->delete($this->user_table,array( + 'cal_user_type' => 'u', + 'cal_user_id' => $old_user, + 'cal_id' => $ids, + ),__LINE__,__FILE__); + // now change participant in the rest to contain new user instead of old user $this->db->update($this->user_table,array('cal_user_id' => $new_user),array('cal_user_type' => 'u','cal_user_id' => $old_user),__LINE__,__FILE__); } }