diff options
| author | hukl <contact@smyck.org> | 2009-04-18 19:52:42 +0200 |
|---|---|---|
| committer | hukl <contact@smyck.org> | 2009-04-18 19:52:42 +0200 |
| commit | 6b936cf82f5357f97aaa909ee4f137b944080ffc (patch) | |
| tree | d2a0a6946e87737b0898695bc5a7671f4f301c90 | |
| parent | 1970df667946a8b55ad0ad5bc140b3d9e5515d20 (diff) | |
added update_authors_on_pages task. run after importing authors
| -rw-r--r-- | lib/authors_importer.rb | 16 | ||||
| -rw-r--r-- | lib/chaos_importer.rb | 19 | ||||
| -rw-r--r-- | lib/tasks/development_init.rake | 6 |
3 files changed, 25 insertions, 16 deletions
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 | |||
| 8 | end | 8 | end |
| 9 | 9 | ||
| 10 | def import_authors | 10 | def import_authors |
| 11 | parse_csv || find_or_create_user | 11 | parse_csv |
| 12 | end | 12 | end |
| 13 | 13 | ||
| 14 | def parse_csv | 14 | def parse_csv |
| @@ -26,24 +26,10 @@ class AuthorsImporter | |||
| 26 | 26 | ||
| 27 | find_or_create_user options | 27 | find_or_create_user options |
| 28 | end | 28 | end |
| 29 | |||
| 30 | return true | ||
| 31 | end | 29 | end |
| 32 | end | 30 | end |
| 33 | 31 | ||
| 34 | def find_or_create_user options = {} | 32 | def find_or_create_user options = {} |
| 35 | password = generate_password | ||
| 36 | |||
| 37 | # default_options = { | ||
| 38 | # :login => "webmaster", | ||
| 39 | # :full_name => "Webmaster", | ||
| 40 | # :email => "webmaster@ccc.de", | ||
| 41 | # :password => password, | ||
| 42 | # :password_confirmation => password | ||
| 43 | # } | ||
| 44 | # default_options = {} | ||
| 45 | # | ||
| 46 | # options = default_options.merge(options) | ||
| 47 | puts options[:login] | 33 | puts options[:login] |
| 48 | 34 | ||
| 49 | unless User.find_by_email(options[:email]) | 35 | 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 | |||
| 49 | end | 49 | end |
| 50 | end | 50 | end |
| 51 | 51 | ||
| 52 | def update_authors_on_pages | ||
| 53 | self.each do |update| | ||
| 54 | author = find_or_create_author( update ) | ||
| 55 | node = Node.find_by_unique_name( update.unique_name ) || raise("no node") | ||
| 56 | pages = node.pages.all(:conditions => {:user_id => nil}) | ||
| 57 | |||
| 58 | pages.each do |page| | ||
| 59 | if page.revision == 1 | ||
| 60 | page.user = author | ||
| 61 | page.save | ||
| 62 | end | ||
| 63 | end | ||
| 64 | |||
| 65 | puts "#{author.try(:login)} >>> #{node.unique_name}" | ||
| 66 | end | ||
| 67 | end | ||
| 68 | |||
| 52 | # Uses the each method to loop over the xml files and uses the attrubutes of | 69 | # Uses the each method to loop over the xml files and uses the attrubutes of |
| 53 | # the returned ChaosXml objects to do some further processing which is needed | 70 | # the returned ChaosXml objects to do some further processing which is needed |
| 54 | # to create proper ActiveRecord records | 71 | # to create proper ActiveRecord records |
| @@ -98,7 +115,7 @@ class ChaosImporter | |||
| 98 | author = User.find_by_login("webmaster") | 115 | author = User.find_by_login("webmaster") |
| 99 | end | 116 | end |
| 100 | 117 | ||
| 101 | author | 118 | author |
| 102 | end | 119 | end |
| 103 | 120 | ||
| 104 | def find_or_create_node update | 121 | 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 | |||
| 28 | importer.import_authors | 28 | importer.import_authors |
| 29 | end | 29 | end |
| 30 | 30 | ||
| 31 | desc "Update authors on pages" | ||
| 32 | task :update_authors_on_pages => :environment do |t| | ||
| 33 | i = ChaosImporter.new("#{RAILS_ROOT}/db/updates") | ||
| 34 | i.update_authors_on_pages | ||
| 35 | end | ||
| 36 | |||
| 31 | desc "Import the old XML Files" | 37 | desc "Import the old XML Files" |
| 32 | task :import_updates => :environment do |t| | 38 | task :import_updates => :environment do |t| |
| 33 | i = ChaosImporter.new("#{RAILS_ROOT}/db/updates") | 39 | i = ChaosImporter.new("#{RAILS_ROOT}/db/updates") |
