From 074b893e37620718eb417e9e9fe5f924f029f9ca Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Thu, 22 Apr 2010 16:09:36 +0000 Subject: [PATCH] Change preserving deleted events. For speed improvements, use an extra column instead of joining to the sync tables --- calendar/inc/class.calendar_boupdate.inc.php | 8 +++++++- calendar/inc/class.calendar_so.inc.php | 6 +++--- calendar/setup/setup.inc.php | 3 ++- calendar/setup/tables_current.inc.php | 3 ++- calendar/setup/tables_update.inc.php | 13 +++++++++++++ 5 files changed, 27 insertions(+), 6 deletions(-) diff --git a/calendar/inc/class.calendar_boupdate.inc.php b/calendar/inc/class.calendar_boupdate.inc.php index c7de969139..570fcc860a 100644 --- a/calendar/inc/class.calendar_boupdate.inc.php +++ b/calendar/inc/class.calendar_boupdate.inc.php @@ -1165,9 +1165,15 @@ class calendar_boupdate extends calendar_bo if (!$recur_date || $event['recur_type'] == MCAL_RECUR_NONE) { $config = config::read('phpgwapi'); - if(!$config['calendar_delete_history'] || $GLOBALS['egw']->contenthistory->getTSforAction('calendar', $cal_id, 'delete')) { + if(!$config['calendar_delete_history'] || $event['deleted']) + { $this->so->delete($cal_id); } + elseif ($config['calendar_delete_history']) + { + $event['deleted'] = true; + $this->save($event); + } $GLOBALS['egw']->contenthistory->updateTimeStamp('calendar',$cal_id,'delete',time()); // delete all links to the event diff --git a/calendar/inc/class.calendar_so.inc.php b/calendar/inc/class.calendar_so.inc.php index 5655d41d74..63c0264319 100644 --- a/calendar/inc/class.calendar_so.inc.php +++ b/calendar/inc/class.calendar_so.inc.php @@ -399,12 +399,12 @@ class calendar_so if (!$useUnionQuery) $where[] = '('.implode(' OR ',$to_or).')'; if($filter != 'deleted') { - $where[] = "sync_deleted IS NULL"; + $where[] = "!cal_deleted"; } switch($filter) { case 'deleted': - $where[] = "sync_deleted IS NOT NULL"; break; + $where[] = "cal_deleted"; break; case 'unknown': $where[] = "cal_status='U'"; break; case 'accepted': @@ -448,7 +448,7 @@ class calendar_so // changed the original OR in the query into a union, to speed up the query execution under MySQL 5 $select = array( 'table' => $this->cal_table, - 'join' => "JOIN $this->dates_table ON $this->cal_table.cal_id=$this->dates_table.cal_id JOIN $this->user_table ON $this->cal_table.cal_id=$this->user_table.cal_id LEFT JOIN $this->repeats_table ON $this->cal_table.cal_id=$this->repeats_table.cal_id JOIN egw_api_content_history ON egw_api_content_history.sync_appname = 'calendar' AND egw_api_content_history.sync_contentid = $history_id", + 'join' => "JOIN $this->dates_table ON $this->cal_table.cal_id=$this->dates_table.cal_id JOIN $this->user_table ON $this->cal_table.cal_id=$this->user_table.cal_id LEFT JOIN $this->repeats_table ON $this->cal_table.cal_id=$this->repeats_table.cal_id", 'cols' => $cols, 'where' => $where, 'app' => 'calendar', diff --git a/calendar/setup/setup.inc.php b/calendar/setup/setup.inc.php index 65b7444f1e..c5b40d4cc8 100755 --- a/calendar/setup/setup.inc.php +++ b/calendar/setup/setup.inc.php @@ -10,7 +10,7 @@ */ $setup_info['calendar']['name'] = 'calendar'; -$setup_info['calendar']['version'] = '1.7.010'; +$setup_info['calendar']['version'] = '1.7.011'; $setup_info['calendar']['app_order'] = 3; $setup_info['calendar']['enable'] = 1; $setup_info['calendar']['index'] = 'calendar.calendar_uiviews.index'; @@ -66,3 +66,4 @@ $setup_info['calendar']['check_install'] = array( ), ); + diff --git a/calendar/setup/tables_current.inc.php b/calendar/setup/tables_current.inc.php index 4ab6964ba2..f2bb3d5657 100644 --- a/calendar/setup/tables_current.inc.php +++ b/calendar/setup/tables_current.inc.php @@ -30,7 +30,8 @@ $phpgw_baseline = array( 'cal_creator' => array('type' => 'int','precision' => '4','nullable' => False,'comment' => 'creating user'), 'cal_created' => array('type' => 'int','precision' => '8','nullable' => False,'comment' => 'creation time of event'), 'cal_recurrence' => array('type' => 'int','precision' => '8','nullable' => False,'default' => '0','comment' => 'cal_start of original recurrence for exception'), - 'tz_id' => array('type' => 'int','precision' => '4','comment' => 'key into egw_cal_timezones') + 'tz_id' => array('type' => 'int','precision' => '4','comment' => 'key into egw_cal_timezones'), + 'cal_deleted' => array('type' => 'bool','nullable' => False,'default' => '0','comment' => '1 if the event has been deleted, but you want to keep it around') ), 'pk' => array('cal_id'), 'fk' => array(), diff --git a/calendar/setup/tables_update.inc.php b/calendar/setup/tables_update.inc.php index d670e850a4..cdcaf77266 100644 --- a/calendar/setup/tables_update.inc.php +++ b/calendar/setup/tables_update.inc.php @@ -2077,3 +2077,16 @@ function calendar_upgrade1_7_009() return $GLOBALS['setup_info']['calendar']['currentver'] = '1.7.010'; } + +function calendar_upgrade1_7_010() +{ + $GLOBALS['egw_setup']->oProc->AddColumn('egw_cal','cal_deleted',array( + 'type' => 'bool', + 'nullable' => False, + 'default' => '0', + 'comment' => '1 if the event has been deleted, but you want to keep it around' + )); + + return $GLOBALS['setup_info']['calendar']['currentver'] = '1.7.011'; +} +