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

View File

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