This repository has been archived by the owner on Oct 12, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac44634
commit 7ba9a2f
Showing
5 changed files
with
28 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,30 @@ | ||
namespace :needs do | ||
require 'csv' | ||
|
||
require 'csv' | ||
require 'ansi/code' | ||
|
||
task :import_csv => :environment do | ||
|
||
@artefacts = CSV.read( File.join( Rails.root, 'lib', 'import', '20111129_need_ids.csv' ) ).collect{ |row| { :artefact_id => row[0].to_i, :need_id => row[2] } } | ||
@artefacts.each_with_index do |a, i| | ||
@artefacts.each_with_index do |a, i| | ||
puts "[#{i+1}/#{@artefacts.size}] Looking for artefact #{a[:artefact_id]}..." | ||
record = Artefact.find(a[:artefact_id].to_i) rescue nil | ||
record = Artefact.find(a[:artefact_id].to_i) rescue nil | ||
|
||
if (a[:need_id].match(/delete/i) rescue false) || (a[:need_id].match(/Not found/i) rescue false) | ||
print "\t----> #{ANSI.cyan('Need is marked for deletion, skipping.')}\n" | ||
elsif a[:need_id].to_i == 0 | ||
print "\t----> #{ANSI.red('No need ID specified in the CSV.')}\n" | ||
elsif record | ||
print "\t----> Updating artefact #{a[:artefact_id]}: " | ||
if record.update_attribute('need_id', a[:need_id]) | ||
if record.update_attribute('need_id', a[:need_id]) | ||
print ANSI.green("Success!\n") | ||
else | ||
print ANSI.red("Failed\n") | ||
end | ||
end | ||
else | ||
print "\t----> #{ANSI.red('Could not find artefact.')}\n" | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters