Improved code layout.

This commit is contained in:
Martin Edenhofer 2016-01-24 12:50:29 +01:00
parent aa4fffad32
commit 87e1a92e39
4 changed files with 51 additions and 51 deletions

View file

@ -168,7 +168,7 @@ returns:
# lookups
if object
object_lookup_id = ObjectLookup.by_name( object )
object_lookup_id = ObjectLookup.by_name(object)
end
# get attributes in right order
@ -198,7 +198,7 @@ returns:
}
end
if item.data_option
data = data.merge( item.data_option.symbolize_keys )
data = data.merge(item.data_option.symbolize_keys)
end
attributes.push data
}

View file

@ -14,10 +14,10 @@ class Store < ApplicationModel
add an attachment to storage
result = Store.add(
:object => 'Ticket::Article',
:o_id => 4711,
:data => binary_string,
:preferences => {
object: 'Ticket::Article',
o_id: 4711,
data: binary_string,
preferences: {
:content_type => 'image/png',
:content_id => 234,
}
@ -33,11 +33,11 @@ returns
data = data.stringify_keys
# lookup store_object.id
store_object = Store::Object.create_if_not_exists( name: data['object'] )
store_object = Store::Object.create_if_not_exists(name: data['object'])
data['store_object_id'] = store_object.id
# add to real store
file = Store::File.add( data['data'] )
file = Store::File.add(data['data'])
data['size'] = data['data'].to_s.bytesize
data['store_file_id'] = file.id
@ -57,8 +57,8 @@ returns
get attachment of object
list = Store.list(
:object => 'Ticket::Article',
:o_id => 4711,
object: 'Ticket::Article',
o_id: 4711,
)
returns
@ -66,9 +66,9 @@ returns
result = [store1, store2]
store1 = {
:size => 94123,
:filename => 'image.png',
:preferences => {
size: 94123,
filename: 'image.png',
preferences: {
:content_type => 'image/png',
:content_id => 234,
}
@ -79,8 +79,8 @@ returns
def self.list(data)
# search
store_object_id = Store::Object.lookup( name: data[:object] )
stores = Store.where( store_object_id: store_object_id, o_id: data[:o_id].to_i )
store_object_id = Store::Object.lookup(name: data[:object])
stores = Store.where(store_object_id: store_object_id, o_id: data[:o_id].to_i)
.order('created_at ASC, id ASC')
stores
end
@ -90,8 +90,8 @@ returns
remove attachments of object from storage
result = Store.remove(
:object => 'Ticket::Article',
:o_id => 4711,
object: 'Ticket::Article',
o_id: 4711,
)
returns
@ -102,14 +102,14 @@ returns
def self.remove(data)
# search
store_object_id = Store::Object.lookup( name: data[:object] )
stores = Store.where( store_object_id: store_object_id )
.where( o_id: data[:o_id] )
store_object_id = Store::Object.lookup(name: data[:object])
stores = Store.where(store_object_id: store_object_id)
.where(o_id: data[:o_id])
.order('created_at ASC, id ASC')
stores.each do |store|
# check backend for references
Store.remove_item( store.id )
Store.remove_item(store.id)
end
true
end
@ -130,9 +130,9 @@ returns
# check backend for references
store = Store.find(store_id)
files = Store.where( store_file_id: store.store_file_id )
files = Store.where(store_file_id: store.store_file_id)
if files.count == 1 && files.first.id == store.id
Store::File.find( store.store_file_id ).destroy
Store::File.find(store.store_file_id).destroy
end
store.destroy
@ -140,7 +140,7 @@ returns
end
def content
file = Store::File.find_by( id: store_file_id )
file = Store::File.find_by(id: store_file_id)
if !file
fail "No such file #{store_file_id}!"
end
@ -148,7 +148,7 @@ returns
end
def provider
file = Store::File.find_by( id: store_file_id )
file = Store::File.find_by(id: store_file_id)
if !file
fail "No such file #{store_file_id}!"
end

View file

@ -612,7 +612,7 @@ module Import::OTRS
# find 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
user.id
else
@ -623,7 +623,7 @@ module Import::OTRS
# find 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
user.id
else
@ -922,13 +922,13 @@ module Import::OTRS
}
# 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
if state['TypeName'] == 'pending auto'
state['TypeName'] = 'pending action'
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
if state_old
state_old.update_attributes(state_new)
@ -969,7 +969,7 @@ module Import::OTRS
}
# 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
if priority_old
@ -1010,7 +1010,7 @@ module Import::OTRS
}
# 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
if group_old
@ -1070,7 +1070,7 @@ module Import::OTRS
end
# 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
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
user_old = User.where( login: user_new[:login].downcase ).first
user_old = User.lookup( login: user_new[:login] )
# create / update agent
if user_old
@ -1252,7 +1252,7 @@ module Import::OTRS
if user['UserCustomerID']
organizations.each {|organization|
next if user['UserCustomerID'] != organization['CustomerID']
organization = Organization.where(name: organization['CustomerCompanyName'] ).first
organization = Organization.lookup(name: organization['CustomerCompanyName'] )
organization_id = organization.id
}
end
@ -1285,7 +1285,7 @@ module Import::OTRS
}
# 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
if organization_old
@ -1419,9 +1419,9 @@ module Import::OTRS
end
end
user = User.where( email: email.downcase ).first
user = User.lookup(email: email)
if !user
user = User.where( login: email.downcase ).first
user = User.lookup(login: email)
end
if !user
begin
@ -1449,7 +1449,7 @@ module Import::OTRS
)
rescue ActiveRecord::RecordNotUnique
log "User #{email} was handled by another thread, taking this."
user = User.find_by( login: email.downcase )
user = User.lookup(login: email)
if !user
log "User #{email} wasn't created sleep and retry."
sleep rand 3

