Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 7
- Log:
Initial import of RForum 0.2 sources from a downloaded Tarball.
RForum is a Ruby On Rails based forum and mail gateway service.
- Author:
- adh
- Date:
- Sat Jul 22 18:43:13 +0100 2006
- Size:
- 2200 Bytes
- Properties:
- Property svn:executable is set
1 | #!/usr/bin/env ruby |
2 | |
3 | # Script for importing posts from the mikrocontroller.net forum |
4 | |
5 | require 'time' |
6 | require 'rubygems' |
7 | require 'config/environment' |
8 | require 'mysql' |
9 | |
10 | class Post |
11 | def validate |
12 | true |
13 | end |
14 | end |
15 | |
16 | class String |
17 | def to_utf8 |
18 | Iconv.iconv('utf-8', 'iso-8859-1', self)[0] |
19 | end |
20 | end |
21 | |
22 | Post.delete_all |
23 | Topic.delete_all |
24 | Forum.delete_all |
25 | TopicRead.delete_all |
26 | TopicSubscription.delete_all |
27 | |
28 | Post.indexing_disabled = true |
29 | |
30 | dbh = Mysql.connect(nil, ARGV[0], ARGV[1], 'oldforum') |
31 | res = dbh.query 'SELECT * FROM forums' |
32 | res.each_hash do |of| |
33 | puts "Importing forum ##{of['id']}" |
34 | f = Forum.new |
35 | f.name = of['name'].to_utf8 |
36 | f.description = of['description'].to_utf8 |
37 | f.save |
38 | |
39 | res = dbh.query "SELECT posts.*, bodies.content |
40 | FROM posts |
41 | LEFT JOIN bodies |
42 | ON posts.id = bodies.id |
43 | WHERE posts.id = posts.topic_id |
44 | AND forum_id=#{of['id']} |
45 | ORDER BY posts.id DESC |
46 | LIMIT 100" |
47 | res.each_hash do |ot| |
48 | begin |
49 | puts "Importing thread ##{ot['id']}" |
50 | puts "Importing post ##{ot['id']}" |
51 | t = Post.new |
52 | t.guest_name = ot['authorname'].to_utf8 |
53 | t.guest_email = ot['authormail'].to_utf8 |
54 | t.subject = ot['subject'].to_utf8 |
55 | t.text = Wraptools.wrap_ff(ot['content'], 78).to_utf8 |
56 | t.created_at = Time.parse(ot['created_at']) |
57 | f.add_post(t) |
58 | rescue => e |
59 | puts e.inspect |
60 | next |
61 | end |
62 | |
63 | res = dbh.query "SELECT posts.*, bodies.content |
64 | FROM posts |
65 | LEFT JOIN bodies |
66 | ON posts.id = bodies.id |
67 | WHERE posts.id <> posts.topic_id |
68 | AND topic_id=#{ot['id']}" |
69 | |
70 | res.each_hash do |op| |
71 | begin |
72 | puts "Importing post ##{op['id']}" |
73 | p = Post.new |
74 | p.guest_name = op['authorname'].to_utf8 |
75 | p.guest_email = op['authormail'].to_utf8 |
76 | p.subject = op['subject'].to_utf8 |
77 | p.text = Wraptools.wrap_ff(op['content'], 78).to_utf8 |
78 | p.created_at = Time.parse(op['created_at']) |
79 | t.add_reply(p) |
80 | rescue => e |
81 | puts e.inspect |
82 | end |
83 | end |
84 | end |
85 | end |
86 | |
87 | dbh.close |
88 | |
89 | Post.rebuild_index |