Fixed bug: Reports raise error if (history) attribute or type couldn't be found.
This commit is contained in:
parent
18c826c2a2
commit
08940fbb06
1 changed files with 63 additions and 62 deletions
|
@ -14,9 +14,6 @@ class Report::Base
|
||||||
|
|
||||||
query, bind_params, tables = Ticket.selector2sql(params[:selector])
|
query, bind_params, tables = Ticket.selector2sql(params[:selector])
|
||||||
|
|
||||||
count = 0
|
|
||||||
ticket_ids = []
|
|
||||||
|
|
||||||
# created
|
# created
|
||||||
if params[:type] == 'created'
|
if params[:type] == 'created'
|
||||||
history_type = History::Type.lookup( name: 'created' )
|
history_type = History::Type.lookup( name: 'created' )
|
||||||
|
@ -31,73 +28,77 @@ class Report::Base
|
||||||
if params[:type] == 'updated'
|
if params[:type] == 'updated'
|
||||||
history_type = History::Type.lookup( name: 'updated' )
|
history_type = History::Type.lookup( name: 'updated' )
|
||||||
history_attribute = History::Attribute.lookup( name: params[:attribute] )
|
history_attribute = History::Attribute.lookup( name: params[:attribute] )
|
||||||
|
|
||||||
|
result = nil
|
||||||
if !history_attribute || !history_type
|
if !history_attribute || !history_type
|
||||||
count = 0
|
result = 0
|
||||||
elsif params[:id_not_from] && params[:id_to]
|
elsif params[:id_not_from] && params[:id_to]
|
||||||
return History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id')
|
result = History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id')
|
||||||
.where(query, *bind_params).joins(tables)
|
.where(query, *bind_params).joins(tables)
|
||||||
.where(
|
.where(
|
||||||
'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.id_from NOT IN (?) AND histories.id_to IN (?)',
|
'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.id_from NOT IN (?) AND histories.id_to IN (?)',
|
||||||
params[:start],
|
params[:start],
|
||||||
params[:end],
|
params[:end],
|
||||||
history_object.id,
|
history_object.id,
|
||||||
history_type.id,
|
history_type.id,
|
||||||
history_attribute.id,
|
history_attribute.id,
|
||||||
params[:id_not_from],
|
params[:id_not_from],
|
||||||
params[:id_to],
|
params[:id_to],
|
||||||
).count
|
).count
|
||||||
elsif params[:id_from] && params[:id_not_to]
|
elsif params[:id_from] && params[:id_not_to]
|
||||||
return History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id')
|
result = History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id')
|
||||||
.where(query, *bind_params).joins(tables)
|
.where(query, *bind_params).joins(tables)
|
||||||
.where(
|
.where(
|
||||||
'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.id_from IN (?) AND histories.id_to NOT IN (?)',
|
'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.id_from IN (?) AND histories.id_to NOT IN (?)',
|
||||||
params[:start],
|
params[:start],
|
||||||
params[:end],
|
params[:end],
|
||||||
history_object.id,
|
history_object.id,
|
||||||
history_type.id,
|
history_type.id,
|
||||||
history_attribute.id,
|
history_attribute.id,
|
||||||
params[:id_from],
|
params[:id_from],
|
||||||
params[:id_not_to],
|
params[:id_not_to],
|
||||||
).count
|
).count
|
||||||
elsif params[:value_from] && params[:value_not_to]
|
elsif params[:value_from] && params[:value_not_to]
|
||||||
return History.joins('INNER JOIN tickets ON tickets.id = histories.o_id')
|
result = History.joins('INNER JOIN tickets ON tickets.id = histories.o_id')
|
||||||
.where(query, *bind_params).joins(tables)
|
.where(query, *bind_params).joins(tables)
|
||||||
.where(
|
.where(
|
||||||
'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.value_from IN (?) AND histories.value_to NOT IN (?)',
|
'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.value_from IN (?) AND histories.value_to NOT IN (?)',
|
||||||
params[:start],
|
params[:start],
|
||||||
params[:end],
|
params[:end],
|
||||||
history_object.id,
|
history_object.id,
|
||||||
history_type.id,
|
history_type.id,
|
||||||
history_attribute.id,
|
history_attribute.id,
|
||||||
params[:value_from],
|
params[:value_from],
|
||||||
params[:value_not_to],
|
params[:value_not_to],
|
||||||
).count
|
).count
|
||||||
elsif params[:value_to]
|
elsif params[:value_to]
|
||||||
return History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id')
|
result = History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id')
|
||||||
.where(query, *bind_params).joins(tables)
|
.where(query, *bind_params).joins(tables)
|
||||||
.where(
|
.where(
|
||||||
'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.value_to IN (?)',
|
'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.value_to IN (?)',
|
||||||
params[:start],
|
params[:start],
|
||||||
params[:end],
|
params[:end],
|
||||||
history_object.id,
|
history_object.id,
|
||||||
history_type.id,
|
history_type.id,
|
||||||
history_attribute.id,
|
history_attribute.id,
|
||||||
params[:value_to],
|
params[:value_to],
|
||||||
).count
|
).count
|
||||||
elsif params[:id_to]
|
elsif params[:id_to]
|
||||||
return History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id')
|
result = History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id')
|
||||||
.where(query, *bind_params).joins(tables)
|
.where(query, *bind_params).joins(tables)
|
||||||
.where(
|
.where(
|
||||||
'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.id_to IN (?)',
|
'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ? AND histories.history_attribute_id IN (?) AND histories.id_to IN (?)',
|
||||||
params[:start],
|
params[:start],
|
||||||
params[:end],
|
params[:end],
|
||||||
history_object.id,
|
history_object.id,
|
||||||
history_type.id,
|
history_type.id,
|
||||||
history_attribute.id,
|
history_attribute.id,
|
||||||
params[:id_to],
|
params[:id_to],
|
||||||
).count
|
).count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return result if !result.nil?
|
||||||
|
|
||||||
raise "UNKOWN params (#{params.inspect})!"
|
raise "UNKOWN params (#{params.inspect})!"
|
||||||
end
|
end
|
||||||
raise "UNKOWN :type (#{params[:type]})!"
|
raise "UNKOWN :type (#{params[:type]})!"
|
||||||
|
|
Loading…
Reference in a new issue