lib/daengine/teamsite_metadata_parser.rb in daengine-0.3.9.4 vs lib/daengine/teamsite_metadata_parser.rb in daengine-0.3.9.5
- old
+ new
@@ -88,18 +88,19 @@
delete_count += 1
elsif (assets[key]['expires_at'].nil? || (assets[key]['expires_at'] < 1.minute.from_now))
DigitalAsset.where(guid: key).try :delete_all
delete_count += 1
else
- asset_docs = trim_package(assets[key]['documents_attributes'], last_read)
da = DigitalAsset.find_or_initialize_by(guid: key)
+ asset_docs = trim_package(assets[key]['documents_attributes'], last_read, da)
if (!asset_docs.empty?)
assets[key]['documents_attributes'] = asset_docs
+ assets[key]['orderable'] = da.orderable unless da.new?
+
creating = da.new?
da.documents = []
begin
- assets[key].each { |k,v| assets[key][k] = da.orderable if k == 'orderable'}
da.update_attributes!(assets[key])
rescue Exception => e
error_files << "#{e} ---- #{da.try(:guid)}, #{da.try(:errors).try(:full_messages)}"
end
creating ? added_count += 1 : update_count += 1
@@ -122,11 +123,11 @@
DigitalAsset.purge! # if the purge criteria is met, purge anything not updated
Daengine.log("TeamsiteMetadataParser: #{added_count} records added, #{update_count} updated, #{delete_count} removed", "info")
end
end
- def self.trim_package(asset_docs, last_read = nil)
+ def self.trim_package(asset_docs, last_read = nil, existing_da = nil)
docs = []
path = Daengine.config[:digital_assets_file_directory]
if Dir.exist?(path) # dont throw away assets if we can't locate the dir
asset_docs.each do |doc|
#exclude manifest_file
@@ -139,16 +140,29 @@
begin
exifdata = ::MiniExiftool.new(file) # spaces in filename
pages = exifdata.pagecount
pages = exifdata.pages if pages.blank?
pages = exifdata.slides if pages.blank?
+ if(pages.blank?)
+ Daengine.log "Unable to get pages metadata for #{file}, exifdata.pagecount = #{exifdata.pagecount}, exifdata.pages = #{exifdata.pages}", "info"
+ end
doc['pages'] = pages
doc['size'] = exifdata.filesize
doc['mime_type'] = exifdata.mimetype
Daengine.log "Exif data for #{file} was pages:#{doc['pages']}, size:#{doc['size']}", "info"
rescue Exception => e
Daengine.log "Error reading metadata from #{file} #{e.message}", "error"
end
+ elsif(existing_da && !existing_da.new?) # copy over the existing asset metadata
+ existing_doc = existing_da.documents.where(path: doc['path'])[0]
+ if(existing_doc)
+ doc['pages'] = existing_doc.pages
+ doc['size'] = existing_doc.size
+ doc['mime_type'] = existing_doc.mime_type
+ else
+ Daengine.log "Unable to find document with path #{file} on existing asset #{existing_da.guid} title: #{existing_da.title}", "info"
+ end
+ Daengine.log "Saving existing pages #{existing_doc.pages} and size #{existing_doc.size} on #{file}", "info"
end
else
# the file was missing on disk, show a warning!
Daengine.log("TeamsiteMetadataParser: Unable to locate file #{file} on disk! Removing from metadata", "warn")
end
\ No newline at end of file