50 lines
2.0 KiB
Ruby
50 lines
2.0 KiB
Ruby
#!/usr/bin/env ruby
|
|
ENV['RAILS_ENV'] = 'production'
|
|
require File.dirname(__FILE__) + '/../config/environment'
|
|
|
|
MAX_SIZE = 20000
|
|
[:News,:Advert,:Card,:Company,:Forum,:GroupLink,:GroupPost,:GuestBook,:JobResume,:Job,:Problem,:Solution].each do |model_name|
|
|
puts "#{model_name} | begin_at #{Time.now.to_s(:db)}"
|
|
$stdout.flush
|
|
i = 0
|
|
j = 0
|
|
model = Object.const_get(model_name)
|
|
model.find_in_batches(:batch_size => MAX_SIZE) do |items|
|
|
items.each do |item|
|
|
item.body = item.body.gsub(/javaeye\.com/i,"iteye.com") if item.respond_to?(:body) && item.body =~ /javaeye\.com/i
|
|
item.html_code = item.html_code.gsub(/javaeye\.com/i,"iteye.com") if item.respond_to?(:html_code) && item.html_code =~ /javaeye\.com/i #adverts
|
|
item.description = item.description.gsub(/javaeye\.com/i,"iteye.com") if item.respond_to?(:description) && item.description =~ /javaeye\.com/i
|
|
item.url = item.url.gsub(/javaeye\.com/i,"iteye.com") if (item.respond_to? :url) && (item.instance_of? GroupLink) && (item.url =~ /javaeye\.com/i) #GroupLink
|
|
|
|
|
|
item.remark = item.remark.gsub(/javaeye\.com/i,"iteye.com") if item.respond_to?(:remark) && item.remark =~ /javaeye\.com/i #JobResume
|
|
|
|
#item.name.gsub!(/javaeye/i,"ItEye") if item.instance_of? Company
|
|
#item.short_name.gsub!(/javaeye/i,"ItEye") if item.instance_of? Company
|
|
|
|
if item.changed?
|
|
j += 1
|
|
i += 1 if item.save_without_validation
|
|
end
|
|
end
|
|
puts i if i > 0
|
|
$stdout.flush
|
|
end
|
|
puts "#{model_name} has count #{i}, changed count #{j} | end_at: #{Time.now.to_s(:db)}"
|
|
$stdout.flush
|
|
end
|
|
|
|
puts "Post | begin_at #{Time.now.to_s(:db)}"
|
|
$stdout.flush
|
|
i,j = 0,0
|
|
PostText.find_in_batches(:batch_size => MAX_SIZE) do |items|
|
|
items.each do |item|
|
|
if item.body =~ /javaeye\.com/i
|
|
i += 1
|
|
j += 1 if item.update_attribute(:body, item.body.gsub(/javaeye\.com/i, "iteye.com"))
|
|
Post.expire_cache item.post.id if item.post
|
|
end
|
|
end
|
|
end
|
|
puts "Post has count #{i}, changed count #{j} | end_at: #{Time.now.to_s(:db)}"
|
|
$stdout.flush |