Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 13
- Log:
Initial import of Typo 2.6.0 sources from a downloaded Tarball.
Typo is a Ruby On Rails based blog engine.
- Author:
- adh
- Date:
- Sat Jul 22 22:25:02 +0100 2006
- Size:
- 3779 Bytes
- Properties:
- Property svn:executable is set
1 | #!/usr/bin/env ruby |
2 | |
3 | # TextPattern 1.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 TXPMigrate |
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 | txp_categories = ActiveRecord::Base.connection.select_all(%{ |
24 | SELECT name |
25 | FROM `#{self.options[:txp_db]}`.txp_category |
26 | WHERE parent = 'root' |
27 | AND type = 'article' |
28 | }) |
29 | |
30 | puts "Converting #{txp_categories.size} categories.." |
31 | |
32 | txp_categories.each do |cat| |
33 | Category.create(cat) unless Category.find_by_name(cat['name']) |
34 | end |
35 | end |
36 | |
37 | def convert_entries |
38 | txp_entries = ActiveRecord::Base.connection.select_all(%{ |
39 | SELECT |
40 | ID, |
41 | Annotate AS allow_comments, |
42 | 1 AS allow_pings, |
43 | Title AS title, |
44 | (CASE LENGTH(Body) WHEN 0 THEN Excerpt ELSE Body END) AS body, |
45 | Excerpt AS excerpt, |
46 | Keywords AS keywords, |
47 | Posted AS created_at, |
48 | LastMod AS updated_at, |
49 | AuthorID AS author, |
50 | (CASE textile_body WHEN '1' THEN 'textile' ELSE 'none' END) AS text_filter, |
51 | (CASE Status WHEN '1' THEN '0' ELSE '1' END) AS published, |
52 | Category1, Category2 |
53 | FROM `#{self.options[:txp_db]}`.textpattern |
54 | }) |
55 | |
56 | puts "Converting #{txp_entries.size} entries.." |
57 | |
58 | txp_entries.each do |entry| |
59 | a = Article.new |
60 | a.attributes = entry.reject { |k,v| k =~ /^(Category|ID)/ } |
61 | a.save |
62 | |
63 | # Assign categories |
64 | puts "Assign primary category for entry #{entry['ID']}" |
65 | a.categories.push_with_attributes(Category.find_by_name(entry['Category1']), :is_primary => 1) rescue nil |
66 | puts "Assign secondary category for entry #{entry['ID']}" |
67 | a.categories.push_with_attributes(Category.find_by_name(entry['Category2']), :is_primary => 0) rescue nil |
68 | |
69 | # Fetch comments |
70 | ActiveRecord::Base.connection.select_all(%{ |
71 | SELECT |
72 | name AS author, |
73 | email AS email, |
74 | web AS url, |
75 | message AS body, |
76 | posted AS created_at, |
77 | ip AS ip |
78 | FROM `#{self.options[:txp_db]}`.txp_discuss |
79 | WHERE parentid = #{entry['ID']} |
80 | }).each do |c| |
81 | a.comments.create(c) |
82 | end |
83 | |
84 | end |
85 | end |
86 | |
87 | def convert_prefs |
88 | puts "Converting prefs" |
89 | |
90 | ActiveRecord::Base.connection.select_all(%{ |
91 | SELECT |
92 | (CASE name |
93 | WHEN 'sitename' THEN 'blog_name' |
94 | WHEN 'comments_on_default' THEN 'default_allow_comments' |
95 | WHEN 'use_textile' THEN 'text_filter' |
96 | END) AS name, |
97 | val AS value |
98 | FROM `#{self.options[:txp_db]}`.txp_prefs |
99 | WHERE name IN ('sitename', 'comments_on_default', 'use_textile') |
100 | }).each do |pref| |
101 | if pref['name'] == "text_filter" and pref['value'].to_i > 0 |
102 | pref['value'] = 'textile' |
103 | end |
104 | |
105 | begin |
106 | Setting.find_by_name(pref['name']).update_attribute("value", pref['value']) |
107 | rescue |
108 | Setting.create(pref) |
109 | end |
110 | end |
111 | end |
112 | |
113 | def parse_options |
114 | OptionParser.new do |opt| |
115 | opt.banner = "Usage: textpattern.rb [options]" |
116 | |
117 | opt.on('--db DBNAME', String, 'Text Pattern database name.') { |d| self.options[:txp_db] = d } |
118 | |
119 | opt.on_tail('-h', '--help', 'Show this message.') do |
120 | puts opt |
121 | exit |
122 | end |
123 | |
124 | opt.parse!(ARGV) |
125 | end |
126 | |
127 | unless self.options.include?(:txp_db) |
128 | puts "See textpattern.rb --help for help." |
129 | exit |
130 | end |
131 | end |
132 | end |
133 | |
134 | TXPMigrate.new |