aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/import/base.rb
blob: 82494b1dce65df9bd6780b26d8ac5a8e005dd6cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
class Import::Base < ApplicationModel
  self.table_name = "imports"
  validates :file, presence: true

  def self.messages_class_name
    "Import::Message"
  end

  def self.resources_class_name
    "Import::Resource"
  end

  def self.file_extension_whitelist
    %w(zip)
  end

  include IevInterfaces::Task

  def self.model_name
    ActiveModel::Name.new Import::Base, Import::Base, "Import"
  end

  def child_change
    Rails.logger.info "child_change for #{inspect}"
    return if self.class.finished_statuses.include?(status)

    super
    update_referentials
  end

  def update_referentials
    Rails.logger.info "update_referentials for #{inspect}"
    return unless self.class.finished_statuses.include?(status)

    children.each do |import|
      import.referential.update(ready: true) if import.referential
    end
  end

  private

  def initialize_fields
    super
    self.token_download = SecureRandom.urlsafe_base64
  end

end