mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-17 11:54:22 +01:00
[bug] recursive_events_over_DST fail with deleted events
This commit is contained in:
parent
c7b88c29b2
commit
de6ea6ff14
@ -60,11 +60,12 @@ namespace :fablab do
|
|||||||
|
|
||||||
task recursive_events_over_DST: :environment do
|
task recursive_events_over_DST: :environment do
|
||||||
include ApplicationHelper
|
include ApplicationHelper
|
||||||
|
failed_ids = []
|
||||||
groups = Event.group(:recurrence_id).count
|
groups = Event.group(:recurrence_id).count
|
||||||
groups.keys.each do |recurrent_event_id|
|
groups.keys.each do |recurrent_event_id|
|
||||||
if recurrent_event_id
|
if recurrent_event_id
|
||||||
initial_event = Event.find(recurrent_event_id)
|
begin
|
||||||
if initial_event
|
initial_event = Event.find(recurrent_event_id)
|
||||||
Event.where(recurrence_id: recurrent_event_id).where.not(id: recurrent_event_id).each do |event|
|
Event.where(recurrence_id: recurrent_event_id).where.not(id: recurrent_event_id).each do |event|
|
||||||
availability = event.availability
|
availability = event.availability
|
||||||
if initial_event.availability.start_at.hour != availability.start_at.hour
|
if initial_event.availability.start_at.hour != availability.start_at.hour
|
||||||
@ -73,11 +74,16 @@ namespace :fablab do
|
|||||||
availability.save!
|
availability.save!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
rescue ActiveRecord::RecordNotFound
|
||||||
puts "Error: The initial event (id: #{recurrent_event_id}) of the recurrence was not found. You may have to correct events manually"
|
failed_ids.push recurrent_event_id
|
||||||
end
|
end
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user