forked from aksdb/CalAnonSync
Added option to rebuild the complete calendar
This commit is contained in:
parent
8d8cc94213
commit
73a7754742
|
@ -8,12 +8,17 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
var syncSettings = struct {
|
||||
rebuild bool
|
||||
}{}
|
||||
|
||||
func main() {
|
||||
rootCmd := &cobra.Command{
|
||||
Use: "calanonsync",
|
||||
Short: "Synchronize a calendar from EWS to CalDAV by event time and an anonymized title only.",
|
||||
Run: runSynchronization,
|
||||
}
|
||||
rootCmd.Flags().BoolVar(&syncSettings.rebuild, "rebuild", false, "Rebuild all calendar items, no matter if they already exist.")
|
||||
|
||||
rootCmd.AddCommand(InitSettingsCmd())
|
||||
|
||||
|
@ -66,6 +71,13 @@ func runSynchronization(cmd *cobra.Command, args []string) {
|
|||
for uid, calDavItem := range calDavItemMap {
|
||||
if ewsItem, ok := relevantEWSItems[uid]; ok {
|
||||
// Good, so we still know the item at least.
|
||||
|
||||
// If we want a full rebuild, we can skip this step
|
||||
// since we will create new items anyway.
|
||||
if syncSettings.rebuild {
|
||||
continue
|
||||
}
|
||||
|
||||
if !ewsItem.Start.Equal(calDavItem.Start()) ||
|
||||
!ewsItem.End.Equal(calDavItem.End()) {
|
||||
|
||||
|
@ -92,9 +104,9 @@ func runSynchronization(cmd *cobra.Command, args []string) {
|
|||
}
|
||||
}
|
||||
|
||||
// Find items we don't know so far and create them.
|
||||
// Find items we don't know so far and create them. Also recreate them if we want to rebuild all.
|
||||
for uid, ewsItem := range relevantEWSItems {
|
||||
if _, ok := calDavItemMap[uid]; !ok {
|
||||
if _, ok := calDavItemMap[uid]; !ok || syncSettings.rebuild {
|
||||
title := s.Anonymize.Title.Apply(ewsItem.Subject)
|
||||
ical := CreateICal(ewsItem.Hash(), title, ewsItem.Start, ewsItem.End, ewsItem.IsAllDayEvent)
|
||||
calDavItem := CalDAVItem{HRef: uid + ".ics", ICal: ical}
|
||||
|
|
Loading…
Reference in New Issue