engine/script/upgrade_v1.1.rb
Didier Lafforgue da2d689bdc fix issue #412
2012-05-26 14:35:04 +02:00

46 lines
1.2 KiB
Ruby
Executable File

#!/usr/bin/env ruby
begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end
# ================ GLOBAL VARIABLES ==============
$database_name = 'locomotive_engine_dev'
$database_host = 'localhost'
$database_port = '27017'
# $database_username = '<your username>'
# $database_password = '<your password>'
$default_locale = 'en'
$locale_exceptions = {}
# ================ MONGODB ==============
require 'mongoid'
Mongoid.configure do |config|
db = config.master = Mongo::Connection.new($database_host, $database_port).db($database_name)
if $database_username && $database_password
db.authenticate($database_username, $database_password)
end
end
db = Mongoid.config.master
def get_locale(site_id)
$locale_exceptions[site_id.to_s] || $default_locale
end
# locomotive_pages
# localize redirect_url
collection = db.collections.detect { |c| c.name == 'locomotive_pages' }
collection.find.each do |page|
next if !page['redirect'] || page['redirect_url'].is_a?(Hash)
locale = get_locale(page['site_id'])
collection.update({ '_id' => page['_id'] }, { '$set' => { 'redirect_url' => { locale => page['redirect_url'] } } })
end