require 'transition/import/mappings_from_host_paths'

namespace :import do
  desc 'Create mappings from HostPaths for a site'
  task :mappings_from_host_paths, [:site_abbr] => :environment do |_, args|
    site = Site.find_by_abbr(args[:site_abbr])
    raise "No site found for #{args[:site_abbr]}" unless site
    raise 'ABORT: This site is not managed by transition' unless site.managed_by_transition?

    if site.global_type
      STDOUT.flush
      STDOUT.puts "WARNING: This site has a global_type, so Bouncer will not use any mappings you create.\nDo you want to continue? (y/N)"
      input = STDIN.gets.chomp
      unless %w(y yes).include?(input)
        abort("Not creating mappings for site #{args[:site_abbr]} with global_type.")
      end
    end

    Transition::Import::MappingsFromHostPaths.refresh!(site)
    puts 'You may now want to run `rake import:hits_mappings_relations` to connect hits and any new mappings.'
  end
end

require 'transition/import/mappings_from_host_paths'

namespace :import do
  desc 'Create mappings from HostPaths for a site'
  task :mappings_from_host_paths, [:site_abbr] => :environment do |_, args|
    site = Site.find_by_abbr(args[:site_abbr])
    raise "No site found for #{args[:site_abbr]}" unless site

    if site.global_type
      STDOUT.flush
      STDOUT.puts "WARNING: This site has a global_type, so Bouncer will not use any mappings you create.\nDo you want to continue? (y/N)"
      input = STDIN.gets.chomp
      unless %w(y yes).include?(input)
        abort("Not creating mappings for site #{args[:site_abbr]} with global_type.")
      end
    end

    Transition::Import::MappingsFromHostPaths.refresh!(site)
    puts 'You may now want to run `rake import:hits_mappings_relations` to connect hits and any new mappings.'
  end
end

Remove a reference to managed_by_transition from an import rake task
Remove a reference to managed_by_transition from an import rake task

- A transtion-postgres Errbit error
  (https://errbit.preview.alphagov.co.uk/apps/53e8c4e40da115dfc200684d/problems/5425716e0da11550d7001181)
  made me do a full search
  everywhere. Clearly nothing has used this rake task since
  https://github.com/alphagov/transition/pull/413 otherwise
  Errbit would have caught the exception?
