fix minor bugs

This commit is contained in:
Adrian Hinz 2018-04-22 00:16:45 +02:00
parent ea10e38551
commit 1336cb995b
2 changed files with 22 additions and 21 deletions

View File

@ -1,13 +1,12 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
ENV["RAILS_ENV"] ||= "development" ENV['RAILS_ENV'] ||= 'development'
require File.dirname(__FILE__) + "/../config/environment" require File.dirname(__FILE__) + '/../config/environment'
# import images from old presta shop # import images from old presta shop
# images needs to be stored in public/tmp/original # images needs to be stored in public/tmp/original
class PsImage < ApplicationRecord class PsImage < ApplicationRecord
self.table_name = 'ps_image' self.table_name = 'ps_image'
establish_connection :prestashop_old establish_connection :prestashop_old
end end
@ -16,18 +15,17 @@ path = "#{Rails.root}/public/tmp/original/"
ps_images.each do |pi| ps_images.each do |pi|
file = "#{path}#{pi.id_product}-#{pi.id_image}.jpg" file = "#{path}#{pi.id_product}-#{pi.id_image}.jpg"
puts "#{file} - #{File.exist?(file)}" puts "#{file} - #{File.exist?(file)}"
if File.exist?(file) next unless File.exist?(file)
image = Image.new image = Image.new
f = File.open(file) f = File.open(file)
image.image = f image.image = f
f.close f.close
image.imageable_type = "Product" image.imageable_type = 'Product'
image.imageable_id = pi.id_product image.imageable_id = pi.id_product
image.position = pi.position image.position = pi.position
image.cover = pi.cover image.cover = pi.cover
image.updated_by = 1 image.updated_by = 1
image.active = true image.active = true
image.save image.save
puts "saved: #{image.id}" puts "saved: #{image.id}"
end
end end

View File

@ -1,9 +1,12 @@
# This file should contain all the record creation needed to seed the database with its default values. # This file should contain all the record creation needed to seed the
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). # 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: # 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) # Character.create(name: 'Luke', movie: movies.first)
admin = Admin.new admin = Admin.new