forked from zammad/zammad
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed issue zammad#1375 - assignment_timeout in group settings has no…
… effect.
- Loading branch information
Showing
6 changed files
with
394 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ | ||
|
||
class Observer::Ticket::LastOwnerUpdate < ActiveRecord::Observer | ||
observe 'ticket' | ||
|
||
def before_create(record) | ||
_check('create', record) | ||
end | ||
|
||
def before_update(record) | ||
_check('update', record) | ||
end | ||
|
||
private | ||
|
||
def _check(type, record) | ||
|
||
# return if we run import mode | ||
return true if Setting.get('import_mode') | ||
|
||
# check if owner has changed | ||
if type == 'update' | ||
return true if record.changes['owner_id'].blank? | ||
end | ||
|
||
# check if owner is nobody | ||
if record.owner_id.blank? || record.owner_id == 1 | ||
record.last_owner_update_at = nil | ||
return true | ||
end | ||
|
||
record.last_owner_update_at = Time.zone.now | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
class LastOwnerUpdate < ActiveRecord::Migration | ||
def up | ||
|
||
# return if it's a new setup | ||
return if !Setting.find_by(name: 'system_init_done') | ||
|
||
# reset assignment_timeout to prevent unwanted things happen | ||
Group.all.each { |group| | ||
group.assignment_timeout = nil | ||
group.save! | ||
} | ||
|
||
add_column :tickets, :last_owner_update_at, :timestamp, limit: 3, null: true | ||
add_index :tickets, [:last_owner_update_at] | ||
Ticket.reset_column_information | ||
|
||
Scheduler.create_if_not_exists( | ||
name: 'Process auto unassign tickets', | ||
method: 'Ticket.process_auto_unassign', | ||
period: 10.minutes, | ||
prio: 1, | ||
active: true, | ||
) | ||
|
||
state_ids = Ticket::State.by_category(:work_on).pluck(:id) | ||
if state_ids.present? | ||
ticket_ids = Ticket.where('tickets.state_id IN (?) AND tickets.owner_id != 1', state_ids).order(created_at: :desc).limit(1000).pluck(:id) | ||
ticket_ids.each { |ticket_id| | ||
ticket = Ticket.find_by(id: ticket_id) | ||
next if !ticket | ||
ticket.last_owner_update_at = last_owner_update_at(ticket) | ||
ticket.save! | ||
} | ||
end | ||
end | ||
|
||
def last_owner_update_at(ticket) | ||
type = History::Type.lookup(name: 'updated') | ||
if type | ||
object = History::Object.lookup(name: 'Ticket') | ||
if object | ||
attribute = History::Attribute.lookup(name: 'owner') | ||
if attribute | ||
history = History.where(o_id: ticket.id, history_type_id: type.id, history_object_id: object.id, history_attribute_id: attribute.id).where.not(id_to: 1).order(created_at: :desc).limit(1) | ||
if history.present? | ||
return history.first.created_at | ||
end | ||
end | ||
end | ||
end | ||
return nil if ticket.owner_id == 1 | ||
ticket.created_at | ||
end | ||
|
||
end |
Oops, something went wrong.