-
Notifications
You must be signed in to change notification settings - Fork 0
/
removeCDATA.rb
33 lines (27 loc) · 1.06 KB
/
removeCDATA.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env ruby
require 'mysql2' # to install : gem install mysql2
host = 'yourhost.fr'
username = 'forum'
password = 'yourpassword'
database = 'forum'
puts "This script removes CDATA from posts for PhpBB 3.2"
puts "Connecting..."
client = Mysql2::Client.new(:host => host,
:username => username,
:password => password,
:database => database)
puts "Querying, please wait..."
posts = client.query("select * from phpbb_posts")
posts.each do |p|
content = p['post_text']
r = /<!-- .+ -->/ # The regular expression to match CDATA (match HTML comments too)
if r =~ content # regexp match
puts " MATCH: post_id=#{p['post_id']}"
new_content = content.gsub(r,'') # remove the cdata from regular expression
# puts new_content
# escape the quotes if needed (not needed in my case)
new_content = new_content.gsub("'","''")
client.query("update phpbb_posts set post_text='#{new_content}' where post_id=#{p['post_id']}")
puts " #{p['post_id']} updated !"
end
end