namespace :db do namespace :artist do desc 'Fix broken imports' task :fix => :environment do Artist.where(:status => [0, 2]).each do |artist| artist.albums.each do |album| album.destroy end puts artist.name+(artist.mbid.nil? or artist.mbid.empty? ? '' : ' ('+artist.mbid+')') res = ImportController.importArtist(artist.name) if res == 1 puts 'OK' elsif res == 2 puts 'FAIL' elsif res == 3 puts 'SKIP' end puts '' end end end end