Skip to content

Commit

Permalink
Merge pull request #3342 from CartoDB/3286-fix-undefined-method-scrol…
Browse files Browse the repository at this point in the history
…lwheel

Script to delete inconsistent vizs #3286
  • Loading branch information
Rafa de la Torre committed Apr 23, 2015
2 parents 7a2e3e2 + 4f9eee3 commit c0aeef6
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions lib/tasks/viz_maintenance.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
namespace :cartodb do
namespace :vizs do

desc "Purges broken visualizations due to bug during deletion."
task :delete_inconsistent, [:username] => :environment do |t, args|
username = args[:username]
raise "You should pass a username param" unless username
user = User[username: username]
collection = CartoDB::Visualization::Collection.new.fetch(user_id: user.id)

collection.each do |viz|
if is_inconsistent?(viz)
delete_with_confirmation(viz)
end
end
end

def is_inconsistent?(viz)
(viz.table? && viz.related_tables.empty?) || (viz.derived? && viz.map.nil?)
end

def delete_with_confirmation(viz)
display_info(viz)
if ok_to_delete?
viz.delete
STDOUT.puts "deleted!"
end
end

def display_info(viz)
STDOUT.puts "\nviz.name = #{viz.name}"
STDOUT.puts "viz.type = #{viz.type}"
STDOUT.puts "viz.related_tables = #{viz.related_tables.map {|t| t.name}}"
STDOUT.puts "viz.map_id = #{viz.map_id}"
end

def ok_to_delete?
STDOUT.puts "About to delete. Are you sure? (y/n)"
input = STDIN.gets.strip
return input == 'y'
end

end
end

0 comments on commit c0aeef6

Please sign in to comment.