diff --git a/app/models/asset.rb b/app/models/asset.rb index f95259b55..8327e21bf 100644 --- a/app/models/asset.rb +++ b/app/models/asset.rb @@ -141,6 +141,10 @@ class Asset < ActiveRecord::Base !(self.file.content_type =~ /^image/).nil? end + def text? + TEXT_EXTRACT_FILE_TYPES.any? { |v| file_content_type.start_with? v } + end + # TODO: get the current_user # before_save do # if current_user @@ -158,7 +162,7 @@ class Asset < ActiveRecord::Base self.update(file_present: true) # Extract asset text if it's of correct type - if TEXT_EXTRACT_FILE_TYPES.any? { |v| file_content_type.start_with? v } + if text? Rails.logger.info "Asset #{id}: Creating extract text job" # The extract_asset_text also includes # estimated size calculation @@ -215,13 +219,19 @@ class Asset < ActiveRecord::Base # this automatically, so this is not needed in such cases) key = file.path[1..-1] S3_BUCKET.object(key).delete + Rails.logger.info "Asset #{id} (original): Asset file "\ + "successfully deleted from S3 (" + key.to_s + ')' if (file_content_type =~ %r{^image\/}) == 0 - file.options[:styles].each do |style| + file.options[:styles].each do |style, _| key = file.path(style)[1..-1] S3_BUCKET.object(key).delete + Rails.logger.info "Asset #{id} (" + style.to_s + '): Asset file '\ + 'successfully deleted from S3 (' + key.to_s + ')' end end + report_elements.destroy_all + asset_text_datum.destroy if asset_text_datum.present? delete end diff --git a/app/models/asset_text_datum.rb b/app/models/asset_text_datum.rb index 47d2f326e..e4471e4e0 100644 --- a/app/models/asset_text_datum.rb +++ b/app/models/asset_text_datum.rb @@ -3,7 +3,7 @@ class AssetTextDatum < ActiveRecord::Base validates :data, presence: true validates :asset, presence: true, uniqueness: true - belongs_to :asset + belongs_to :asset, inverse_of: :asset_text_datum after_save :update_ts_index diff --git a/app/models/result_asset.rb b/app/models/result_asset.rb index d683a9dca..a2411892e 100644 --- a/app/models/result_asset.rb +++ b/app/models/result_asset.rb @@ -2,8 +2,7 @@ class ResultAsset < ActiveRecord::Base validates :result, :asset, presence: true belongs_to :result, inverse_of: :result_asset - belongs_to :asset, inverse_of: :result_asset, - dependent: :destroy + belongs_to :asset, inverse_of: :result_asset, dependent: :destroy def space_taken asset.present? ? asset.estimated_size : 0