From de6ea6ff14cbc30c3b54b27a1cfb9d4a9c3be684 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Mon, 11 Sep 2017 16:32:33 +0200 Subject: [PATCH] [bug] recursive_events_over_DST fail with deleted events --- lib/tasks/fablab/fix.rake | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/tasks/fablab/fix.rake b/lib/tasks/fablab/fix.rake index ef358a502..4b66e78aa 100644 --- a/lib/tasks/fablab/fix.rake +++ b/lib/tasks/fablab/fix.rake @@ -60,11 +60,12 @@ namespace :fablab do task recursive_events_over_DST: :environment do include ApplicationHelper + failed_ids = [] groups = Event.group(:recurrence_id).count groups.keys.each do |recurrent_event_id| if recurrent_event_id - initial_event = Event.find(recurrent_event_id) - if initial_event + begin + initial_event = Event.find(recurrent_event_id) Event.where(recurrence_id: recurrent_event_id).where.not(id: recurrent_event_id).each do |event| availability = event.availability if initial_event.availability.start_at.hour != availability.start_at.hour @@ -73,11 +74,16 @@ namespace :fablab do availability.save! end end - else - puts "Error: The initial event (id: #{recurrent_event_id}) of the recurrence was not found. You may have to correct events manually" + rescue ActiveRecord::RecordNotFound + failed_ids.push recurrent_event_id end end end + + if failed_ids.size > 0 + puts "WARNING: The events with IDs #{failed_ids} were not found.\n These were initial events of a recurrence.\n\n You may have to correct the following events manually (IDs): " + puts "#{Events.where(recurrence_id: failed_ids).map(&:id)}" + end end end end