2016-11-25 16:10:37 +00:00
|
|
|
module Import
|
|
|
|
module Helper
|
|
|
|
# rubocop:disable Style/ModuleFunction
|
|
|
|
extend self
|
|
|
|
|
|
|
|
def check_import_mode
|
|
|
|
# check if system is in import mode
|
|
|
|
return true if Setting.get('import_mode')
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2016-11-25 16:10:37 +00:00
|
|
|
raise 'System is not in import mode!'
|
|
|
|
end
|
|
|
|
|
2017-03-27 13:22:07 +00:00
|
|
|
def check_system_init_done
|
|
|
|
return true if !Setting.get('system_init_done')
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2017-03-27 13:22:07 +00:00
|
|
|
raise 'System is already system_init_done!'
|
|
|
|
end
|
|
|
|
|
2016-11-25 16:10:37 +00:00
|
|
|
def log(message)
|
|
|
|
thread_no = Thread.current[:thread_no] || '-'
|
|
|
|
Rails.logger.info "thread##{thread_no}: #{message}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def utf8_encode(data)
|
2017-10-01 12:25:52 +00:00
|
|
|
data.each do |key, value|
|
2016-11-25 16:10:37 +00:00
|
|
|
next if !value
|
2018-06-01 11:32:59 +00:00
|
|
|
next if !value.respond_to?(:utf8_encode)
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2018-06-01 11:32:59 +00:00
|
|
|
data[key] = value.utf8_encode
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2016-11-25 16:10:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def reset_primary_key_sequence(table)
|
|
|
|
DbHelper.import_post(table)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|