Commit 52a58802 authored by Enrique García's avatar Enrique García

finished licenses importer task

parent 25a87138
...@@ -10,10 +10,10 @@ end ...@@ -10,10 +10,10 @@ end
namespace :licenses do namespace :licenses do
desc "creates default licenses, imports them, and removes the license custom field from ohwr" desc "creates default licenses, imports them, and removes the license custom field from ohwr"
task :all => [:destroy_all, :create] task :all => [:reset, :create, :link, :remove_custom_field]
desc "destroys all licenses" desc "destroys all licenses"
task :destroy_all => :environment do task :reset => :environment do
License.destroy_all License.destroy_all
LicenseVersion.destroy_all LicenseVersion.destroy_all
...@@ -31,14 +31,24 @@ namespace :licenses do ...@@ -31,14 +31,24 @@ namespace :licenses do
create_license("CERN OHL", "cern-ohl", nil, "v1.1", Date.new(2011,7,8), nil) create_license("CERN OHL", "cern-ohl", nil, "v1.1", Date.new(2011,7,8), nil)
end end
desc "associates projects to the licenses they belong to" do desc "associates projects to the licenses they belong to"
task :link => :environment do
license_custom_field_id = CustomField.find_by_type_and_name("ProjectCustomField", "License").id
["GPL", "LGPL", "TAPR OHL", "CERN OHL"].each do |license_name| ["GPL", "LGPL", "TAPR OHL", "CERN OHL"].each do |license_name|
license = License.find_by_name(license_name) license = License.find_by_name(license_name)
license_version = license.license_versions.first license_version = license.versions.first
Project.with_custom_fields(:License => license_name).each do |p| Project.with_custom_values(license_custom_field_id => license_name).each do |p|
p.license = license.version writable_p = Project.find(p.id)
p.save writable_p.license = license_version
writable_p.save
end end
end end
end end
desc "removes the previous custom field"
task :remove_custom_field do
CustomField.destroy_all(:type => "ProjectCustomField", :name => "License")
end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment