Skip to content

Commit

Permalink
Merge pull request #233 from b123400/fix-231-2
Browse files Browse the repository at this point in the history
Add more log for image extraction
  • Loading branch information
zdavatz authored Dec 31, 2023
2 parents 1ced1ad + 22116b3 commit ccd8f04
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/model/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Text
class ImageLink
attr_accessor :src, :style
def attributes
{ 'src' => @src, 'style' => @style }
{ 'src' => @src, 'style' => @style, 'alt' => '' }
end
def clean!
end
Expand Down
24 changes: 19 additions & 5 deletions src/plugin/text_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,7 @@ def store_patinfo_change_diff(patinfo, lang, new_patinfo_lang)
if old_text.eql?(new_patinfo_lang.to_s)
LogFile.debug "store_patinfo_change_diff: #{lang} skip #{patinfo.odba_id} eql? #{old_text.eql?(new_patinfo_lang)} size #{old_size}"
else
new_patinfo_lang.change_log = patinfo.description(lang).change_log
new_patinfo_lang.add_change_log_item(old_text, new_patinfo_lang)
new_patinfo_lang.odba_store
patinfo.descriptions[lang] = new_patinfo_lang
diff_item = patinfo.description(lang).add_change_log_item(old_text, new_patinfo_lang)
patinfo.odba_store
LogFile.debug "store_patinfo_change_diff: #{lang} #{patinfo.odba_id} eql? #{old_text.eql?(new_patinfo_lang)} size #{old_size} -> #{patinfo.description(lang).change_log.size}"
end
Expand All @@ -317,6 +314,10 @@ def store_package_patinfo(package, lang, patinfo_lang)
package.patinfo.odba_store
end if package.patinfo && package.patinfo.is_a?(ODDB::Patinfo)
if package.patinfo && package.patinfo.is_a?(ODDB::Patinfo) && package.patinfo.descriptions[lang]
old_ti = package.patinfo; Languages.each do |old_lang|
next if old_lang.eql?(lang)
eval("package.patinfo.descriptions['#{old_lang}']= old_ti.descriptions['#{old_lang}']")
end
msg += ' change_diff'
store_patinfo_change_diff(package.patinfo, lang, patinfo_lang)
elsif package.patinfo && package.patinfo.is_a?(ODDB::Patinfo) && package.patinfo.descriptions.is_a?(Hash)
Expand Down Expand Up @@ -903,6 +904,7 @@ def match(node_set, iksnr)
return name
end
def extract_image(html_file, name, type, lang, iksnrs)
LogFile.debug "Extracting image to #{name}"
if html_file && File.exist?(html_file)
resource_dir = (File.join(ODDB::IMAGE_DIR, type.to_s, lang.to_s))
FileUtils.mkdir_p(resource_dir)
Expand Down Expand Up @@ -1274,7 +1276,7 @@ def parse_textinfo(meta_info)
return
end
styles = res[1]
extract_image(html_name, meta_info.title, meta_info.type, meta_info.lang, meta_info.authNrs)
textinfo_pi_name = nil
if type == :fi
if is_same_html && !@options[:reparse] && reg && reg.fachinfo && text_info.descriptions.keys.index(meta_info.lang)
LogFile.debug "parse_textinfo #{__LINE__} #{meta_info.iksnr} at #{nr_uptodate}: #{type} #{html_name} is_same_html #{html_name}"
Expand All @@ -1292,8 +1294,20 @@ def parse_textinfo(meta_info)
end
textinfo_pi = @parser.parse_patinfo_html(html_name, @format, meta_info.title, styles)
update_patinfo_lang(meta_info, { meta_info.lang => textinfo_pi } )
if textinfo_pi.respond_to?(:name)
textinfo_pi_name = textinfo_pi.name
end
textinfo_pi = nil
end
# Extract image to path generated from XML title,
# This should be the "correct" path
extract_image(html_name, meta_info.title, meta_info.type, meta_info.lang, meta_info.authNrs)
# However, ODBA is always buggy, sometimes it just doesn't like saving objects #231
# There's case which the Html pointed the image to a wrong path, and we cannot update
# the HTML because ODBA's problem, so here we extract image to path generated from the wrong H1 title,
if !textinfo_pi_name.nil?
extract_image(html_name, textinfo_pi_name.to_s, meta_info.type, meta_info.lang, meta_info.authNrs)
end
LogFile.debug "parse_textinfo #{__LINE__} at #{nr_uptodate}: #{type} textinfo #{textinfo.to_s.split("\n")[0..2]}" if self.respond_to?(:textinfo)
if reg
reg.odba_store
Expand Down
3 changes: 2 additions & 1 deletion test/test_model/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def test_attributes
@link.src = '/foo/bar.gif'
expected = {
'src' => '/foo/bar.gif',
'style' => nil
'style' => nil,
'alt' => ''
}
assert_equal(expected, @link.attributes)
end
Expand Down

0 comments on commit ccd8f04

Please sign in to comment.