diff --git a/lib/licence_identifier_migrator.rb b/lib/licence_identifier_migrator.rb deleted file mode 100644 index d4b0d2094..000000000 --- a/lib/licence_identifier_migrator.rb +++ /dev/null @@ -1,37 +0,0 @@ -require "net/http" -require "uri" - -class LicenceIdentifierMigrator - LICENCE_MAPPING_URL = "https://raw.github.com/alphagov/licence-finder/correlation_id_migration/data/licence_gds_ids.yaml".freeze - - def self.update_all - counter = 0 - licence_mappings = mappings_as_hash - - LicenceEdition.all.each do |licence_edition| - licence_identifier = licence_mappings[licence_edition.licence_identifier.to_i] - if licence_identifier - licence_edition.licence_identifier = licence_identifier - if licence_edition.save(validate: false) - counter += 1 - end - end - done(counter, "\r") - end - done(counter, "\n") - end - - def self.mappings_as_hash - uri = URI.parse(LICENCE_MAPPING_URL) - http = Net::HTTP.new(uri.host, uri.port) - http.use_ssl = true - http.verify_mode = OpenSSL::SSL::VERIFY_PEER - request = Net::HTTP::Get.new(uri.request_uri) - response = http.request(request) - YAML.safe_load(response.body) - end - - def self.done(counter, line_ending) - Rails.logger.debug "Migrated #{counter} LicenceEditions.#{line_ending}" - end -end diff --git a/lib/tasks/licence_finder.rake b/lib/tasks/licence_finder.rake deleted file mode 100644 index 348c46c5e..000000000 --- a/lib/tasks/licence_finder.rake +++ /dev/null @@ -1,53 +0,0 @@ -def create_artefact! - artefact = Artefact.new( - content_id: "69af22e0-da49-4810-9ee4-22b4666ac627", - slug: "licence-finder", - name: "Licence finder", - owning_app: "publisher", - kind: "transaction", - state: "draft", - language: "en", - ) - - artefact.save! -end - -namespace :licence_finder do - desc "Create draft start page for licence finder" - task licence_finder_draft: :environment do - # Claim path - # https://github.com/alphagov/publishing-api/blob/master/doc/api.md#put-pathsbase_path - puts "Claiming path /licence-finder" - endpoint = Services.publishing_api.options[:endpoint_url] - Services.publishing_api.put_json("#{endpoint}/paths/licence-finder", publishing_app: "publisher", override_existing: true) - - # Delete existing artefact - # allowing us to create a new one at the right path - old_artefact = Artefact.where(slug: "licence-finder", owning_app: "licencefinder").first - if old_artefact - puts "Deleting existing artefact to allow creating a new one with path /licence-finder" - old_artefact.delete - end - - puts "Creating Artefact matching old content_id: 69af22e0-da49-4810-9ee4-22b4666ac627" - create_artefact! - puts "Artefact saved" - puts "Creating Edition from Artefact" - - current_user = User.where(name: "Paul Hayes").first - edition = Edition.find_or_create_from_panopticon_data(artefact.id.to_s, current_user) - overview = "Find out which licences you might need for your activity or business" - link = "/licence-finder/sectors" - introduction = "You may need a licence for:\r\n\r\n* some business activities\r\n* other activities, eg street parties\r\n\r\nUse this tool to find out which licences you may need." - - edition[:link] = link - edition[:introduction] = introduction - edition[:overview] = overview - - edition.save! - puts "Draft edition created: /editions/#{edition.id}" - - UpdateWorker.perform_async(edition.id.to_s) - puts "Pushing draft to publishing API: /licence-finder" - end -end diff --git a/lib/tasks/licence_identifier_migrate.rake b/lib/tasks/licence_identifier_migrate.rake deleted file mode 100644 index b1e11ecb7..000000000 --- a/lib/tasks/licence_identifier_migrate.rake +++ /dev/null @@ -1,11 +0,0 @@ -require "licence_identifier_migrator" - -desc "Maps old correlation_ids stored in the LicenceEdition licence_identifier field to legal_ref_ids" -task licence_identifier_migrate: ["licence_identifier_migrate:update_all"] - -namespace :licence_identifier_migrate do - desc "sub task to update licence_identifiers" - task update_all: :environment do - LicenceIdentifierMigrator.update_all - end -end diff --git a/test/unit/licence_identifier_migrator_test.rb b/test/unit/licence_identifier_migrator_test.rb deleted file mode 100644 index 111619be2..000000000 --- a/test/unit/licence_identifier_migrator_test.rb +++ /dev/null @@ -1,29 +0,0 @@ -require "test_helper" -require "licence_identifier_migrator" - -class LicenceIdentifierMigratorTest < ActiveSupport::TestCase - context "update_all" do - setup do - LicenceIdentifierMigrator.stubs(:mappings_as_hash).returns( - 1_083_741_393 => "123-1-1", - 1_083_741_799 => "146-7-1", - 1_084_062_157 => "898-1-1", - 1_075_329_002 => "999-4-1", - ) - @le1 = LicenceEdition.create!(licence_identifier: "1083741799", title: "Licence One", panopticon_id: FactoryBot.create(:artefact).id) - @le2 = LicenceEdition.create!(licence_identifier: "9999999999", title: "Licence Two", panopticon_id: FactoryBot.create(:artefact).id) - end - - should "update licence editions with a matching licence identifier" do - LicenceIdentifierMigrator.update_all - @le1.reload - assert_equal "146-7-1", @le1.licence_identifier - end - - should "ignore licence editions without a matching licence identifier" do - LicenceIdentifierMigrator.update_all - @le2.reload - assert_equal "9999999999", @le2.licence_identifier - end - end -end