Improved code layout.
This commit is contained in:
parent
aa4fffad32
commit
87e1a92e39
4 changed files with 51 additions and 51 deletions
|
@ -14,10 +14,10 @@ class Store < ApplicationModel
|
||||||
add an attachment to storage
|
add an attachment to storage
|
||||||
|
|
||||||
result = Store.add(
|
result = Store.add(
|
||||||
:object => 'Ticket::Article',
|
object: 'Ticket::Article',
|
||||||
:o_id => 4711,
|
o_id: 4711,
|
||||||
:data => binary_string,
|
data: binary_string,
|
||||||
:preferences => {
|
preferences: {
|
||||||
:content_type => 'image/png',
|
:content_type => 'image/png',
|
||||||
:content_id => 234,
|
:content_id => 234,
|
||||||
}
|
}
|
||||||
|
@ -57,8 +57,8 @@ returns
|
||||||
get attachment of object
|
get attachment of object
|
||||||
|
|
||||||
list = Store.list(
|
list = Store.list(
|
||||||
:object => 'Ticket::Article',
|
object: 'Ticket::Article',
|
||||||
:o_id => 4711,
|
o_id: 4711,
|
||||||
)
|
)
|
||||||
|
|
||||||
returns
|
returns
|
||||||
|
@ -66,9 +66,9 @@ returns
|
||||||
result = [store1, store2]
|
result = [store1, store2]
|
||||||
|
|
||||||
store1 = {
|
store1 = {
|
||||||
:size => 94123,
|
size: 94123,
|
||||||
:filename => 'image.png',
|
filename: 'image.png',
|
||||||
:preferences => {
|
preferences: {
|
||||||
:content_type => 'image/png',
|
:content_type => 'image/png',
|
||||||
:content_id => 234,
|
:content_id => 234,
|
||||||
}
|
}
|
||||||
|
@ -90,8 +90,8 @@ returns
|
||||||
remove attachments of object from storage
|
remove attachments of object from storage
|
||||||
|
|
||||||
result = Store.remove(
|
result = Store.remove(
|
||||||
:object => 'Ticket::Article',
|
object: 'Ticket::Article',
|
||||||
:o_id => 4711,
|
o_id: 4711,
|
||||||
)
|
)
|
||||||
|
|
||||||
returns
|
returns
|
||||||
|
|
|
@ -612,7 +612,7 @@ module Import::OTRS
|
||||||
|
|
||||||
# find owner
|
# find owner
|
||||||
if ticket_new[:owner]
|
if ticket_new[:owner]
|
||||||
user = User.lookup( login: ticket_new[:owner].downcase )
|
user = User.lookup(login: ticket_new[:owner])
|
||||||
ticket_new[:owner_id] = if user
|
ticket_new[:owner_id] = if user
|
||||||
user.id
|
user.id
|
||||||
else
|
else
|
||||||
|
@ -623,7 +623,7 @@ module Import::OTRS
|
||||||
|
|
||||||
# find customer
|
# find customer
|
||||||
if ticket_new[:customer]
|
if ticket_new[:customer]
|
||||||
user = User.lookup( login: ticket_new[:customer].downcase )
|
user = User.lookup(login: ticket_new[:customer])
|
||||||
ticket_new[:customer_id] = if user
|
ticket_new[:customer_id] = if user
|
||||||
user.id
|
user.id
|
||||||
else
|
else
|
||||||
|
@ -922,13 +922,13 @@ module Import::OTRS
|
||||||
}
|
}
|
||||||
|
|
||||||
# check if state already exists
|
# check if state already exists
|
||||||
state_old = Ticket::State.where( id: state_new[:id] ).first
|
state_old = Ticket::State.lookup( id: state_new[:id] )
|
||||||
|
|
||||||
# set state types
|
# set state types
|
||||||
if state['TypeName'] == 'pending auto'
|
if state['TypeName'] == 'pending auto'
|
||||||
state['TypeName'] = 'pending action'
|
state['TypeName'] = 'pending action'
|
||||||
end
|
end
|
||||||
state_type = Ticket::StateType.where( name: state['TypeName'] ).first
|
state_type = Ticket::StateType.lookup( name: state['TypeName'] )
|
||||||
state_new[:state_type_id] = state_type.id
|
state_new[:state_type_id] = state_type.id
|
||||||
if state_old
|
if state_old
|
||||||
state_old.update_attributes(state_new)
|
state_old.update_attributes(state_new)
|
||||||
|
@ -969,7 +969,7 @@ module Import::OTRS
|
||||||
}
|
}
|
||||||
|
|
||||||
# check if state already exists
|
# check if state already exists
|
||||||
priority_old = Ticket::Priority.where( id: priority_new[:id] ).first
|
priority_old = Ticket::Priority.lookup( id: priority_new[:id] )
|
||||||
|
|
||||||
# set state types
|
# set state types
|
||||||
if priority_old
|
if priority_old
|
||||||
|
@ -1010,7 +1010,7 @@ module Import::OTRS
|
||||||
}
|
}
|
||||||
|
|
||||||
# check if state already exists
|
# check if state already exists
|
||||||
group_old = Group.where( id: group_new[:id] ).first
|
group_old = Group.lookup( id: group_new[:id] )
|
||||||
|
|
||||||
# set state types
|
# set state types
|
||||||
if group_old
|
if group_old
|
||||||
|
@ -1070,7 +1070,7 @@ module Import::OTRS
|
||||||
end
|
end
|
||||||
|
|
||||||
# check if agent already exists
|
# check if agent already exists
|
||||||
user_old = User.where( id: user_new[:id] ).first
|
user_old = User.lookup( id: user_new[:id] )
|
||||||
|
|
||||||
# check if login is already used
|
# check if login is already used
|
||||||
login_in_use = User.where( "login = ? AND id != #{user_new[:id]}", user_new[:login].downcase ).count
|
login_in_use = User.where( "login = ? AND id != #{user_new[:id]}", user_new[:login].downcase ).count
|
||||||
|
@ -1223,7 +1223,7 @@ module Import::OTRS
|
||||||
}
|
}
|
||||||
|
|
||||||
# check if customer already exists
|
# check if customer already exists
|
||||||
user_old = User.where( login: user_new[:login].downcase ).first
|
user_old = User.lookup( login: user_new[:login] )
|
||||||
|
|
||||||
# create / update agent
|
# create / update agent
|
||||||
if user_old
|
if user_old
|
||||||
|
@ -1252,7 +1252,7 @@ module Import::OTRS
|
||||||
if user['UserCustomerID']
|
if user['UserCustomerID']
|
||||||
organizations.each {|organization|
|
organizations.each {|organization|
|
||||||
next if user['UserCustomerID'] != organization['CustomerID']
|
next if user['UserCustomerID'] != organization['CustomerID']
|
||||||
organization = Organization.where(name: organization['CustomerCompanyName'] ).first
|
organization = Organization.lookup(name: organization['CustomerCompanyName'] )
|
||||||
organization_id = organization.id
|
organization_id = organization.id
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -1285,7 +1285,7 @@ module Import::OTRS
|
||||||
}
|
}
|
||||||
|
|
||||||
# check if state already exists
|
# check if state already exists
|
||||||
organization_old = Organization.where( name: organization_new[:name] ).first
|
organization_old = Organization.lookup( name: organization_new[:name] )
|
||||||
|
|
||||||
# set state types
|
# set state types
|
||||||
if organization_old
|
if organization_old
|
||||||
|
@ -1419,9 +1419,9 @@ module Import::OTRS
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
user = User.where( email: email.downcase ).first
|
user = User.lookup(email: email)
|
||||||
if !user
|
if !user
|
||||||
user = User.where( login: email.downcase ).first
|
user = User.lookup(login: email)
|
||||||
end
|
end
|
||||||
if !user
|
if !user
|
||||||
begin
|
begin
|
||||||
|
@ -1449,7 +1449,7 @@ module Import::OTRS
|
||||||
)
|
)
|
||||||
rescue ActiveRecord::RecordNotUnique
|
rescue ActiveRecord::RecordNotUnique
|
||||||
log "User #{email} was handled by another thread, taking this."
|
log "User #{email} was handled by another thread, taking this."
|
||||||
user = User.find_by( login: email.downcase )
|
user = User.lookup(login: email)
|
||||||
if !user
|
if !user
|
||||||
log "User #{email} wasn't created sleep and retry."
|
log "User #{email} wasn't created sleep and retry."
|
||||||
sleep rand 3
|
sleep rand 3
|
||||||
|
|
|
@ -515,9 +515,9 @@ module Import::Zendesk
|
||||||
|
|
||||||
@zendesk_user_mapping = {}
|
@zendesk_user_mapping = {}
|
||||||
|
|
||||||
role_admin = Role.find_by( name: 'Admin' )
|
role_admin = Role.lookup(name: 'Admin')
|
||||||
role_agent = Role.find_by( name: 'Agent' )
|
role_agent = Role.lookup(name: 'Agent')
|
||||||
role_customer = Role.find_by( name: 'Customer' )
|
role_customer = Role.lookup(name: 'Customer')
|
||||||
|
|
||||||
@client.users.all { |zendesk_user|
|
@client.users.all { |zendesk_user|
|
||||||
|
|
||||||
|
@ -612,18 +612,18 @@ module Import::Zendesk
|
||||||
# https://developer.zendesk.com/rest_api/docs/core/ticket_audits # v2
|
# https://developer.zendesk.com/rest_api/docs/core/ticket_audits # v2
|
||||||
def import_tickets
|
def import_tickets
|
||||||
|
|
||||||
article_sender_customer = Ticket::Article::Sender.find_by(name: 'Customer')
|
article_sender_customer = Ticket::Article::Sender.lookup(name: 'Customer')
|
||||||
article_sender_agent = Ticket::Article::Sender.find_by(name: 'Agent')
|
article_sender_agent = Ticket::Article::Sender.lookup(name: 'Agent')
|
||||||
article_sender_system = Ticket::Article::Sender.find_by(name: 'System')
|
article_sender_system = Ticket::Article::Sender.lookup(name: 'System')
|
||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
article_type_web = Ticket::Article::Type.find_by(name: 'web')
|
article_type_web = Ticket::Article::Type.lookup(name: 'web')
|
||||||
article_type_note = Ticket::Article::Type.find_by(name: 'note')
|
article_type_note = Ticket::Article::Type.lookup(name: 'note')
|
||||||
article_type_email = Ticket::Article::Type.find_by(name: 'email')
|
article_type_email = Ticket::Article::Type.lookup(name: 'email')
|
||||||
article_type_twitter_status = Ticket::Article::Type.find_by(name: 'twitter status')
|
article_type_twitter_status = Ticket::Article::Type.lookup(name: 'twitter status')
|
||||||
article_type_twitter_dm = Ticket::Article::Type.find_by(name: 'twitter direct-message')
|
article_type_twitter_dm = Ticket::Article::Type.lookup(name: 'twitter direct-message')
|
||||||
article_type_facebook_feed_post = Ticket::Article::Type.find_by(name: 'facebook feed post')
|
article_type_facebook_feed_post = Ticket::Article::Type.lookup(name: 'facebook feed post')
|
||||||
article_type_facebook_feed_comment = Ticket::Article::Type.find_by(name: 'facebook feed comment')
|
article_type_facebook_feed_comment = Ticket::Article::Type.lookup(name: 'facebook feed comment')
|
||||||
|
|
||||||
@client.tickets.all { |zendesk_ticket|
|
@client.tickets.all { |zendesk_ticket|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue