Added merge_to().

This commit is contained in:
Martin Edenhofer 2012-07-03 15:24:31 +02:00
parent 8f0e578107
commit 3d1ab793e7

View file

@ -39,6 +39,37 @@ class Ticket < ActiveRecord::Base
User.where( :active => true ).joins(:roles).where( 'roles.name' => 'Agent', 'roles.active' => true ).uniq() User.where( :active => true ).joins(:roles).where( 'roles.name' => 'Agent', 'roles.active' => true ).uniq()
end end
def merge_to(data)
# update articles
Ticket::Article.where( :ticket_id => self.id ).update_all( ['ticket_id = ?', data[:ticket_id] ] )
# update history
# create new merge article
Ticket::Article.create(
:created_by_id => data[:created_by_id],
:ticket_id => self.id,
:ticket_article_type_id => Ticket::Article::Type.where( :name => 'note' ).first.id,
:ticket_article_sender_id => Ticket::Article::Sender.where( :name => 'Agent' ).first.id,
:body => 'merged',
:internal => false
)
# add history to both
# link tickets
# set state to 'merged'
self.ticket_state_id = Ticket::State.where( :name => 'merged' ).first.id
# rest owner
self.owner_id = User.where(:login => '-').first.id
# save ticket
self.save
end
# def self.agent # def self.agent
# Role.where( :name => ['Agent'], :active => true ).first.users.where( :active => true ).uniq() # Role.where( :name => ['Agent'], :active => true ).first.users.where( :active => true ).uniq()
# end # end
@ -146,6 +177,12 @@ class Ticket < ActiveRecord::Base
type = Ticket::Article::Type.where( :id => self.ticket_article_type_id ).first type = Ticket::Article::Type.where( :id => self.ticket_article_type_id ).first
ticket = Ticket.find(self.ticket_id) ticket = Ticket.find(self.ticket_id)
# set from if not given
if !self.from
user = User.find(self.created_by_id)
self.from = "#{user.firstname} #{user.lastname}"
end
# set email attributes # set email attributes
if type['name'] == 'email' if type['name'] == 'email'