app/models/upload.rb
#
# Updates the associated content for the upload with the content of the file from the blockchain. This only works for content of an appropriate type.
#
Updates the associated content for the upload with the content of the file from the blockchain. This only works for content of an appropriate type.
Updates the associated content for the upload with the content of the file from the blockchain . This only works for content of an appropriate type .
def update_content!
    result = false
    if self&.file_type&.convert_to_content?
      content = self.download_from_blockchain!
      if content && content[:io] && content[:file]
        ActiveRecord::Base.transaction do
          self.contents.destroy_all
          lines = content[:file].convert(content[:io])
          lines.each_with_index do |line, i|
            content = self.contents.new(sequence: i)
            line.each_with_index do |value, j|
              content[Content.field_index_to_sym(j)] = value
            end
            content.save!
            result = true
          end
          self.update!(retrieved_at: Time.current)
        end
      end
    else
      result = true
    end
    result
  end
def update_content! result = false if self &. file_type &. convert_to_content? content = self . download_from_blockchain! if content && content [ :io ] && content [ :file ] ActiveRecord :: Base . transaction do self . contents . destroy_all lines = content [ :file ] . convert ( content [ :io ] ) lines . each_with_index do | line , i | content = self . contents . new ( sequence : i ) line . each_with_index do | value , j | content [ Content . field_index_to_sym ( j ) ] = value end content . save! result = true end self . update! ( retrieved_at : Time . current ) end end else result = true end result end
Updates the associated content for the upload with the content of the file from the blockchain.
Updates the associated content for the upload with the content of the file from the blockchain .
# Destroy all existing content for the upload. # Update the content from the downloaded file.