Sha256: 096d86510166af97cb862b3a734d2895d992f0d4cc852ca3991f1997c8622e15

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

# == Schema Information
#
# Table name: xml_imports
#
#  id                 :integer          not null, primary key
#  xml_import_type_id :integer          default(1)
#  updated_count      :integer          default(0)
#  created_count      :integer          default(0)
#  created_at         :datetime
#  updated_at         :datetime
#

class XmlImport < ActiveRecord::Base
  enumerated_attribute :xml_import_type

  has_many :pictures, as: :assetable, dependent: :destroy
  has_one :attachment_file, as: :assetable, dependent: :destroy
  fileuploads :attachment_file

  after_save :start

  def title
    I18n.l(created_at, format: :long)
  end

  def kind
    xml_import_type.title
  end

  def start
    path = (attachment_file || AttachmentFile.where(guid: fileupload_guid).first).try(:data).try(:path)
    return nil if path.nil?

    response = case xml_import_type.code
               when :post then TranslationCms::Import::Post.start(path, self)
               when :sample then TranslationCms::Import::Sample.start(path, self)
    end

    update_column :updated_count, response.updated_count.to_i
    update_column :created_count, response.created_count.to_i
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
translation_cms-0.1.5 app/models/xml_import.rb