Improved API, renamed methodes.
This commit is contained in:
parent
a8d8764ac3
commit
d1700945d8
9 changed files with 39 additions and 40 deletions
|
@ -147,7 +147,7 @@ class TicketsController < ApplicationController
|
||||||
return if !ticket_permission( ticket )
|
return if !ticket_permission( ticket )
|
||||||
|
|
||||||
# get history of ticket
|
# get history of ticket
|
||||||
history = History.history_list( 'Ticket', params[:id], 'Ticket::Article' )
|
history = History.list( 'Ticket', params[:id], 'Ticket::Article' )
|
||||||
|
|
||||||
# get related users
|
# get related users
|
||||||
users = {}
|
users = {}
|
||||||
|
|
|
@ -10,7 +10,7 @@ class History < ApplicationModel
|
||||||
@@cache_object = {}
|
@@cache_object = {}
|
||||||
@@cache_attribute = {}
|
@@cache_attribute = {}
|
||||||
|
|
||||||
def self.history_create(data)
|
def self.add(data)
|
||||||
|
|
||||||
# lookups
|
# lookups
|
||||||
if data[:history_type]
|
if data[:history_type]
|
||||||
|
@ -61,13 +61,15 @@ class History < ApplicationModel
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.history_destroy( requested_object, requested_object_id )
|
def self.remove( requested_object, requested_object_id )
|
||||||
History.where( :history_object_id => History::Object.where( :name => requested_object ) ).
|
history_object = History::Object.where( :name => requested_object ).first
|
||||||
where( :o_id => requested_object_id ).
|
History.where(
|
||||||
destroy_all
|
:history_object_id => history_object.id,
|
||||||
|
:o_id => requested_object_id,
|
||||||
|
).destroy_all
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.history_list( requested_object, requested_object_id, related_history_object = nil )
|
def self.list( requested_object, requested_object_id, related_history_object = nil )
|
||||||
if !related_history_object
|
if !related_history_object
|
||||||
history_object = self.history_object_lookup( requested_object )
|
history_object = self.history_object_lookup( requested_object )
|
||||||
history = History.where( :history_object_id => history_object.id ).
|
history = History.where( :history_object_id => history_object.id ).
|
||||||
|
|
|
@ -19,7 +19,7 @@ class Observer::History < ActiveRecord::Observer
|
||||||
related_o_id = record.ticket_id
|
related_o_id = record.ticket_id
|
||||||
related_history_object = 'Ticket'
|
related_history_object = 'Ticket'
|
||||||
end
|
end
|
||||||
History.history_create(
|
History.add(
|
||||||
:o_id => record.id,
|
:o_id => record.id,
|
||||||
:history_type => 'created',
|
:history_type => 'created',
|
||||||
:history_object => record.class.name,
|
:history_object => record.class.name,
|
||||||
|
@ -143,7 +143,7 @@ class Observer::History < ActiveRecord::Observer
|
||||||
related_o_id = record.ticket_id
|
related_o_id = record.ticket_id
|
||||||
related_history_object_id = 'Ticket'
|
related_history_object_id = 'Ticket'
|
||||||
end
|
end
|
||||||
History.history_create(
|
History.add(
|
||||||
:o_id => current.id,
|
:o_id => current.id,
|
||||||
:history_type => 'updated',
|
:history_type => 'updated',
|
||||||
:history_object => record.class.name,
|
:history_object => record.class.name,
|
||||||
|
|
|
@ -9,13 +9,12 @@ class Observer::Tag::TicketHistory < ActiveRecord::Observer
|
||||||
return true if record.tag_object.name != 'Ticket';
|
return true if record.tag_object.name != 'Ticket';
|
||||||
|
|
||||||
# add ticket history
|
# add ticket history
|
||||||
History.history_create(
|
History.add(
|
||||||
:o_id => record.o_id,
|
:o_id => record.o_id,
|
||||||
:history_type => 'added',
|
:history_type => 'added',
|
||||||
:history_object => 'Ticket',
|
:history_object => 'Ticket',
|
||||||
:history_attribute => 'Tag',
|
:history_attribute => 'Tag',
|
||||||
:value_from => record.tag_item.name,
|
:value_from => record.tag_item.name,
|
||||||
:created_by_id => record.created_by_id || UserInfo.current_user_id || 1
|
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
def after_destroy(record)
|
def after_destroy(record)
|
||||||
|
@ -24,13 +23,12 @@ class Observer::Tag::TicketHistory < ActiveRecord::Observer
|
||||||
return true if record.tag_object.name != 'Ticket';
|
return true if record.tag_object.name != 'Ticket';
|
||||||
|
|
||||||
# add ticket history
|
# add ticket history
|
||||||
History.history_create(
|
History.add(
|
||||||
:o_id => record.o_id,
|
:o_id => record.o_id,
|
||||||
:history_type => 'removed',
|
:history_type => 'removed',
|
||||||
:history_object => 'Ticket',
|
:history_object => 'Ticket',
|
||||||
:history_attribute => 'Tag',
|
:history_attribute => 'Tag',
|
||||||
:value_from => record.tag_item.name,
|
:value_from => record.tag_item.name,
|
||||||
:created_by_id => record.created_by_id || UserInfo.current_user_id || 1
|
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -55,7 +55,7 @@ class Observer::Ticket::Article::CommunicateEmail < ActiveRecord::Observer
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
if recipient_list != ''
|
if recipient_list != ''
|
||||||
History.history_create(
|
History.add(
|
||||||
:o_id => record.id,
|
:o_id => record.id,
|
||||||
:history_type => 'email',
|
:history_type => 'email',
|
||||||
:history_object => 'Ticket::Article',
|
:history_object => 'Ticket::Article',
|
||||||
|
@ -63,7 +63,6 @@ class Observer::Ticket::Article::CommunicateEmail < ActiveRecord::Observer
|
||||||
:related_history_object => 'Ticket',
|
:related_history_object => 'Ticket',
|
||||||
:value_from => record.subject,
|
:value_from => record.subject,
|
||||||
:value_to => recipient_list,
|
:value_to => recipient_list,
|
||||||
:created_by_id => record.created_by_id,
|
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -235,7 +235,7 @@ From: #{article.from}
|
||||||
|
|
||||||
# add history record
|
# add history record
|
||||||
if recipient_list != ''
|
if recipient_list != ''
|
||||||
History.history_create(
|
History.add(
|
||||||
:o_id => ticket.id,
|
:o_id => ticket.id,
|
||||||
:history_type => 'notification',
|
:history_type => 'notification',
|
||||||
:history_object => 'Ticket',
|
:history_object => 'Ticket',
|
||||||
|
|
|
@ -695,7 +695,7 @@ class Ticket < ApplicationModel
|
||||||
def destroy_dependencies
|
def destroy_dependencies
|
||||||
|
|
||||||
# delete history
|
# delete history
|
||||||
History.history_destroy( 'Ticket', self.id )
|
History.remove( 'Ticket', self.id )
|
||||||
|
|
||||||
# delete articles
|
# delete articles
|
||||||
self.articles.destroy_all
|
self.articles.destroy_all
|
||||||
|
|
|
@ -417,7 +417,7 @@ module Import::OTRS
|
||||||
# puts '-------'
|
# puts '-------'
|
||||||
# puts history.inspect
|
# puts history.inspect
|
||||||
if history['HistoryType'] == 'NewTicket'
|
if history['HistoryType'] == 'NewTicket'
|
||||||
History.history_create(
|
History.add(
|
||||||
:id => history['HistoryID'],
|
:id => history['HistoryID'],
|
||||||
:o_id => history['TicketID'],
|
:o_id => history['TicketID'],
|
||||||
:history_type => 'created',
|
:history_type => 'created',
|
||||||
|
@ -444,7 +444,7 @@ module Import::OTRS
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
# puts "STATE UPDATE (#{history['HistoryID']}): -> #{from}->#{to}"
|
# puts "STATE UPDATE (#{history['HistoryID']}): -> #{from}->#{to}"
|
||||||
History.history_create(
|
History.add(
|
||||||
:id => history['HistoryID'],
|
:id => history['HistoryID'],
|
||||||
:o_id => history['TicketID'],
|
:o_id => history['TicketID'],
|
||||||
:history_type => 'updated',
|
:history_type => 'updated',
|
||||||
|
@ -469,7 +469,7 @@ module Import::OTRS
|
||||||
to = $3
|
to = $3
|
||||||
to_id = $4
|
to_id = $4
|
||||||
end
|
end
|
||||||
History.history_create(
|
History.add(
|
||||||
:id => history['HistoryID'],
|
:id => history['HistoryID'],
|
||||||
:o_id => history['TicketID'],
|
:o_id => history['TicketID'],
|
||||||
:history_type => 'updated',
|
:history_type => 'updated',
|
||||||
|
@ -494,7 +494,7 @@ module Import::OTRS
|
||||||
to = $3
|
to = $3
|
||||||
to_id = $4
|
to_id = $4
|
||||||
end
|
end
|
||||||
History.history_create(
|
History.add(
|
||||||
:id => history['HistoryID'],
|
:id => history['HistoryID'],
|
||||||
:o_id => history['TicketID'],
|
:o_id => history['TicketID'],
|
||||||
:history_type => 'updated',
|
:history_type => 'updated',
|
||||||
|
@ -509,7 +509,7 @@ module Import::OTRS
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
if history['ArticleID'] && history['ArticleID'] != 0
|
if history['ArticleID'] && history['ArticleID'] != 0
|
||||||
History.history_create(
|
History.add(
|
||||||
:id => history['HistoryID'],
|
:id => history['HistoryID'],
|
||||||
:o_id => history['ArticleID'],
|
:o_id => history['ArticleID'],
|
||||||
:history_type => 'created',
|
:history_type => 'created',
|
||||||
|
|
|
@ -162,7 +162,7 @@ class HistoryTest < ActiveSupport::TestCase
|
||||||
tickets.push ticket
|
tickets.push ticket
|
||||||
|
|
||||||
# get history
|
# get history
|
||||||
history_list = History.history_list( 'Ticket', ticket.id, 'Ticket::Article' )
|
history_list = History.list( 'Ticket', ticket.id, 'Ticket::Article' )
|
||||||
puts history_list.inspect
|
puts history_list.inspect
|
||||||
test[:history_check].each { |check_item|
|
test[:history_check].each { |check_item|
|
||||||
# puts '+++++++++++'
|
# puts '+++++++++++'
|
||||||
|
|
Loading…
Reference in a new issue