diff --git a/bin/import_images_from_ps.rb b/bin/import_images_from_ps.rb index e1ab940..0bad06a 100644 --- a/bin/import_images_from_ps.rb +++ b/bin/import_images_from_ps.rb @@ -1,13 +1,12 @@ #!/usr/bin/env ruby -ENV["RAILS_ENV"] ||= "development" -require File.dirname(__FILE__) + "/../config/environment" +ENV['RAILS_ENV'] ||= 'development' +require File.dirname(__FILE__) + '/../config/environment' # import images from old presta shop # images needs to be stored in public/tmp/original - class PsImage < ApplicationRecord - self.table_name = 'ps_image' + self.table_name = 'ps_image' establish_connection :prestashop_old end @@ -16,18 +15,17 @@ path = "#{Rails.root}/public/tmp/original/" ps_images.each do |pi| file = "#{path}#{pi.id_product}-#{pi.id_image}.jpg" puts "#{file} - #{File.exist?(file)}" - if File.exist?(file) - image = Image.new - f = File.open(file) - image.image = f - f.close - image.imageable_type = "Product" - image.imageable_id = pi.id_product - image.position = pi.position - image.cover = pi.cover - image.updated_by = 1 - image.active = true - image.save - puts "saved: #{image.id}" - end + next unless File.exist?(file) + image = Image.new + f = File.open(file) + image.image = f + f.close + image.imageable_type = 'Product' + image.imageable_id = pi.id_product + image.position = pi.position + image.cover = pi.cover + image.updated_by = 1 + image.active = true + image.save + puts "saved: #{image.id}" end diff --git a/db/seeds.rb b/db/seeds.rb index 938a247..14259b4 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,9 +1,12 @@ -# This file should contain all the record creation needed to seed the database with its default values. -# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). +# This file should contain all the record creation needed to seed the +# database with its default values. +# The data can then be loaded with the rails db:seed command +# (or created alongside the database with db:setup). # # Examples: # -# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) +# movies = +# Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) # Character.create(name: 'Luke', movie: movies.first) admin = Admin.new