diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index d1e9102f2..c89277955 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,4 +1,6 @@ 7.4.0 + - fix: old recurring events were not deleted when changing recurrence pattern + - fix: unable to remove recurrence on events diff --git a/lib/WebGUI/Asset/Event.pm b/lib/WebGUI/Asset/Event.pm index e15b70ed2..ca89fd008 100644 --- a/lib/WebGUI/Asset/Event.pm +++ b/lib/WebGUI/Asset/Event.pm @@ -1419,23 +1419,30 @@ sub processPropertiesFromFormPost { if (nfreeze(\%recurrence_new) ne nfreeze(\%recurrence_old)) { # Delete all old events and create new ones my $old_id = $self->get("recurId"); - - # Set the new recurrence pattern - my $new_id = $self->setRecurrence(\%recurrence_new); - return ["There is something wrong with your recurrence pattern."] - unless $new_id; - # Generate the new recurring events - $self->generateRecurringEvents(); + # Set the new recurrence pattern + if (%recurrence_new) { + my $new_id = $self->setRecurrence(\%recurrence_new); + return ["There is something wrong with your recurrence pattern."] + unless $new_id; + + # Generate the new recurring events + $self->generateRecurringEvents(); + } + else { + $self->update({recurId => undef}); + } # Delete old events - my $events = $self->getLineage(["siblings"], { + if ($old_id) { + my $events = $self->getLineage(["siblings"], { returnObjects => 1, includeOnlyClasses => ['WebGUI::Asset::Event'], joinClass => 'WebGUI::Asset::Event', - whereClause => qq{Event.recurId = "$old_id" and Event.recurId <> NULL}, #without the <> NULL, it pulls in the recurId's + whereClause => qq{Event.recurId = "$old_id"}, }); - $_->purge for @$events; + $_->purge for @$events; + } } else { # TODO: Give users a form property to decide what events to update