1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
require 'csv'
namespace :cccms do
desc "Setup everythin"
task :setup_environment => [
:create_admin_user,
:import_authors,
:import_updates,
:create_home_page
] do |t|
end
desc "Create admin:foobar user:password"
task :create_admin_user => :environment do |t|
User.create!(
:login => 'admin',
:email => 'admin@cccms.de',
:password => 'foobar',
:password_confirmation => 'foobar',
:admin => true
)
end
desc "Import the authors"
task :import_authors => :environment do |t|
importer = AuthorsImporter.new("#{RAILS_ROOT}/db/authors.csv")
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")
i.import_updates
end
desc "Create Home Page"
task :create_home_page => :environment do |t|
n = Node.create :slug => 'home'
n.move_to_child_of Node.root
d = n.draft
d.title = "Startseite"
d.abstract = "Wilkommen auf der Seite des CCC"
d.body = "Hier gibts content"
d.save
n.publish_draft!
end
desc "Convert Entities to real charactes"
task :convert_entities => :environment do |t|
Page.all.each do |page|
if page.body && page.body != ""
puts ">> #{page.id} -- #{page.node.unique_name if page.node}"
tmp_body = page.body.dup
tmp_body.gsub!(/ä/, "ä")
tmp_body.gsub!(/ö/, "ö")
tmp_body.gsub!(/ü/, "ü")
tmp_body.gsub!(/Ä/, "ä")
tmp_body.gsub!(/Ö/, "ö")
tmp_body.gsub!(/Ü/, "ü")
tmp_body.gsub!(/ß/, "ß")
tmp_body.gsub!(/ /, " ")
tmp_body.gsub!(/–/, "–")
tmp_body.gsub!(/µ/, "µ")
tmp_body.gsub!(/³/, "³")
tmp_body.gsub!(/é/, "é")
tmp_body.gsub!(/§/, "§")
tmp_body.gsub!(/“/, "“")
tmp_body.gsub!(/”/, "”")
tmp_body.gsub!(/„/, "„")
page.body = tmp_body
page.save
end
end
end
desc "Migrate users to editors"
task :migrate_editors => :environment do |t|
Page.record_timestamps = false
Page.before_save.reject! {|filter| filter.method == :rewrite_links_in_body}
Page.all.each do |page|
if page.node.locked?
page.editor = page.node.lock_owner
puts "#{page.id} #{page.node.lock_owner.login}"
else
page.editor = page.user if page.user
end
page.save!
end
end
desc "Repair pages without published_at set"
task :set_published_at => :environment do |t|
unpublished = Page.all(:conditions => {:published_at => nil})
unpublished.each do |p|
p.published_at = p.created_at
p.save!
end
end
desc "Remove pages without a node"
task :remove_orphans => :environment do |t|
orphans = Page.all.select { |x| x.node == nil }
orphans.each { |page| page.destroy }
end
end
|