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:
- 4001 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]}`.`#{self.options[:txp_pfx]}`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 | Body_html AS body_html, |
46 | Excerpt AS excerpt, |
47 | Keywords AS keywords, |
48 | Posted AS created_at, |
49 | LastMod AS updated_at, |
50 | AuthorID AS author, |
51 | (CASE textile_body WHEN '1' THEN 'textile' ELSE 'none' END) AS text_filter, |
52 | (CASE Status WHEN '1' THEN '0' ELSE '1' END) AS published, |
53 | Category1, Category2 |
54 | FROM `#{self.options[:txp_db]}`..`#{self.options[:txp_pfx]}`textpattern |
55 | }) |
56 | |
57 | puts "Converting #{txp_entries.size} entries.." |
58 | |
59 | txp_entries.each do |entry| |
60 | a = Article.new |
61 | a.attributes = entry.reject { |k,v| k =~ /^(Category|ID)/ } |
62 | a.save |
63 | |
64 | # Assign categories |
65 | puts "Assign primary category for entry #{entry['ID']}" |
66 | a.categories.push_with_attributes(Category.find_by_name(entry['Category1']), :is_primary => 1) rescue nil |
67 | puts "Assign secondary category for entry #{entry['ID']}" |
68 | a.categories.push_with_attributes(Category.find_by_name(entry['Category2']), :is_primary => 0) rescue nil |
69 | |
70 | # Fetch comments |
71 | ActiveRecord::Base.connection.select_all(%{ |
72 | SELECT |
73 | name AS author, |
74 | email AS email, |
75 | web AS url, |
76 | message AS body, |
77 | message as body_html, |
78 | posted AS created_at, |
79 | ip AS ip |
80 | FROM `#{self.options[:txp_db]}`..`#{self.options[:txp_pfx]}`txp_discuss |
81 | WHERE parentid = #{entry['ID']} |
82 | }).each do |c| |
83 | a.comments.create(c) |
84 | end |
85 | |
86 | end |
87 | end |
88 | |
89 | def convert_prefs |
90 | puts "Converting prefs" |
91 | |
92 | ActiveRecord::Base.connection.select_all(%{ |
93 | SELECT |
94 | (CASE name |
95 | WHEN 'sitename' THEN 'blog_name' |
96 | WHEN 'comments_on_default' THEN 'default_allow_comments' |
97 | WHEN 'use_textile' THEN 'text_filter' |
98 | END) AS name, |
99 | val AS value |
100 | FROM `#{self.options[:txp_db]}`..`#{self.options[:txp_pfx]}`txp_prefs |
101 | WHERE name IN ('sitename', 'comments_on_default', 'use_textile') |
102 | }).each do |pref| |
103 | if pref['name'] == "text_filter" and pref['value'].to_i > 0 |
104 | pref['value'] = 'textile' |
105 | end |
106 | |
107 | begin |
108 | Setting.find_by_name(pref['name']).update_attribute("value", pref['value']) |
109 | rescue |
110 | Setting.create(pref) |
111 | end |
112 | end |
113 | end |
114 | |
115 | def parse_options |
116 | OptionParser.new do |opt| |
117 | opt.banner = "Usage: textpattern.rb [options]" |
118 | |
119 | opt.on('--db DBNAME', String, 'Text Pattern database name.') { |d| self.options[:txp_db] = d } |
120 | opt.on('--pf PREFIX', String, 'Textpattern table prefix.') { |p| self.options[:txp_pfx] = p } |
121 | |
122 | opt.on_tail('-h', '--help', 'Show this message.') do |
123 | puts opt |
124 | exit |
125 | end |
126 | |
127 | opt.parse!(ARGV) |
128 | end |
129 | |
130 | unless self.options.include?(:txp_db) |
131 | puts "See textpattern.rb --help for help." |
132 | exit |
133 | end |
134 | end |
135 | end |
136 | |
137 | TXPMigrate.new |