module ClonesTicketArticleAttachments extend ActiveSupport::Concern private def article_attachments_clone(article) raise Exceptions::UnprocessableEntity, 'Need form_id to attach attachments to new form.' if params[:form_id].blank? existing_attachments = Store.list( object: 'UploadCache', o_id: params[:form_id], ) attachments = [] article.attachments.each do |new_attachment| next if new_attachment.preferences['Content-ID'].present? next if new_attachment.preferences['content-alternative'] == true already_added = false existing_attachments.each do |existing_attachment| next if existing_attachment.filename != new_attachment.filename || existing_attachment.size != new_attachment.size already_added = true break end next if already_added == true file = Store.add( object: 'UploadCache', o_id: params[:form_id], data: new_attachment.content, filename: new_attachment.filename, preferences: new_attachment.preferences, ) attachments.push file end attachments end end