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:
- 6324 Bytes
- Properties:
- Property svn:executable is set
1 | #!/usr/bin/env ruby |
2 | |
3 | # WordPress 1.5x converter for typo by Patrick Lenz <patrick@lenz.sh> |
4 | # |
5 | # MAKE BACKUPS OF EVERYTHING BEFORE RUNNING THIS SCRIPT! |
6 | # THIS SCRIPT IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND |
7 | |
8 | require File.dirname(__FILE__) + '/../../config/environment' |
9 | require 'optparse' |
10 | |
11 | class WPMigrate |
12 | attr_accessor :options |
13 | |
14 | def initialize |
15 | self.options = {} |
16 | self.parse_options |
17 | self.convert_categories |
18 | self.convert_entries |
19 | self.convert_prefs |
20 | end |
21 | |
22 | def convert_categories |
23 | wp_categories = ActiveRecord::Base.connection.select_all(%{ |
24 | SELECT cat_name AS name |
25 | FROM `#{self.options[:wp_db]}`.`#{self.options[:wp_prefix]}_categories` |
26 | }) |
27 | |
28 | puts "Converting #{wp_categories.size} categories.." |
29 | |
30 | wp_categories.each do |cat| |
31 | Category.create(cat) unless Category.find_by_name(cat['name']) |
32 | end |
33 | end |
34 | |
35 | def convert_entries |
36 | wp_entries = ActiveRecord::Base.connection.select_all(%{ |
37 | SELECT |
38 | `#{self.options[:wp_prefix]}_posts`.ID, |
39 | (CASE comment_status WHEN 'closed' THEN '0' ELSE '1' END) AS allow_comments, |
40 | (CASE ping_status WHEN 'closed' THEN '0' ELSE '1' END) AS allow_pings, |
41 | post_title AS title, |
42 | post_content AS body, |
43 | post_excerpt AS excerpt, |
44 | post_date AS created_at, |
45 | post_modified AS updated_at, |
46 | (CASE LENGTH(user_nickname) WHEN '0' THEN user_login ELSE user_nickname END) AS author, |
47 | (CASE post_status WHEN 'publish' THEN '1' ELSE '0' END) AS published, |
48 | post_category |
49 | FROM `#{self.options[:wp_db]}`.`#{self.options[:wp_prefix]}_posts`, `#{self.options[:wp_db]}`.`#{self.options[:wp_prefix]}_users` |
50 | WHERE `#{self.options[:wp_prefix]}_users`.ID = `#{self.options[:wp_prefix]}_posts`.post_author |
51 | }) |
52 | |
53 | puts "Converting #{wp_entries.size} entries.." |
54 | |
55 | wp_entries.each do |entry| |
56 | a = Article.new |
57 | a.attributes = entry.reject { |k,v| k =~ /^(ID|post_category|body)/ } |
58 | a.text_filter = self.options[:text_filter] |
59 | body = entry['body'] |
60 | more_index = body.index('<!--more-->') |
61 | if more_index |
62 | a.body = body[0...more_index] |
63 | a.extended = body[more_index+11...body.length] |
64 | else |
65 | a.body = body |
66 | end |
67 | a.save |
68 | |
69 | # Assign primary category |
70 | unless entry['post_category'].to_i.zero? |
71 | puts "Assign primary category for entry #{entry['ID']}" |
72 | |
73 | ActiveRecord::Base.connection.select_all(%{ |
74 | SELECT cat_name |
75 | FROM `#{self.options[:wp_db]}`.`#{self.options[:wp_prefix]}_categories` |
76 | WHERE cat_ID = '#{entry['post_category']}' |
77 | }).each do |c| |
78 | a.categories.push_with_attributes(Category.find_by_name(c['cat_name']), :is_primary => 1) rescue nil |
79 | end |
80 | end |
81 | |
82 | # Fetch category assignments |
83 | puts "Assign remaining categories for entry #{entry['ID']}" |
84 | ActiveRecord::Base.connection.select_all(%{ |
85 | SELECT cat_name |
86 | FROM `#{self.options[:wp_db]}`.`#{self.options[:wp_prefix]}_categories`, `#{self.options[:wp_db]}`.`#{self.options[:wp_prefix]}_post2cat` |
87 | WHERE post_id = #{entry['ID']} |
88 | AND `#{self.options[:wp_prefix]}_post2cat`.category_id = `#{self.options[:wp_prefix]}_categories`.cat_ID |
89 | }).each do |c| |
90 | a.categories.push_with_attributes(Category.find_by_name(c['cat_name']), :is_primary => 0) |
91 | end |
92 | |
93 | # Fetch comments |
94 | ActiveRecord::Base.connection.select_all(%{ |
95 | SELECT |
96 | comment_author AS author, |
97 | comment_author_email AS email, |
98 | comment_author_url AS url, |
99 | comment_content AS body, |
100 | comment_date AS created_at, |
101 | comment_author_IP AS ip |
102 | FROM `#{self.options[:wp_db]}`.`#{self.options[:wp_prefix]}_comments` |
103 | WHERE comment_post_ID = #{entry['ID']} |
104 | AND comment_type != 'trackback' |
105 | AND comment_approved = '1' |
106 | }).each do |c| |
107 | a.comments.create(c) |
108 | end |
109 | |
110 | # Fetch trackbacks |
111 | ActiveRecord::Base.connection.select_all(%{ |
112 | SELECT |
113 | comment_author AS blog_name, |
114 | comment_author_url AS url, |
115 | comment_content AS excerpt, |
116 | comment_date AS created_at, |
117 | comment_author_IP AS ip |
118 | FROM `#{self.options[:wp_db]}`.`#{self.options[:wp_prefix]}_comments` |
119 | WHERE comment_post_ID = #{entry['ID']} |
120 | AND comment_type = 'trackback' |
121 | AND comment_approved = '1' |
122 | }).each do |c| |
123 | c['title'] = c['excerpt'].match("<(strong)>(.+?)</\\1>")[2] rescue c['blog_name'] |
124 | a.trackbacks.create(c) |
125 | end |
126 | |
127 | end |
128 | end |
129 | |
130 | def convert_prefs |
131 | puts "Converting prefs" |
132 | |
133 | ActiveRecord::Base.connection.select_all(%{ |
134 | SELECT |
135 | (CASE option_name |
136 | WHEN 'blogname' THEN 'blog_name' |
137 | WHEN 'default_comment_status' THEN 'default_allow_comments' |
138 | WHEN 'default_ping_status' THEN 'default_allow_pings' |
139 | END) AS name, |
140 | option_value AS value |
141 | FROM `#{self.options[:wp_db]}`.`#{self.options[:wp_prefix]}_options` |
142 | WHERE option_name IN ('blogname', 'default_comment_status', 'default_ping_status') |
143 | }).each do |pref| |
144 | if pref['name'] =~ /^default_allow/ |
145 | pref['value'] = (pref['value'] == "open" ? 1 : 0) |
146 | end |
147 | |
148 | begin |
149 | Setting.find_by_name(pref['name']).update_attribute("value", pref['value']) |
150 | rescue |
151 | Setting.create(pref) |
152 | end |
153 | end |
154 | end |
155 | |
156 | def parse_options |
157 | OptionParser.new do |opt| |
158 | opt.banner = "Usage: wordpress.rb [options]" |
159 | |
160 | opt.on('--db DBNAME', String, 'WordPress database name.') { |d| self.options[:wp_db] = d } |
161 | opt.on('--prefix PREFIX', String, 'WordPress table prefix (defaults to \'wp\').') { |d| self.options[:wp_prefix] = d } |
162 | opt.on('--filter TEXTFILTER', String, 'Textfilter for imported articles (defaults to markdown).') { |d| self.options[:text_filter] = d } |
163 | |
164 | opt.on_tail('-h', '--help', 'Show this message.') do |
165 | puts opt |
166 | exit |
167 | end |
168 | |
169 | opt.parse!(ARGV) |
170 | end |
171 | |
172 | unless self.options.include?(:wp_db) |
173 | puts "See wordpress.rb --help for help." |
174 | exit |
175 | end |
176 | |
177 | unless self.options.include?(:wp_prefix) |
178 | self.options[:wp_prefix] = "wp" |
179 | end |
180 | |
181 | unless self.options.include?(:text_filter) |
182 | self.options[:text_filter] = 'markdown' |
183 | end |
184 | end |
185 | end |
186 | |
187 | WPMigrate.new |