db/migrate/20150519124846_remove_unstandardized_custom_languages.rb
# Redefine all Active Record models, so that the migration doesn't depend on the version of code
Redefine all Active Record models, so that the migration doesn't depend on the version of code
Redefine all Active Record models so that the migration doesn ' t depend on the version of code
def up
    communities = communities_w_unstandard_locales(UNSTANDARD_LANGUAGES)
    puts ""
    puts "-- Removing unstandard locales"
    puts ""
    ActiveRecord::Base.transaction do
      communities.each do |(c, all_unstandard_locales)|
        all_unstandard_locales.each do |unstandard_locale|
          fallback = LANGUAGE_MAP[unstandard_locale]
          if !c.locales.include?(fallback)
            change_locale(community: c, from: unstandard_locale, to: fallback)
            replace_locale_settings(community: c, from: unstandard_locale, to: fallback)
          else
            puts "-- WARNING: Community #{c.ident} has unstandard locale #{unstandard_locale}, but it already has the fallback locale #{fallback}"
            remove_locale_settings(community: c, locale: unstandard_locale)
          end
          puts "Changed locale from: #{unstandard_locale} to: #{fallback} for community: #{c.ident}"
        end
      end
    end
  end
def up communities = communities_w_unstandard_locales ( UNSTANDARD_LANGUAGES ) puts "" puts "-- Removing unstandard locales" puts "" ActiveRecord :: Base . transaction do communities . each do | ( c , all_unstandard_locales ) | all_unstandard_locales . each do | unstandard_locale | fallback = LANGUAGE_MAP [ unstandard_locale ] if ! c . locales . include? ( fallback ) change_locale ( community : c , from : unstandard_locale , to : fallback ) replace_locale_settings ( community : c , from : unstandard_locale , to : fallback ) else puts "-- WARNING: Community #{c.ident} has unstandard locale #{unstandard_locale}, but it already has the fallback locale #{fallback}" remove_locale_settings ( community : c , locale : unstandard_locale ) end puts "Changed locale from: #{unstandard_locale} to: #{fallback} for community: #{c.ident}" end end end end
Redefine all Active Record models, so that the migration doesn't depend on the version of code
Redefine all Active Record models so that the migration doesn ' t depend on the version of code
# Set up the fallback locale (if it's not already there)