Redmine 4.1.1
This commit is contained in:
parent
33e7b881a5
commit
3d976f1b3b
1593 changed files with 36180 additions and 19489 deletions
|
@ -1,5 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang
|
||||
# Copyright (C) 2006-2019 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
|
@ -31,10 +33,23 @@ class Import < ActiveRecord::Base
|
|||
'%Y-%m-%d',
|
||||
'%d/%m/%Y',
|
||||
'%m/%d/%Y',
|
||||
'%Y/%m/%d',
|
||||
'%d.%m.%Y',
|
||||
'%d-%m-%Y'
|
||||
]
|
||||
|
||||
def self.menu_item
|
||||
nil
|
||||
end
|
||||
|
||||
def self.layout
|
||||
'base'
|
||||
end
|
||||
|
||||
def self.authorized?(user)
|
||||
user.admin?
|
||||
end
|
||||
|
||||
def initialize(*args)
|
||||
super
|
||||
self.settings ||= {}
|
||||
|
@ -47,13 +62,13 @@ class Import < ActiveRecord::Base
|
|||
Redmine::Utils.save_upload(arg, filepath)
|
||||
end
|
||||
|
||||
def set_default_settings
|
||||
def set_default_settings(options={})
|
||||
separator = lu(user, :general_csv_separator)
|
||||
if file_exists?
|
||||
begin
|
||||
content = File.read(filepath, 256)
|
||||
separator = [',', ';'].sort_by {|sep| content.count(sep) }.last
|
||||
rescue Exception => e
|
||||
rescue => e
|
||||
end
|
||||
end
|
||||
wrapper = '"'
|
||||
|
@ -66,8 +81,17 @@ class Import < ActiveRecord::Base
|
|||
'separator' => separator,
|
||||
'wrapper' => wrapper,
|
||||
'encoding' => encoding,
|
||||
'date_format' => date_format
|
||||
'date_format' => date_format,
|
||||
'notifications' => '0'
|
||||
)
|
||||
|
||||
if options.key?(:project_id) && !options[:project_id].blank?
|
||||
# Do not fail if project doesn't exist
|
||||
begin
|
||||
project = Project.find(options[:project_id])
|
||||
self.settings.merge!('mapping' => {'project_id' => project.id})
|
||||
rescue; end
|
||||
end
|
||||
end
|
||||
|
||||
def to_param
|
||||
|
@ -77,7 +101,7 @@ class Import < ActiveRecord::Base
|
|||
# Returns the full path of the file to import
|
||||
# It is stored in tmp/imports with a random hex as filename
|
||||
def filepath
|
||||
if filename.present? && filename =~ /\A[0-9a-f]+\z/
|
||||
if filename.present? && /\A[0-9a-f]+\z/.match?(filename)
|
||||
File.join(Rails.root, "tmp", "imports", filename)
|
||||
else
|
||||
nil
|
||||
|
@ -141,8 +165,8 @@ class Import < ActiveRecord::Base
|
|||
# Adds a callback that will be called after the item at given position is imported
|
||||
def add_callback(position, name, *args)
|
||||
settings['callbacks'] ||= {}
|
||||
settings['callbacks'][position.to_i] ||= []
|
||||
settings['callbacks'][position.to_i] << [name, args]
|
||||
settings['callbacks'][position] ||= []
|
||||
settings['callbacks'][position] << [name, args]
|
||||
save!
|
||||
end
|
||||
|
||||
|
@ -174,6 +198,7 @@ class Import < ActiveRecord::Base
|
|||
if position > resume_after
|
||||
item = items.build
|
||||
item.position = position
|
||||
item.unique_id = row_value(row, 'unique_id') if use_unique_id?
|
||||
|
||||
if object = build_object(row, item)
|
||||
if object.save
|
||||
|
@ -186,7 +211,7 @@ class Import < ActiveRecord::Base
|
|||
item.save!
|
||||
imported += 1
|
||||
|
||||
do_callbacks(item.position, object)
|
||||
do_callbacks(use_unique_id? ? item.unique_id : item.position, object)
|
||||
end
|
||||
current = position
|
||||
end
|
||||
|
@ -257,7 +282,7 @@ class Import < ActiveRecord::Base
|
|||
if file_exists?
|
||||
begin
|
||||
File.delete filepath
|
||||
rescue Exception => e
|
||||
rescue => e
|
||||
logger.error "Unable to delete file #{filepath}: #{e.message}" if logger
|
||||
end
|
||||
end
|
||||
|
@ -267,4 +292,8 @@ class Import < ActiveRecord::Base
|
|||
def yes?(value)
|
||||
value == lu(user, :general_text_yes) || value == '1'
|
||||
end
|
||||
|
||||
def use_unique_id?
|
||||
mapping['unique_id'].present?
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue