1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-28 09:24:24 +01:00

[bug] recursive_events_over_DST fail with deleted events

This commit is contained in:
Sylvain 2017-09-11 16:32:33 +02:00
parent c7b88c29b2
commit de6ea6ff14

View File

@ -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