Module: Pictrails::MassUpload

Included in:
Admin::BaseController
Defined in:
lib/pictrails/mass_upload.rb

Overview

Module to manage the mass_upload

Instance Method Summary collapse

Instance Method Details

#upload_fileObject

Check if an import exist still in database If an import exist, it’s factory Use RAILS_DEFAULT_LOGGER because we can be out of Rails class



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/pictrails/mass_upload.rb', line 10

def upload_file
  RAILS_DEFAULT_LOGGER.debug 'upload file launch'
  imports = Import.find :all, :include => 'gallery', 
    :limit => Setting.default.nb_upload_mass_by_request,
    :conditions => [ 'gallery_id IS NOT NULL']
  imports.each { |import|
    RAILS_DEFAULT_LOGGER.debug 'one pictures import'
    begin
      Picture.create_picture_by_import(import)
    rescue Errno::ENOENT
      RAILS_DEFAULT_LOGGER.warn 'A file in Import directory is bad. Send a bug report'
      import.destroy
    end
    PageCache.sweep_all
    import.destroy
  }
  @imports = Import.gallery_import.all.group_by(&:gallery)
end