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
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

View File

@ -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