Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 15
- Log:
Attempt to update Typo to a Typo SVN HEAD release from around the
time the prototype installation was set up on the RISC OS Open Limited
web site. Timestamps place this at 04-Jul so a revision from 05-Jul or
earlier was pulled and copied over the 2.6.0 tarball stable code.
- Author:
- adh
- Date:
- Sat Jul 22 23:27:35 +0100 2006
- Size:
- 5147 Bytes
- Properties:
- Property svn:executable is set
1 | #!/usr/bin/env ruby |
2 | |
3 | # Serendipity (S9Y) 0.8.x converter for typo by Jochen Schalanda <jochen@schalanda.de> |
4 | # heavily based on the Wordpress 1.5x converter by Patrick Lenz <patrick@lenz.sh> |
5 | # |
6 | # MAKE BACKUPS OF EVERYTHING BEFORE RUNNING THIS SCRIPT! |
7 | # THIS SCRIPT IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND |
8 | # |
9 | # |
10 | # SECURITY NOTICE: |
11 | # |
12 | # Migrated users will have the default password "password", since the |
13 | # MD5 hashes of S9Y cannot be converted to salted SHA1 hashes which are |
14 | # used by Typo. |
15 | # |
16 | |
17 | require File.dirname(__FILE__) + '/../../config/environment' |
18 | require 'optparse' |
19 | |
20 | class S9YMigrate |
21 | attr_accessor :options |
22 | |
23 | def initialize |
24 | self.options = {} |
25 | self.parse_options |
26 | self.convert_users |
27 | self.convert_categories |
28 | self.convert_entries |
29 | self.convert_prefs |
30 | end |
31 | |
32 | def convert_categories |
33 | s9y_categories = ActiveRecord::Base.connection.select_all(%{ |
34 | SELECT category_name AS name |
35 | FROM `#{self.options[:s9y_db]}`.`#{self.options[:s9y_prefix]}category` |
36 | }) |
37 | |
38 | puts "Converting #{s9y_categories.size} categories.." |
39 | |
40 | s9y_categories.each do |cat| |
41 | Category.create(cat) unless Category.find_by_name(cat['name']) |
42 | end |
43 | end |
44 | |
45 | def convert_entries |
46 | s9y_entries = ActiveRecord::Base.connection.select_all(%{ |
47 | SELECT |
48 | id, |
49 | (CASE allow_comments WHEN 'true' THEN '1' ELSE '0' END) AS allow_comments, |
50 | title, |
51 | body, |
52 | extended, |
53 | FROM_UNIXTIME(timestamp) AS created_at, |
54 | FROM_UNIXTIME(last_modified) AS updated_at, |
55 | author, |
56 | authorid AS user_id, |
57 | (CASE isdraft WHEN 'true' THEN '0' ELSE '1' END) AS published |
58 | FROM `#{self.options[:s9y_db]}`.`#{self.options[:s9y_prefix]}entries` |
59 | }) |
60 | |
61 | puts "Converting #{s9y_entries.size} entries.." |
62 | |
63 | s9y_entries.each do |entry| |
64 | a = Article.new |
65 | a.attributes = entry.reject { |k,v| k =~ /^(id)/ } |
66 | a.save |
67 | |
68 | # Fetch category assignments |
69 | ActiveRecord::Base.connection.select_all(%{ |
70 | SELECT category_name |
71 | FROM `#{self.options[:s9y_db]}`.`#{self.options[:s9y_prefix]}category`, `#{self.options[:s9y_db]}`.`#{self.options[:s9y_prefix]}entrycat` |
72 | WHERE entryid = #{entry['id']} |
73 | AND `#{self.options[:s9y_prefix]}entrycat`.categoryid = `#{self.options[:s9y_prefix]}category`.categoryid |
74 | }).each do |c| |
75 | a.categories.push_with_attributes(Category.find_by_name(c['category_name']), :is_primary => 0) |
76 | end |
77 | |
78 | # Fetch comments |
79 | ActiveRecord::Base.connection.select_all(%{ |
80 | SELECT |
81 | author, |
82 | email, |
83 | url, |
84 | body, |
85 | FROM_UNIXTIME(timestamp) AS created_at, |
86 | ip |
87 | FROM `#{self.options[:s9y_db]}`.`#{self.options[:s9y_prefix]}comments` |
88 | WHERE id = #{entry['id']} |
89 | AND type != 'TRACKBACK' |
90 | AND status = 'approved' |
91 | }).each do |c| |
92 | a.comments.create(c) |
93 | end |
94 | |
95 | # Fetch trackbacks |
96 | ActiveRecord::Base.connection.select_all(%{ |
97 | SELECT |
98 | author AS blog_name, |
99 | url, |
100 | title, |
101 | body AS excerpt, |
102 | FROM_UNIXTIME(timestamp) AS created_at, |
103 | ip |
104 | FROM `#{self.options[:s9y_db]}`.`#{self.options[:s9y_prefix]}comments` |
105 | WHERE entry_id = #{entry['id']} |
106 | AND type = 'TRACKBACK' |
107 | AND status = 'approved' |
108 | }).each do |c| |
109 | a.trackbacks.create(c) |
110 | end |
111 | |
112 | end |
113 | end |
114 | |
115 | def convert_prefs |
116 | puts "Converting prefs" |
117 | |
118 | ActiveRecord::Base.connection.select_all(%{ |
119 | SELECT |
120 | (CASE name |
121 | WHEN 'blogTitle' THEN 'blog_name' |
122 | WHEN 'blogDescription' THEN 'blog_subtitle' |
123 | END) AS name, |
124 | value |
125 | FROM `#{self.options[:s9y_db]}`.`#{self.options[:s9y_prefix]}config` |
126 | WHERE name IN ('blogTitle', 'blogDescription') |
127 | }).each do |pref| |
128 | begin |
129 | Setting.find_by_name(pref['name']).update_attribute("value", pref['value']) |
130 | rescue |
131 | Setting.create(pref) |
132 | end |
133 | end |
134 | end |
135 | |
136 | def convert_users |
137 | puts "Converting users" |
138 | puts "** all users will have the default password \"password\" **" |
139 | puts "** you should change it as soon as possible! **" |
140 | |
141 | ActiveRecord::Base.connection.select_all(%{ |
142 | SELECT |
143 | realname AS name, |
144 | username AS login, |
145 | |
146 | FROM `#{self.options[:s9y_db]}`.`#{self.options[:s9y_prefix]}authors` |
147 | }).each do |user| |
148 | u = User.new |
149 | u.attributes = user |
150 | u.password = "password" |
151 | u.save |
152 | end |
153 | end |
154 | |
155 | def parse_options |
156 | OptionParser.new do |opt| |
157 | opt.banner = "Usage: s9y.rb [options]" |
158 | |
159 | opt.on('--db DBNAME', String, 'S9Y database name.') { |d| self.options[:s9y_db] = d } |
160 | opt.on('--prefix PREFIX', String, 'S9Y table prefix (defaults to empty string).') { |d| self.options[:s9y_prefix] = d } |
161 | |
162 | opt.on_tail('-h', '--help', 'Show this message.') do |
163 | puts opt |
164 | exit |
165 | end |
166 | |
167 | opt.parse!(ARGV) |
168 | end |
169 | |
170 | unless self.options.include?(:s9y_db) |
171 | puts "See s9y.rb --help for help." |
172 | exit |
173 | end |
174 | |
175 | unless self.options.include?(:s9y_prefix) |
176 | self.options[:s9y_prefix] = "" |
177 | end |
178 | |
179 | end |
180 | end |
181 | |
182 | S9YMigrate.new |