mmsc_app/lib/tasks/qi.rake
Nicolas Bally f4ccdc82dc suite
2020-07-23 11:17:11 +02:00

167 lines
4.0 KiB
Ruby

namespace :qi do
desc "TODO"
task import_stickers: :environment do
@file = "#{Rails.root}/import_csv/stickers.csv"
require 'csv'
csv_text = File.read(@file, :encoding => 'UTF-8')
@csv = CSV.parse(csv_text, :headers => true, :col_sep => ";")
@csv.each do |csv|
if p_customer = PCustomer.joins(:particular).where("particulars.name = ? and particulars.firstname = ?", csv[0], csv["prenom"]).first
p_customer.sticker = true
p_customer.save
else
puts csv[0].to_s+ " "+csv["prenom"]
end
end
puts "Fin de l'import"
end
task migrate_all: :environment do
puts "test"
Dir["#{Rails.root.join('db','migrate')}/*"].sort.each do |mf|
version = mf.split('/')[-1].split('_')[0]
puts version
ENV['VERSION'] = version
Rake::Task["db:migrate"].execute
sleep(10)
end
end
task :import_photos_organisateurs => :environment do
if false
if album = Album.where(:name => "import logos organisateurs").first
else
album = Album.create(:name => "import logos organisateurs")
end
dir = "#{Rails.root.join('import_photos','ORGANISATEURS','LOGO')}/*"
Dir[dir].sort.each do |mf|
puts mf
id = File.basename(mf.to_s.gsub('_',""))
puts id
if organisateur = Organisateur.where(:id => id).first
image_file = ImageFile.new(:file => File.open(mf), :album_id => album.id)
if image_file.save
organisateur.logo = image_file
organisateur.save
else
puts image_file.errors.messages
end
end
end
else
if album = Album.where(:name => "import photos organisateurs").first
else
album = Album.create(:name => "import photos organisateurs")
end
dir = "#{Rails.root.join('import_photos','ORGANISATEURS','PHOTOS')}/*"
Dir[dir].sort.each do |mf|
puts mf
id = File.basename(mf.to_s.gsub('_',""))
puts id
if organisateur = Organisateur.where(:id => id).first
image_file = ImageFile.new(:file => File.open(mf), :album_id => album.id)
if image_file.save
organisateur.image_file = image_file
organisateur.save
else
puts image_file.errors.messages
end
end
end
end
end
task :import_photos_circuits => :environment do
if true
if album = Album.where(:name => "import logos circuits").first
else
album = Album.create(:name => "import logos circuits")
end
dir = "#{Rails.root.join('import_photos','CIRCUITS','LOGO')}/*"
Dir[dir].sort.each do |mf|
puts mf
id = File.basename(mf.to_s.gsub('_',""))
puts id
if organisateur = Circuit.where(:id => id).first
image_file = ImageFile.new(:file => File.open(mf), :album_id => album.id)
if image_file.save
organisateur.logo = image_file
organisateur.save
else
puts image_file.errors.messages
end
end
end
else
if album = Album.where(:name => "import photos circuits").first
else
album = Album.create(:name => "import photos circuits")
end
dir = "#{Rails.root.join('import_photos','CIRCUITS','PHOTOS')}/*"
Dir[dir].sort.each do |mf|
puts mf
id = File.basename(mf.to_s.gsub('_',""))
puts id
if organisateur = Circuit.where(:id => id).first
image_file = ImageFile.new(:file => File.open(mf), :album_id => album.id)
if image_file.save
organisateur.image_file = image_file
organisateur.save
else
puts image_file.errors.messages
end
end
end
end
end
end