2016-10-19 03:11:36 +00:00
|
|
|
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
|
2015-04-27 23:19:26 +00:00
|
|
|
module Ticket::SearchIndex
|
2018-04-26 08:55:53 +00:00
|
|
|
extend ActiveSupport::Concern
|
2014-01-27 22:59:41 +00:00
|
|
|
|
|
|
|
=begin
|
|
|
|
|
2016-07-06 06:13:44 +00:00
|
|
|
lookup name of ref. objects
|
2014-01-27 22:59:41 +00:00
|
|
|
|
|
|
|
ticket = Ticket.find(123)
|
2016-07-06 06:13:44 +00:00
|
|
|
result = ticket.search_index_attribute_lookup
|
2014-01-27 22:59:41 +00:00
|
|
|
|
|
|
|
returns
|
|
|
|
|
2016-07-06 06:13:44 +00:00
|
|
|
attributes # object with lookup data
|
2014-01-27 22:59:41 +00:00
|
|
|
|
|
|
|
=end
|
|
|
|
|
2016-07-06 06:13:44 +00:00
|
|
|
def search_index_attribute_lookup
|
|
|
|
attributes = super
|
|
|
|
return if !attributes
|
2015-04-27 23:19:26 +00:00
|
|
|
|
2016-07-06 06:13:44 +00:00
|
|
|
# collect article data
|
2015-04-27 23:19:26 +00:00
|
|
|
# add tags
|
2017-04-12 07:34:49 +00:00
|
|
|
tags = tag_list
|
2016-12-02 11:24:00 +00:00
|
|
|
if tags.present?
|
2018-07-04 16:24:51 +00:00
|
|
|
attributes[:tags] = tags
|
2015-04-27 23:19:26 +00:00
|
|
|
end
|
2015-04-05 23:28:52 +00:00
|
|
|
|
2015-04-27 23:19:26 +00:00
|
|
|
# list ignored file extentions
|
|
|
|
attachments_ignore = Setting.get('es_attachment_ignore') || [ '.png', '.jpg', '.jpeg', '.mpeg', '.mpg', '.mov', '.bin', '.exe' ]
|
2014-01-27 22:59:41 +00:00
|
|
|
|
2015-04-27 23:19:26 +00:00
|
|
|
# max attachment size
|
2018-11-15 09:52:42 +00:00
|
|
|
attachment_max_size_in_mb = Setting.get('es_attachment_max_size_in_mb') || 10
|
|
|
|
attachment_total_max_size_in_kb = 314_572
|
|
|
|
attachment_total_max_size_in_kb_current = 0
|
2015-04-05 23:28:52 +00:00
|
|
|
|
2015-04-27 23:19:26 +00:00
|
|
|
# collect article data
|
2018-11-15 09:52:42 +00:00
|
|
|
articles = Ticket::Article.where(ticket_id: id).limit(1000)
|
2016-09-09 21:10:27 +00:00
|
|
|
attributes['article'] = []
|
2017-10-01 12:25:52 +00:00
|
|
|
articles.each do |article|
|
2017-10-15 22:16:37 +00:00
|
|
|
|
|
|
|
# lookup attributes of ref. objects (normally name and note)
|
|
|
|
article_attributes = article.search_index_attribute_lookup
|
2015-04-05 23:28:52 +00:00
|
|
|
|
2015-04-27 23:19:26 +00:00
|
|
|
# remove note needed attributes
|
2017-12-04 00:24:58 +00:00
|
|
|
ignore = %w[message_id_md5 ticket]
|
2017-10-01 12:25:52 +00:00
|
|
|
ignore.each do |attribute|
|
2016-07-06 06:13:44 +00:00
|
|
|
article_attributes.delete(attribute)
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2014-02-02 18:58:59 +00:00
|
|
|
|
2015-04-27 23:19:26 +00:00
|
|
|
# index raw text body
|
|
|
|
if article_attributes['content_type'] && article_attributes['content_type'] == 'text/html' && article_attributes['body']
|
|
|
|
article_attributes['body'] = article_attributes['body'].html2text
|
|
|
|
end
|
2015-04-27 21:27:51 +00:00
|
|
|
|
2015-04-27 23:19:26 +00:00
|
|
|
# lookup attachments
|
2017-12-04 00:24:58 +00:00
|
|
|
article_attributes['attachment'] = []
|
2018-11-15 09:52:42 +00:00
|
|
|
if attachment_total_max_size_in_kb_current < attachment_total_max_size_in_kb
|
|
|
|
article.attachments.each do |attachment|
|
2015-04-05 23:28:52 +00:00
|
|
|
|
2018-11-15 09:52:42 +00:00
|
|
|
# check file size
|
|
|
|
next if !attachment.content
|
|
|
|
next if attachment.content.size / 1024 > attachment_max_size_in_mb * 1024
|
2015-05-07 09:04:40 +00:00
|
|
|
|
2018-11-15 09:52:42 +00:00
|
|
|
# check ignored files
|
|
|
|
next if !attachment.filename
|
2015-05-07 09:04:40 +00:00
|
|
|
|
2018-11-15 09:52:42 +00:00
|
|
|
filename_extention = attachment.filename.downcase
|
|
|
|
filename_extention.gsub!(/^.*(\..+?)$/, '\\1')
|
2015-05-07 09:04:40 +00:00
|
|
|
|
2018-11-15 09:52:42 +00:00
|
|
|
next if attachments_ignore.include?(filename_extention.downcase)
|
2015-05-07 09:04:40 +00:00
|
|
|
|
2018-11-15 09:52:42 +00:00
|
|
|
attachment_total_max_size_in_kb_current += (attachment.content.size / 1024).to_i
|
|
|
|
next if attachment_total_max_size_in_kb_current > attachment_total_max_size_in_kb
|
|
|
|
|
|
|
|
data = {
|
|
|
|
'_name' => attachment.filename,
|
|
|
|
'_content' => Base64.encode64(attachment.content).delete("\n")
|
|
|
|
}
|
|
|
|
article_attributes['attachment'].push data
|
|
|
|
end
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2016-09-09 21:10:27 +00:00
|
|
|
attributes['article'].push article_attributes
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2014-01-27 22:59:41 +00:00
|
|
|
|
2016-07-06 06:13:44 +00:00
|
|
|
attributes
|
2014-01-27 22:59:41 +00:00
|
|
|
end
|
2016-07-06 06:13:44 +00:00
|
|
|
|
2015-04-27 14:15:29 +00:00
|
|
|
end
|