2016-05-04 18:17:50 +02:00
namespace :fablab do
namespace :fix do
task reservations_not_existing_reservable : :environment do
ActiveRecord :: Base . logger = Logger . new ( STDOUT )
ActiveRecord :: Base . connection . execute (
'UPDATE reservations SET reservable_type = NULL, reservable_id = NULL' \
' WHERE NOT EXISTS (SELECT 1 FROM events WHERE events.id = reservations.reservable_id)' \
' AND reservations.reservable_type = \'Event\''
)
end
2016-08-11 11:07:49 +02:00
task assign_category_to_uncategorized_events : :environment do
c = Category . find_or_create_by! ( { name : 'No category' } )
Event . where ( category : nil ) . each do | e |
e . category = c
e . save!
end
end
2017-03-15 12:50:19 +01:00
task rolling_plans : :environment do
Plan . where ( is_rolling : nil ) . each do | p |
if p . is_rolling . nil? and p . is_rolling != false
p . is_rolling = true
p . save!
end
end
end
2017-03-21 15:47:25 +01:00
task new_plans_statistics : :environment do
StatisticSubType . where ( key : nil ) . each do | sst |
p = Plan . find_by ( name : sst . label )
if p
sst . key = p . slug
sst . save!
end
end
end
2017-05-15 15:25:27 +02:00
task new_group_space_prices : :environment do
Space . all . each do | space |
Group . all . each do | group |
begin
Price . find ( priceable : space , group : group )
rescue ActiveRecord :: RecordNotFound
Price . create ( priceable : space , group : group , amount : 0 )
end
end
end
end
2017-08-30 14:57:06 +02:00
task migrate_admins_group : :environment do
admins = Group . find_by ( slug : 'admins' )
User . all . each do | user |
2019-01-14 12:57:31 +01:00
if user . admin?
2017-08-30 14:57:06 +02:00
user . group = admins
user . save!
end
end
end
2017-09-04 17:27:18 +02:00
task recursive_events_over_DST : :environment do
include ApplicationHelper
2017-09-11 16:32:33 +02:00
failed_ids = [ ]
2017-09-04 17:27:18 +02:00
groups = Event . group ( :recurrence_id ) . count
groups . keys . each do | recurrent_event_id |
2017-09-11 10:39:40 +02:00
if recurrent_event_id
2017-09-11 16:32:33 +02:00
begin
initial_event = Event . find ( recurrent_event_id )
2017-09-11 10:39:40 +02:00
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
availability . start_at = dst_correction ( initial_event . availability . start_at , availability . start_at )
availability . end_at = dst_correction ( initial_event . availability . end_at , availability . end_at )
availability . save!
end
end
2017-09-11 16:32:33 +02:00
rescue ActiveRecord :: RecordNotFound
failed_ids . push recurrent_event_id
2017-09-05 10:36:49 +02:00
end
2017-09-04 17:27:18 +02:00
end
end
2017-09-11 16:32:33 +02:00
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): "
2017-09-12 08:39:07 +02:00
puts " #{ Event . where ( recurrence_id : failed_ids ) . map ( & :id ) } "
2017-09-11 16:32:33 +02:00
end
2017-09-04 17:27:18 +02:00
end
2018-07-12 12:48:50 +02:00
desc 'reset slug in events categories'
task categories_slugs : :environment do
Category . all . each do | cat |
2018-09-06 11:22:23 +02:00
` curl -XPOST http:// #{ ENV [ " ELASTICSEARCH_HOST " ] } :9200/stats/event/_update_by_query?conflicts=proceed \\ &refresh \\ &wait_for_completion -d '
2018-07-12 12:48:50 +02:00
{
" script " : {
" source " : " ctx._source.subType = params.slug " ,
" lang " : " painless " ,
" params " : {
" slug " : " #{ cat . slug } "
}
} ,
" query " : {
" term " : {
" subType " : " #{ cat . name } "
}
}
} ' ; `
end
end
2016-05-04 18:17:50 +02:00
end
end