From cce8f1be9b6550ccd7001afcee58624e553ca3d0 Mon Sep 17 00:00:00 2001 From: chris Date: Sat, 19 Oct 2013 20:20:40 +0800 Subject: [PATCH] Add migration task for ad_banner --- lib/tasks/new_ui.rake | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/tasks/new_ui.rake b/lib/tasks/new_ui.rake index 483785aa..86d5e8d1 100644 --- a/lib/tasks/new_ui.rake +++ b/lib/tasks/new_ui.rake @@ -43,6 +43,10 @@ namespace :new_ui do migrate_ad_images_dates end + task :migrate_ad_banners => :environment do + migrate_ad_banners + end + def migrate_categories(args = nil) if args && args[:app_key] && args[:model_name] migrate_category(args[:app_key], args[:model_name], args[:category_name]) @@ -213,4 +217,19 @@ namespace :new_ui do end end + def migrate_ad_banners + @db ||= Mongoid.database + collection_ad_banner = @db['ad_banners'] + ad_banners = collection_ad_banner.find() + ad_banners.each do |ad_banner| + ad_banner['timeout'] = ad_banner['transition_msec']/1000 if ad_banner['transition_msec'].present? + ad_banner['speed'] = 500 unless ad_banner['speed'].present? + ad_banner['width'], ad_banner['height'] = ad_banner['best_size'].gsub('px', '').delete(' ').split('x').map{|d| d.to_i} if ad_banner['best_size'].present? + ad_banner['ad_fx'] = (AdBanner::FX_TYPES.include?(ad_banner['ad_fx']) ? ad_banner['ad_fx'] : AdBanner::FX_TYPES[0]) + ad_banner.delete('best_size') + ad_banner.delete('transition_msec') + collection_ad_banner.save(ad_banner) + end + end + end