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:
- 5205 Bytes
- Properties:
- Property svn:executable is set
1 | #!/usr/bin/env ruby |
2 | |
3 | # MovableType 3.x 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 MTMigrate |
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 | mt_categories = ActiveRecord::Base.connection.select_all(%{ |
24 | SELECT category_label AS name |
25 | FROM `#{self.options[:mt_db]}`.mt_category |
26 | WHERE category_blog_id = '#{self.options[:blog_id]}' |
27 | }) |
28 | |
29 | puts "Converting #{mt_categories.size} categories.." |
30 | |
31 | mt_categories.each do |cat| |
32 | Category.create(cat) unless Category.find_by_name(cat['name']) |
33 | end |
34 | end |
35 | |
36 | def convert_entries |
37 | default_filter = translate_filter ActiveRecord::Base.connection.select_all(%{ |
38 | SELECT |
39 | blog_convert_paras |
40 | FROM `#{self.options[:mt_db]}`.mt_blog |
41 | WHERE blog_id = '#{self.options[:blog_id]}' |
42 | })[0]["blog_convert_paras"] |
43 | |
44 | mt_entries = ActiveRecord::Base.connection.select_all(%{ |
45 | SELECT |
46 | entry_id, |
47 | entry_allow_comments AS allow_comments, |
48 | entry_allow_pings AS allow_pings, |
49 | entry_title AS title, |
50 | entry_text AS body, |
51 | entry_text_more AS extended, |
52 | entry_excerpt AS excerpt, |
53 | entry_convert_breaks AS convert_breaks, |
54 | entry_keywords AS keywords, |
55 | entry_created_on AS created_at, |
56 | entry_modified_on AS updated_at, |
57 | author_name AS author |
58 | FROM `#{self.options[:mt_db]}`.mt_entry, `#{self.options[:mt_db]}`.mt_author |
59 | WHERE entry_blog_id = '#{self.options[:blog_id]}' |
60 | AND author_id = entry_author_id |
61 | }) |
62 | |
63 | puts "Converting #{mt_entries.size} entries.." |
64 | |
65 | mt_entries.each do |entry| |
66 | a = Article.new |
67 | a.attributes = entry.reject { |k,v| k =~ /entry_id|convert_breaks/ } |
68 | |
69 | if entry["convert_breaks"] == "__default__" |
70 | a.text_filter = default_filter |
71 | else |
72 | a.text_filter = translate_filter entry["convert_breaks"] |
73 | end |
74 | |
75 | a.save |
76 | |
77 | # Fetch category assignments |
78 | ActiveRecord::Base.connection.select_all(%{ |
79 | SELECT category_label, placement_is_primary |
80 | FROM `#{self.options[:mt_db]}`.mt_category, `#{self.options[:mt_db]}`.mt_entry, `#{self.options[:mt_db]}`.mt_placement |
81 | WHERE entry_id = #{entry['entry_id']} |
82 | AND category_id = placement_category_id |
83 | AND entry_id = placement_entry_id |
84 | }).each do |c| |
85 | a.categories.push_with_attributes(Category.find_by_name(c['category_label']), :is_primary => c['placement_is_primary']) |
86 | end |
87 | |
88 | # Fetch comments |
89 | ActiveRecord::Base.connection.select_all(%{ |
90 | SELECT |
91 | comment_author AS author, |
92 | comment_email AS email, |
93 | comment_url AS url, |
94 | comment_text AS body, |
95 | comment_created_on AS created_at, |
96 | comment_modified_on AS updated_at |
97 | FROM `#{self.options[:mt_db]}`.mt_comment |
98 | WHERE comment_entry_id = #{entry['entry_id']} |
99 | }).each do |c| |
100 | a.comments.create(c) |
101 | end |
102 | |
103 | # Fetch trackbacks |
104 | ActiveRecord::Base.connection.select_all(%{ |
105 | SELECT |
106 | tbping_title AS title, |
107 | tbping_excerpt AS excerpt, |
108 | tbping_source_url AS url, |
109 | tbping_ip AS ip, |
110 | tbping_blog_name AS blog_name, |
111 | tbping_created_on AS created_at, |
112 | tbping_modified_on AS updated_at |
113 | FROM `#{self.options[:mt_db]}`.mt_tbping, `#{self.options[:mt_db]}`.mt_trackback |
114 | WHERE tbping_tb_id = trackback_id |
115 | AND trackback_entry_id = #{entry['entry_id']} |
116 | }).each do |tb| |
117 | a.trackbacks.create(tb) |
118 | end |
119 | end |
120 | end |
121 | |
122 | def convert_prefs |
123 | puts "Converting prefs" |
124 | |
125 | ActiveRecord::Base.connection.select_one(%{ |
126 | SELECT |
127 | blog_name, |
128 | blog_allow_comments_default AS default_allow_comments, |
129 | blog_allow_pings_default AS default_allow_pings |
130 | FROM `#{self.options[:mt_db]}`.mt_blog |
131 | WHERE blog_id = '#{self.options[:blog_id]}' |
132 | }).each do |pref_name, pref_value| |
133 | begin |
134 | Setting.find_by_name(pref_name).update_attribute("value", pref_value) |
135 | rescue |
136 | Setting.create({'name' => pref_name, 'value' => pref_value}) |
137 | end |
138 | end |
139 | |
140 | end |
141 | |
142 | def parse_options |
143 | OptionParser.new do |opt| |
144 | opt.banner = "Usage: mt3.rb [options]" |
145 | |
146 | opt.on('--blog-id BLOGID', Integer, 'Blog ID to import from.') { |i| self.options[:blog_id] = i } |
147 | opt.on('--db DBNAME', String, 'Movable Type database name.') { |d| self.options[:mt_db] = d } |
148 | |
149 | opt.on_tail('-h', '--help', 'Show this message.') do |
150 | puts opt |
151 | exit |
152 | end |
153 | |
154 | opt.parse!(ARGV) |
155 | end |
156 | |
157 | unless self.options.include?(:blog_id) and self.options.include?(:mt_db) |
158 | puts "See mt3.rb --help for help." |
159 | exit |
160 | end |
161 | end |
162 | |
163 | def translate_filter(input) |
164 | return case input |
165 | when /textile/: 'textile' |
166 | when /markdown/ : 'markdown' |
167 | else nil |
168 | end |
169 | end |
170 | end |
171 | |
172 | MTMigrate.new |