From 575530bfacac8f799230f4ce4781ddc7695506d4 Mon Sep 17 00:00:00 2001 From: Javi Fontan <jfontan@opennebula.org> Date: Fri, 27 Oct 2017 16:54:12 +0200 Subject: [PATCH] B #5492: change-body modifies db instead of API data (cherry picked from commit c631781bef710a50e6648f01ed274f07a91743dc) --- src/onedb/onedb_live.rb | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/onedb/onedb_live.rb b/src/onedb/onedb_live.rb index 360745008e..3cf5739308 100644 --- a/src/onedb/onedb_live.rb +++ b/src/onedb/onedb_live.rb @@ -343,8 +343,20 @@ class OneDBLive next unless check_expr(o, options[:expr]) end - o.info - doc = Nokogiri::XML(o.to_xml, nil, NOKOGIRI_ENCODING) do |c| + # Get body from the database + begin + db_data = select(table, "oid = #{o.id}") + rescue => e + STDERR.puts "Error getting object id #{o.id}" + STDERR.puts e.message + STDERR.puts e.backtrace + next + end + + row = db_data.first + body = Base64.decode64(row['body64']) + + doc = Nokogiri::XML(body, nil, NOKOGIRI_ENCODING) do |c| c.default_xml.noblanks end @@ -361,7 +373,14 @@ class OneDBLive if options[:dry] puts xml else - update_body(table, xml, "oid = #{o.id}", federate) + begin + update_body(table, xml, "oid = #{o.id}", federate) + rescue => e + STDERR.puts "Error updating object id #{o.id}" + STDERR.puts e.message + STDERR.puts e.backtrace + next + end end end end