Improved name spaces.
This commit is contained in:
parent
0095f24af7
commit
0dc6e96a5a
7 changed files with 255 additions and 234 deletions
|
@ -251,6 +251,9 @@ class Package < ApplicationModel
|
||||||
|
|
||||||
# prebuild assets
|
# prebuild assets
|
||||||
|
|
||||||
|
# reload new files
|
||||||
|
Package.reload_classes
|
||||||
|
|
||||||
# delete package
|
# delete package
|
||||||
record = Package.where(
|
record = Package.where(
|
||||||
:name => meta[:name],
|
:name => meta[:name],
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
module Auth
|
||||||
|
end
|
||||||
module Auth::ENV
|
module Auth::ENV
|
||||||
def self.check( user, username, password, config )
|
def self.check( user, username, password, config )
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
module Auth
|
||||||
|
end
|
||||||
module Auth::INTERNAL
|
module Auth::INTERNAL
|
||||||
def self.check( user, username, password, config )
|
def self.check( user, username, password, config )
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
module Auth
|
||||||
|
end
|
||||||
module Auth::LDAP
|
module Auth::LDAP
|
||||||
def self.check( user, username, password, config )
|
def self.check( user, username, password, config )
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
class Auth::OTRS
|
module Auth
|
||||||
|
end
|
||||||
|
module Auth::OTRS
|
||||||
def self.check( user, username, password, config )
|
def self.check( user, username, password, config )
|
||||||
|
|
||||||
endpoint = Setting.get('import_otrs_endpoint')
|
endpoint = Setting.get('import_otrs_endpoint')
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
module Auth
|
||||||
|
end
|
||||||
module Auth::TEST
|
module Auth::TEST
|
||||||
def self.check( user, username, password, config )
|
def self.check( user, username, password, config )
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
module Import
|
||||||
|
end
|
||||||
module Import::OTRS
|
module Import::OTRS
|
||||||
def self.request(part)
|
def self.request(part)
|
||||||
url = Setting.get('import_otrs_endpoint') + '/' + part + ';Key=' + Setting.get('import_otrs_endpoint_key')
|
url = Setting.get('import_otrs_endpoint') + '/' + part + ';Key=' + Setting.get('import_otrs_endpoint_key')
|
||||||
|
@ -85,7 +87,8 @@ module Import::OTRS
|
||||||
result = JSON.parse( response.body )
|
result = JSON.parse( response.body )
|
||||||
result = result.reverse
|
result = result.reverse
|
||||||
|
|
||||||
thread_count = 8
|
Thread.abort_on_exception = true
|
||||||
|
thread_count = 2
|
||||||
threads = {}
|
threads = {}
|
||||||
(1..thread_count).each {|thread|
|
(1..thread_count).each {|thread|
|
||||||
threads[thread] = Thread.new {
|
threads[thread] = Thread.new {
|
||||||
|
@ -158,6 +161,10 @@ module Import::OTRS
|
||||||
}
|
}
|
||||||
|
|
||||||
result.each {|record|
|
result.each {|record|
|
||||||
|
|
||||||
|
# use transaction
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
|
||||||
ticket_new = {
|
ticket_new = {
|
||||||
:title => '',
|
:title => '',
|
||||||
:created_by_id => 1,
|
:created_by_id => 1,
|
||||||
|
@ -176,7 +183,7 @@ module Import::OTRS
|
||||||
#puts 'TICKET OLD ' + ticket_old.inspect
|
#puts 'TICKET OLD ' + ticket_old.inspect
|
||||||
# find user
|
# find user
|
||||||
if ticket_new[:owner]
|
if ticket_new[:owner]
|
||||||
user = User.where( :login => ticket_new[:owner] ).first
|
user = User.lookup( :login => ticket_new[:owner] )
|
||||||
if user
|
if user
|
||||||
ticket_new[:owner_id] = user.id
|
ticket_new[:owner_id] = user.id
|
||||||
else
|
else
|
||||||
|
@ -185,7 +192,7 @@ module Import::OTRS
|
||||||
ticket_new.delete(:owner)
|
ticket_new.delete(:owner)
|
||||||
end
|
end
|
||||||
if ticket_new[:customer]
|
if ticket_new[:customer]
|
||||||
user = User.where( :login => ticket_new[:customer] ).first
|
user = User.lookup( :login => ticket_new[:customer] )
|
||||||
if user
|
if user
|
||||||
ticket_new[:customer_id] = user.id
|
ticket_new[:customer_id] = user.id
|
||||||
else
|
else
|
||||||
|
@ -242,7 +249,7 @@ module Import::OTRS
|
||||||
# do extra decoding because we needed to use field.value
|
# do extra decoding because we needed to use field.value
|
||||||
display_name = Mail::Field.new( 'X-From', display_name ).to_s
|
display_name = Mail::Field.new( 'X-From', display_name ).to_s
|
||||||
|
|
||||||
roles = Role.where( :name => 'Customer' )
|
roles = Role.lookup( :name => 'Customer' )
|
||||||
user = User.create(
|
user = User.create(
|
||||||
:login => email,
|
:login => email,
|
||||||
:firstname => display_name,
|
:firstname => display_name,
|
||||||
|
@ -294,11 +301,11 @@ module Import::OTRS
|
||||||
end
|
end
|
||||||
article_new.delete( :ticket_article_type )
|
article_new.delete( :ticket_article_type )
|
||||||
article_old = Ticket::Article.where( :id => article_new[:id] ).first
|
article_old = Ticket::Article.where( :id => article_new[:id] ).first
|
||||||
#puts 'ARTICLE OLD ' + article_old.inspect
|
#puts 'ARTICLE OLD ' + article_old.inspect
|
||||||
# set state types
|
# set state types
|
||||||
if article_old
|
if article_old
|
||||||
puts "update Ticket::Article.find(#{article_new[:id]})"
|
puts "update Ticket::Article.find(#{article_new[:id]})"
|
||||||
# puts article_new.inspect
|
# puts article_new.inspect
|
||||||
article_old.update_attributes(article_new)
|
article_old.update_attributes(article_new)
|
||||||
else
|
else
|
||||||
puts "add Ticket::Article.find(#{article_new[:id]})"
|
puts "add Ticket::Article.find(#{article_new[:id]})"
|
||||||
|
@ -310,8 +317,8 @@ module Import::OTRS
|
||||||
}
|
}
|
||||||
|
|
||||||
record['History'].each { |history|
|
record['History'].each { |history|
|
||||||
# puts '-------'
|
# puts '-------'
|
||||||
# puts history.inspect
|
# puts history.inspect
|
||||||
if history['HistoryType'] == 'NewTicket'
|
if history['HistoryType'] == 'NewTicket'
|
||||||
History.history_create(
|
History.history_create(
|
||||||
:id => history['HistoryID'],
|
:id => history['HistoryID'],
|
||||||
|
@ -339,7 +346,7 @@ module Import::OTRS
|
||||||
to_id = state_to.id
|
to_id = state_to.id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
# puts "STATE UPDATE (#{history['HistoryID']}): -> #{from}->#{to}"
|
# puts "STATE UPDATE (#{history['HistoryID']}): -> #{from}->#{to}"
|
||||||
History.history_create(
|
History.history_create(
|
||||||
:id => history['HistoryID'],
|
:id => history['HistoryID'],
|
||||||
:o_id => history['TicketID'],
|
:o_id => history['TicketID'],
|
||||||
|
@ -417,6 +424,7 @@ module Import::OTRS
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue