From bdac50531f06d079533c8a8fecbb8e198acb7270 Mon Sep 17 00:00:00 2001 From: ralf Date: Fri, 7 Jun 2024 18:55:49 +0200 Subject: [PATCH] script to merge multiple events with same UID due to calendar-import per user without participants and organizer --- doc/merge-cal-events-by-uid.sh | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 doc/merge-cal-events-by-uid.sh diff --git a/doc/merge-cal-events-by-uid.sh b/doc/merge-cal-events-by-uid.sh new file mode 100755 index 0000000000..42315067bc --- /dev/null +++ b/doc/merge-cal-events-by-uid.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# +# This script merges multiple events with same uid existing due to importing each users calendar without participant or chair information. +# +# The event-owner is kinda random, as events are merged in the one with the smallest cal_id / earliest imported! +# + +DB=${1:-egroupware} + +# merge multiple single events or series masters with same uid +mysql $DB --execute "SELECT min(cal_id),cal_uid FROM egw_cal where cal_reference=0 group by cal_uid having count(*) > 1" --skip-column-names | +while read ID UUID; do +#echo "#$ID: $UUID" +cat << EOF | mysql $DB +update ignore egw_cal_user set cal_id=$ID where cal_id in (select cal_id from egw_cal where cal_uid='$UUID' and cal_reference=0); +delete from egw_cal_user where cal_id<>$ID AND cal_id in (select cal_id from egw_cal where cal_uid='$UUID' and cal_reference=0); +update ignore egw_cal_dates set cal_id=$ID where cal_id in (select cal_id from egw_cal where cal_uid='$UUID' and cal_reference=0); +delete from egw_cal_dates where cal_id<>$ID AND cal_id in (select cal_id from egw_cal where cal_uid='$UUID' and cal_reference=0); +delete from egw_cal_repeats where cal_id<>$ID AND cal_id in (select cal_id from egw_cal where cal_uid='$UUID' and cal_reference=0); +update egw_cal set cal_reference=$ID where cal_reference<>0 and cal_uid='$UUID'; +delete from egw_cal where cal_id<>$ID AND cal_id in (select cal_id from egw_cal where cal_uid='$UUID' and cal_reference=0); +EOF +done + +# merge multiple recurrences/exceptions at same time +mysql $DB --execute "SELECT min(cal_id),cal_uid,cal_recurrence FROM egw_cal where cal_reference<>0 group by cal_uid,cal_recurrence having count(*) > 1" --skip-column-names | +while read ID UUID RECURRENCE; do +#echo "#$ID: $UUID: RECURRENCE" +cat << EOF | mysql $DB +update ignore egw_cal_user set cal_id=$ID where cal_id in (select cal_id from egw_cal where cal_uid='$UUID' and cal_reference<>0 and cal_recurrence=$RECURRENCE); +delete from egw_cal_user where cal_id<>$ID AND cal_id in (select cal_id from egw_cal where cal_uid='$UUID' and cal_reference<>0 and cal_recurrence=$RECURRENCE); +delete from egw_cal_dates where cal_id<>$ID AND cal_id in (select cal_id from egw_cal where cal_uid='$UUID' and cal_reference<>0 and cal_recurrence=$RECURRENCE); +delete from egw_cal where cal_id<>$ID AND cal_id in (select cal_id from egw_cal where cal_uid='$UUID' and cal_reference<>0 and cal_recurrence=$RECURRENCE); +EOF +done \ No newline at end of file