48 lines
1.9 KiB
Ruby
48 lines
1.9 KiB
Ruby
namespace :matchlivetv do
|
|
desc "Svuota MatchLiveTV e importa il foglio Campagna 100"
|
|
task reset_campaign: :environment do
|
|
path = ENV["CAMPAIGN_CSV"].presence ||
|
|
Rails.root.join("db/data/matchlivetv_campagna_100.csv")
|
|
user = User.find_by(email: "admin@simplecrm.local") || User.find_by!(role: "admin")
|
|
project = Project.find_by!(code: "matchlivetv")
|
|
|
|
puts "File: #{path}"
|
|
result = CampaignImport::MatchlivetvLaunch.new(path: path, user: user, project: project, wipe: true).call
|
|
puts "Organizzazioni rimosse dal solo MatchLiveTV: #{result.wiped_organizations}"
|
|
puts "Società importate: #{result.imported}"
|
|
if result.errors.any?
|
|
puts "Errori: #{result.errors.size}"
|
|
result.errors.first(10).each { |err| puts " riga #{err[:line]} #{err[:name]}: #{err[:message]}" }
|
|
abort "Import incompleto"
|
|
end
|
|
end
|
|
|
|
desc "Importa un foglio campagna senza cancellare le società già in CRM"
|
|
task import_campaign: :environment do
|
|
path = ENV["CAMPAIGN_CSV"].presence or abort "Imposta CAMPAIGN_CSV"
|
|
sport = ENV["SPORT"].presence or abort "Imposta SPORT (es. Calcio a 5)"
|
|
campaign = ENV["CAMPAIGN_NAME"].presence || "Campagna #{sport}"
|
|
user = User.find_by(email: "admin@simplecrm.local") || User.find_by!(role: "admin")
|
|
project = Project.find_by!(code: "matchlivetv")
|
|
|
|
puts "File: #{path}"
|
|
puts "Sport: #{sport}"
|
|
puts "Campagna: #{campaign}"
|
|
result = CampaignImport::MatchlivetvLaunch.new(
|
|
path: path,
|
|
user: user,
|
|
project: project,
|
|
wipe: false,
|
|
sport: sport,
|
|
campaign_name: campaign
|
|
).call
|
|
puts "Società importate: #{result.imported}"
|
|
puts "Duplicati saltati: #{result.skipped}"
|
|
if result.errors.any?
|
|
puts "Errori: #{result.errors.size}"
|
|
result.errors.first(10).each { |err| puts " riga #{err[:line]} #{err[:name]}: #{err[:message]}" }
|
|
abort "Import incompleto"
|
|
end
|
|
end
|
|
end
|