From bde2ee3d7d6b1f4c0d4cb66732a575c2a99f0e4c Mon Sep 17 00:00:00 2001 From: Ana Date: Mon, 15 Aug 2016 20:31:23 +0200 Subject: [PATCH] Delete Eventschedules out of conference hours --- app/controllers/admin/conferences_controller.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/controllers/admin/conferences_controller.rb b/app/controllers/admin/conferences_controller.rb index e4309b7a..84f92838 100644 --- a/app/controllers/admin/conferences_controller.rb +++ b/app/controllers/admin/conferences_controller.rb @@ -82,6 +82,7 @@ module Admin short_title = @conference.short_title @conference.assign_attributes(conference_params) send_mail_on_conf_update = @conference.notify_on_dates_changed? + delete_event_schedules if @conference.start_hour_changed? || @conference.end_hour_changed? if @conference.update_attributes(conference_params) ConferenceDateUpdateMailJob.perform_later(@conference) if send_mail_on_conf_update @@ -188,5 +189,14 @@ module Admin :targets, :targets_attributes, :campaigns, :campaigns_attributes, :registration_limit) end + + def delete_event_schedules + event_schedules = EventSchedule.select do |e| + e.start_time.strftime('%H').to_i < @conference.start_hour || + e.end_time.strftime('%H').to_i > @conference.end_hour || + (e.end_time.strftime('%H').to_i == @conference.end_hour && e.end_time.strftime('%M').to_i > 0) + end + event_schedules.each(&:destroy) + end end end