Don't use iconv with ruby1.9 (#12787).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11440 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2013-02-18 21:39:17 +00:00
parent b0de1b1908
commit 59c704dcd2
2 changed files with 16 additions and 16 deletions

View File

@ -18,7 +18,7 @@
desc 'Mantis migration script' desc 'Mantis migration script'
require 'active_record' require 'active_record'
require 'iconv' require 'iconv' if RUBY_VERSION < '1.9'
require 'pp' require 'pp'
namespace :redmine do namespace :redmine do
@ -440,9 +440,7 @@ task :migrate_from_mantis => :environment do
end end
def self.encoding(charset) def self.encoding(charset)
@ic = Iconv.new('UTF-8', charset) @charset = charset
rescue Iconv::InvalidEncoding
return false
end end
def self.establish_connection(params) def self.establish_connection(params)
@ -454,9 +452,12 @@ task :migrate_from_mantis => :environment do
end end
def self.encode(text) def self.encode(text)
@ic.iconv text if RUBY_VERSION < '1.9'
rescue @ic ||= Iconv.new('UTF-8', @charset)
text @ic.iconv text
else
text.to_s.force_encoding(@charset).encode('UTF-8')
end
end end
end end

View File

@ -16,7 +16,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require 'active_record' require 'active_record'
require 'iconv' require 'iconv' if RUBY_VERSION < '1.9'
require 'pp' require 'pp'
namespace :redmine do namespace :redmine do
@ -603,10 +603,7 @@ namespace :redmine do
end end
def self.encoding(charset) def self.encoding(charset)
@ic = Iconv.new('UTF-8', charset) @charset = charset
rescue Iconv::InvalidEncoding
puts "Invalid encoding!"
return false
end end
def self.set_trac_directory(path) def self.set_trac_directory(path)
@ -713,11 +710,13 @@ namespace :redmine do
end end
end end
private
def self.encode(text) def self.encode(text)
@ic.iconv text if RUBY_VERSION < '1.9'
rescue @ic ||= Iconv.new('UTF-8', @charset)
text @ic.iconv text
else
text.to_s.force_encoding(@charset).encode('UTF-8')
end
end end
end end