From 78669a307882f3476b4064956192c97a008f8fd4 Mon Sep 17 00:00:00 2001 From: Florian Schlichting Date: Thu, 5 Jan 2017 11:55:15 +0100 Subject: [PATCH] delete obsolete entries when updating addressbooks as external resources (see comment on !34) --- inc/caldav-PUT-functions.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/inc/caldav-PUT-functions.php b/inc/caldav-PUT-functions.php index ce12b809..9cdeedef 100644 --- a/inc/caldav-PUT-functions.php +++ b/inc/caldav-PUT-functions.php @@ -716,7 +716,7 @@ function import_addressbook_collection( $vcard_content, $user_no, $path, $caldav if ( !(isset($c->skip_bad_event_on_import) && $c->skip_bad_event_on_import) ) $qry->Begin(); $base_params = array( - ':collection_id' => $collection->collection_id, + ':collection_id' => $collection_id, ':session_user' => $session->user_no, ':caldav_type' => 'VCARD' ); @@ -805,6 +805,17 @@ EOSQL; if ( isset($c->skip_bad_event_on_import) && $c->skip_bad_event_on_import ) $qry->Commit(); } + if ( !$appending && count($current_data) > 0 ) { + $params = array( ':collection_id' => $collection_id ); + if ( isset($c->skip_bad_event_on_import) && $c->skip_bad_event_on_import ) $qry->Begin(); + foreach( $current_data AS $dav_name => $data ) { + $params[':dav_name'] = $dav_name; + $qry->QDo('DELETE FROM caldav_data WHERE collection_id = :collection_id AND dav_name = :dav_name', $params); + $qry->QDo('SELECT write_sync_change(:collection_id, 404, :dav_name)', $params); + } + if ( isset($c->skip_bad_event_on_import) && $c->skip_bad_event_on_import ) $qry->Commit(); + } + if ( !(isset($c->skip_bad_event_on_import) && $c->skip_bad_event_on_import) ) { if ( ! $qry->Commit() ) rollback_on_error( $caldav_context, $user_no, $path, 'Database error on COMMIT'); }