From 6b936cf82f5357f97aaa909ee4f137b944080ffc Mon Sep 17 00:00:00 2001 From: hukl Date: Sat, 18 Apr 2009 19:52:42 +0200 Subject: added update_authors_on_pages task. run after importing authors --- lib/authors_importer.rb | 16 +--------------- lib/chaos_importer.rb | 19 ++++++++++++++++++- lib/tasks/development_init.rake | 6 ++++++ 3 files changed, 25 insertions(+), 16 deletions(-) (limited to 'lib') diff --git a/lib/authors_importer.rb b/lib/authors_importer.rb index 6195111..08b3be9 100644 --- a/lib/authors_importer.rb +++ b/lib/authors_importer.rb @@ -8,7 +8,7 @@ class AuthorsImporter end def import_authors - parse_csv || find_or_create_user + parse_csv end def parse_csv @@ -26,24 +26,10 @@ class AuthorsImporter find_or_create_user options end - - return true end end def find_or_create_user options = {} - password = generate_password - - # default_options = { - # :login => "webmaster", - # :full_name => "Webmaster", - # :email => "webmaster@ccc.de", - # :password => password, - # :password_confirmation => password - # } - # default_options = {} - # - # options = default_options.merge(options) puts options[:login] unless User.find_by_email(options[:email]) diff --git a/lib/chaos_importer.rb b/lib/chaos_importer.rb index c1ecc7d..cb54093 100644 --- a/lib/chaos_importer.rb +++ b/lib/chaos_importer.rb @@ -49,6 +49,23 @@ class ChaosImporter end end + def update_authors_on_pages + self.each do |update| + author = find_or_create_author( update ) + node = Node.find_by_unique_name( update.unique_name ) || raise("no node") + pages = node.pages.all(:conditions => {:user_id => nil}) + + pages.each do |page| + if page.revision == 1 + page.user = author + page.save + end + end + + puts "#{author.try(:login)} >>> #{node.unique_name}" + end + end + # Uses the each method to loop over the xml files and uses the attrubutes of # the returned ChaosXml objects to do some further processing which is needed # to create proper ActiveRecord records @@ -98,7 +115,7 @@ class ChaosImporter author = User.find_by_login("webmaster") end - author + author end def find_or_create_node update diff --git a/lib/tasks/development_init.rake b/lib/tasks/development_init.rake index 00ef83a..cf97cc3 100644 --- a/lib/tasks/development_init.rake +++ b/lib/tasks/development_init.rake @@ -28,6 +28,12 @@ namespace :cccms do importer.import_authors end + desc "Update authors on pages" + task :update_authors_on_pages => :environment do |t| + i = ChaosImporter.new("#{RAILS_ROOT}/db/updates") + i.update_authors_on_pages + end + desc "Import the old XML Files" task :import_updates => :environment do |t| i = ChaosImporter.new("#{RAILS_ROOT}/db/updates") -- cgit v1.3