From 9267725c9fff931daed3fdcb2a6b169fb5269c77 Mon Sep 17 00:00:00 2001 From: Didier Lafforgue Date: Wed, 18 Apr 2012 14:35:06 +0200 Subject: [PATCH] clean the upgrade script (v1 -> v2) --- script/upgrade.rb | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/script/upgrade.rb b/script/upgrade.rb index 4de49680..5bed8e39 100755 --- a/script/upgrade.rb +++ b/script/upgrade.rb @@ -5,17 +5,6 @@ rescue LoadError puts 'You must `gem install bundler` and `bundle install` to run rake tasks' end -Locomotive::Page.each do |page| - page.editable_elements.each_with_index do |el, index| - next if el._type != 'Locomotive::EditableFile' || el.attributes['source'].is_a?(Hash) - - value = el.attributes['source'] - - page.collection.update({ '_id' => page._id }, { '$set' => { "editable_elements.#{index}.source" => { 'en' => value } } }) - end -end - - # ================ GLOBAL VARIABLES ============== $database = 'locomotive_hosting_production' @@ -24,12 +13,12 @@ $default_locale = 'en' # $locale_exceptions = {} # Example: -$locale_exceptions = { - '4c082a9393d4330812000002' => 'fr', - '4c2330706f40d50ae2000005' => 'fr', - '4dc07643d800a53aea00035a' => 'fr', - '4eb6aca89a976a0001000ebb' => 'fr' -} +# $locale_exceptions = { +# '4c082a9393d4330812000002' => 'fr', +# '4c2330706f40d50ae2000005' => 'fr', +# '4dc07643d800a53aea00035a' => 'fr', +# '4eb6aca89a976a0001000ebb' => 'fr' +# } def get_locale(site_id) $locale_exceptions[site_id.to_s] || $default_locale @@ -42,8 +31,18 @@ require 'mongoid' Mongoid.configure do |config| name = $database host = 'localhost' - config.master = Mongo::Connection.new.db(name) + + # simple connection + # config.master = Mongo::Connection.new.db(name) + + # a more complicated connection # config.master = Mongo::Connection.new('localhost', '27017', :logger => Logger.new($stdout)).db(name) + + # connection with authentication + # db = config.master = Mongo::Connection.new(host, '27019').db(name) + # db.authenticate('username', 'password').tap do |auth| + # puts auth.inspect + # end end db = Mongoid.config.master @@ -305,6 +304,17 @@ if collection = db.collections.detect { |c| c.name == 'pages' } modifications["editable_elements.#{index}.source"] = { locale => editable_element['source_filename'] } removals["editable_elements.#{index}.source_filename"] = '1' end + + # FIXME: do not remember why I needed to run this code. + # Locomotive::Page.each do |page| + # page.editable_elements.each_with_index do |el, index| + # next if el._type != 'Locomotive::EditableFile' || el.attributes['source'].is_a?(Hash) + # + # value = el.attributes['source'] + # + # page.collection.update({ '_id' => page._id }, { '$set' => { "editable_elements.#{index}.source" => { 'en' => value } } }) + # end + # end end if page['depth'] == 0 && page['fullpath'] == '404'