From 39671a357fcc410687ceeeb27ae51e0a926cd5ec Mon Sep 17 00:00:00 2001 From: hukl Date: Tue, 7 Apr 2009 21:54:49 +0200 Subject: adding the new chaos_importer.rb to the setup_environment task. removed libxml-ruby dependency --- lib/chaos_importer.rb | 25 ++++++++----------------- lib/tasks/development_init.rake | 31 ++++++++++--------------------- 2 files changed, 18 insertions(+), 38 deletions(-) diff --git a/lib/chaos_importer.rb b/lib/chaos_importer.rb index f8e98f5..74e0bbe 100644 --- a/lib/chaos_importer.rb +++ b/lib/chaos_importer.rb @@ -73,7 +73,9 @@ class ChaosImporter puts node.unique_name end + puts ">> Publishing Drafts" Node.all.each {|node| node.publish_draft!} + puts ">> Finished" end def lang_from_path path @@ -90,20 +92,13 @@ class ChaosImporter end def find_or_create_author update - # login = update.xml.at("//author").content rescue "webmaster" - # puts login - - # password = Digest::SHA1.hexdigest("#{Time.now+rand(100).days}") - # unless author = User.find_by_login(login) - # author = User.create!( - # :login => login, - # :email => "#{login}@example.com", - # :password => password, - # :password_confirmation => password - # ) - # end + login = update.xml.at("//author").content rescue "webmaster" + + unless author = User.find_by_login(login.downcase) + author = User.find_by_login("webmaster") + end - # author + author end def find_or_create_node update @@ -136,10 +131,6 @@ class ChaosImporter :body => extract_body(html) } - if draft.node.slug == "wahlcomputer-hessen" - puts "#{I18n.locale} >>> #{lang} >>> #{options[:title]}" - end - draft.update_attributes options draft end diff --git a/lib/tasks/development_init.rake b/lib/tasks/development_init.rake index 789cdf6..00ef83a 100644 --- a/lib/tasks/development_init.rake +++ b/lib/tasks/development_init.rake @@ -3,7 +3,12 @@ require 'csv' namespace :cccms do desc "Setup everythin" - task :setup_environment => [:create_admin_user, :import_updates, :create_home_page] do |t| + task :setup_environment => [ + :create_admin_user, + :import_authors, + :import_updates, + :create_home_page + ] do |t| end @@ -19,30 +24,14 @@ namespace :cccms do desc "Import the authors" task :import_authors => :environment do |t| - I18n.locale = :en - @parsed_file = CSV::Reader.parse(File.open("#{RAILS_ROOT}/db/authors.csv")) - - @parsed_file.each_with_index do |row, index| - next if row[0].nil? - - unless author = User.find_by_login(row[0]) - puts "#{row[0]} >> #{row[2]}" - author = User.create!( - :login => row[0], - #:realname => row[1], - :email => row[2], - :password => "foobartrallala", - :password_confirmation => "foobartrallala" - ) - end - - end + importer = AuthorsImporter.new("#{RAILS_ROOT}/db/authors.csv") + importer.import_authors end desc "Import the old XML Files" task :import_updates => :environment do |t| - i = UpdateImporter.new("#{RAILS_ROOT}/db/updates") - i.import_xml + i = ChaosImporter.new("#{RAILS_ROOT}/db/updates") + i.import_updates end desc "Create Home Page" -- cgit v1.3