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

finished licenses importer task

parent 25a87138
......@@ -10,10 +10,10 @@ end
namespace :licenses do
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"
task :destroy_all => :environment do
task :reset => :environment do
License.destroy_all
LicenseVersion.destroy_all
......@@ -31,14 +31,24 @@ namespace :licenses do
create_license("CERN OHL", "cern-ohl", nil, "v1.1", Date.new(2011,7,8), nil)
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|
license = License.find_by_name(license_name)
license_version = license.license_versions.first
Project.with_custom_fields(:License => license_name).each do |p|
p.license = license.version
p.save
license_version = license.versions.first
Project.with_custom_values(license_custom_field_id => license_name).each do |p|
writable_p = Project.find(p.id)
writable_p.license = license_version
writable_p.save
end
end
end
desc "removes the previous custom field"
task :remove_custom_field do
CustomField.destroy_all(:type => "ProjectCustomField", :name => "License")
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