View file

@ -515,9 +515,9 @@ module Import::Zendesk
@zendesk_user_mapping = {}
role_admin = Role.find_by( name: 'Admin' )
role_agent = Role.find_by( name: 'Agent' )
role_customer = Role.find_by( name: 'Customer' )
role_admin = Role.lookup(name: 'Admin')
role_agent = Role.lookup(name: 'Agent')
role_customer = Role.lookup(name: 'Customer')
@client.users.all { |zendesk_user|
@ -612,18 +612,18 @@ module Import::Zendesk
# https://developer.zendesk.com/rest_api/docs/core/ticket_audits # v2
def import_tickets
article_sender_customer = Ticket::Article::Sender.find_by(name: 'Customer')
article_sender_agent = Ticket::Article::Sender.find_by(name: 'Agent')
article_sender_system = Ticket::Article::Sender.find_by(name: 'System')
article_sender_customer = Ticket::Article::Sender.lookup(name: 'Customer')
article_sender_agent = Ticket::Article::Sender.lookup(name: 'Agent')
article_sender_system = Ticket::Article::Sender.lookup(name: 'System')
# TODO
article_type_web = Ticket::Article::Type.find_by(name: 'web')
article_type_note = Ticket::Article::Type.find_by(name: 'note')
article_type_email = Ticket::Article::Type.find_by(name: 'email')
article_type_twitter_status = Ticket::Article::Type.find_by(name: 'twitter status')
article_type_twitter_dm = Ticket::Article::Type.find_by(name: 'twitter direct-message')
article_type_facebook_feed_post = Ticket::Article::Type.find_by(name: 'facebook feed post')
article_type_facebook_feed_comment = Ticket::Article::Type.find_by(name: 'facebook feed comment')
article_type_web = Ticket::Article::Type.lookup(name: 'web')
article_type_note = Ticket::Article::Type.lookup(name: 'note')
article_type_email = Ticket::Article::Type.lookup(name: 'email')
article_type_twitter_status = Ticket::Article::Type.lookup(name: 'twitter status')
article_type_twitter_dm = Ticket::Article::Type.lookup(name: 'twitter direct-message')
article_type_facebook_feed_post = Ticket::Article::Type.lookup(name: 'facebook feed post')
article_type_facebook_feed_comment = Ticket::Article::Type.lookup(name: 'facebook feed comment')
@client.tickets.all { |zendesk_ticket|