Merge pull request #6986 from SuperTux88/cleanup-rake-tasks
Cleanup old rake tasks
This commit is contained in:
commit
e712e4c92f
4 changed files with 5 additions and 229 deletions
|
|
@ -1,15 +0,0 @@
|
||||||
namespace :accounts do
|
|
||||||
desc "Run deletions"
|
|
||||||
task :run_deletions => :environment do
|
|
||||||
if ::AccountDeletion.uncompleted.count > 0
|
|
||||||
puts "Running account deletions.."
|
|
||||||
::AccountDeletion.uncompleted.find_each do |account_delete|
|
|
||||||
account_delete.perform!
|
|
||||||
end
|
|
||||||
puts "OK."
|
|
||||||
else
|
|
||||||
puts "No acccount deletions to run."
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
@ -3,92 +3,15 @@
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
namespace :db do
|
namespace :db do
|
||||||
desc "rebuild and prepare test db"
|
desc "Reset the current RAILS_ENV database and delete the upload-folder"
|
||||||
task :rebuild do
|
|
||||||
Rake::Task['db:drop'].invoke
|
|
||||||
Rake::Task['db:drop_integration'].invoke
|
|
||||||
Rake::Task['db:create'].invoke
|
|
||||||
Rake::Task['db:migrate'].invoke
|
|
||||||
puts "seeding users, this will take awhile"
|
|
||||||
`rake db:seed` #ghetto hax as we have active record garbage in our models
|
|
||||||
puts "seeded!"
|
|
||||||
Rake::Task['db:test:prepare'].invoke
|
|
||||||
end
|
|
||||||
|
|
||||||
namespace :integration do
|
|
||||||
# desc 'Check for pending migrations and load the integration schema'
|
|
||||||
task :prepare => :environment do
|
|
||||||
abcs = ActiveRecord::Base.configurations
|
|
||||||
envs = abcs.keys.select{ |k| k.include?("integration") }
|
|
||||||
puts envs.inspect
|
|
||||||
envs.each_with_index do |env, i|
|
|
||||||
Rails.env = env
|
|
||||||
Rake::Task.tasks.each{ |task| task.reenable }
|
|
||||||
|
|
||||||
print "\n\n## preparing database for #{env}... "
|
|
||||||
puts (i == 0) ? "(go get yourself a coffee)" : "(time for another coffee)"
|
|
||||||
|
|
||||||
# do drop, schema:load_if_ruby, structure:load_if_sql, seed
|
|
||||||
Rake::Task['db:drop'].invoke
|
|
||||||
Rake::Task['db:setup'].invoke
|
|
||||||
|
|
||||||
puts "db #{ActiveRecord::Base.connection.current_database} done"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
desc 'Delete the collections in the current RAILS_ENV database'
|
|
||||||
task :purge do
|
task :purge do
|
||||||
require File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment')
|
require File.join(File.dirname(__FILE__), "..", "..", "config", "environment")
|
||||||
|
|
||||||
puts "Purging the database for #{Rails.env}..."
|
puts "Purging the database for #{Rails.env}..."
|
||||||
|
|
||||||
Rake::Task['db:rebuild'].invoke
|
Rake::Task["db:reset"].invoke
|
||||||
|
|
||||||
puts 'Deleting tmp folder...'
|
puts "Deleting tmp folder..."
|
||||||
`rm -rf #{File.dirname(__FILE__)}/../../public/uploads/*`
|
`rm -rf #{File.dirname(__FILE__)}/../../public/uploads/*`
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Purge and seed the current RAILS_ENV database using information from db/seeds.rb'
|
|
||||||
task :reset do
|
|
||||||
puts "Resetting the database for #{Rails.env}".upcase
|
|
||||||
Rake::Task['db:purge'].invoke
|
|
||||||
Rake::Task['db:seed'].invoke
|
|
||||||
puts "Success!"
|
|
||||||
end
|
|
||||||
|
|
||||||
task :drop_integration do
|
|
||||||
ActiveRecord::Base.configurations.keys.select{ |k|
|
|
||||||
k.include?("integration")
|
|
||||||
}.each{ |k|
|
|
||||||
drop_database ActiveRecord::Base.configurations[k] rescue Mysql2::Error
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
task :fix_diaspora_handle do
|
|
||||||
puts "fixing the people in this seed"
|
|
||||||
require File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment')
|
|
||||||
Person.where(:url => 'example.org').all.each{|person|
|
|
||||||
if person.owner
|
|
||||||
person.url = AppConfig.pod_uri.to_s
|
|
||||||
person.diaspora_handle = person.owner.diaspora_handle
|
|
||||||
person.save
|
|
||||||
end
|
|
||||||
}
|
|
||||||
puts "everything should be peachy"
|
|
||||||
end
|
|
||||||
|
|
||||||
task :move_private_key do
|
|
||||||
require File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment')
|
|
||||||
User.all.each do |user|
|
|
||||||
if user.serialized_private_key.nil?
|
|
||||||
user.serialized_private_key = user.person.serialized_key
|
|
||||||
user.save
|
|
||||||
person = user.person
|
|
||||||
person.serialized_key = nil
|
|
||||||
person.serialized_public_key = user.encryption_key.public_key.to_s
|
|
||||||
person.save
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,40 +3,6 @@
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
namespace :maintenance do
|
namespace :maintenance do
|
||||||
APP_ROOT = File.expand_path( File.join( File.dirname( __FILE__ ), '..', '..') )
|
|
||||||
desc "Clear CarrierWave temp uploads"
|
|
||||||
task :clear_carrierwave_temp_uploads do
|
|
||||||
filename = File.join( APP_ROOT, 'tmp', 'uploads', '*')
|
|
||||||
today_string = Time.now.strftime( '%Y%m%d' )
|
|
||||||
Dir.glob( filename ) do |file|
|
|
||||||
unless file.include?( today_string )
|
|
||||||
FileUtils.rm_rf( file )
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "Rotate Diaspora logs"
|
|
||||||
task :install_logrotate_config do
|
|
||||||
logrotate_conf = <<-RUBY
|
|
||||||
#{APP_ROOT}/logs/production.log {
|
|
||||||
daily
|
|
||||||
missingok
|
|
||||||
rotate 8
|
|
||||||
compress
|
|
||||||
delaycompress
|
|
||||||
notifempty
|
|
||||||
copytruncate
|
|
||||||
}
|
|
||||||
RUBY
|
|
||||||
begin
|
|
||||||
File.open('/etc/logrotate.d/diaspora') do |fin|
|
|
||||||
fin.write logrotate_conf
|
|
||||||
end
|
|
||||||
rescue
|
|
||||||
puts "Could not install logrotate configs. Perhaps you should try running this task as root and ensuring logrotate is installed:\n#{logrotate_conf}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "Queue users for removal"
|
desc "Queue users for removal"
|
||||||
task :queue_users_for_removal => :environment do
|
task :queue_users_for_removal => :environment do
|
||||||
# Queue users for removal due to inactivity
|
# Queue users for removal due to inactivity
|
||||||
|
|
|
||||||
|
|
@ -3,50 +3,6 @@
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
namespace :migrations do
|
namespace :migrations do
|
||||||
|
|
||||||
desc 'copy all hidden share visibilities from share_visibilities to users. Can be run with the site still up.'
|
|
||||||
task :copy_hidden_share_visibilities_to_users => [:environment] do
|
|
||||||
require Rails.root.join('lib', 'share_visibility_converter')
|
|
||||||
ShareVisibilityConverter.copy_hidden_share_visibilities_to_users
|
|
||||||
end
|
|
||||||
|
|
||||||
desc 'puts out information about old invited users'
|
|
||||||
task :invitations => [:environment] do
|
|
||||||
puts "email, invitation_token, :invited_by_id, :invitation_identifier"
|
|
||||||
User.where('username is NULL').select([:id, :email, :invitation_token, :invited_by_id, :invitation_identifier]).find_in_batches do |users|
|
|
||||||
users.each{|x| puts "#{x.email}, #{x.invitation_token}, #{x.invited_by_id}, #{x.invitation_identifier}" }
|
|
||||||
end
|
|
||||||
puts "done"
|
|
||||||
end
|
|
||||||
|
|
||||||
desc 'absolutify all existing image references'
|
|
||||||
task :absolutify_image_references do
|
|
||||||
require File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment')
|
|
||||||
|
|
||||||
Photo.all.each do |photo|
|
|
||||||
unless photo.remote_photo_path
|
|
||||||
# extract root
|
|
||||||
#
|
|
||||||
pod = URI::parse(photo.person.url)
|
|
||||||
pod_url = "#{pod.scheme}://#{pod.host}"
|
|
||||||
|
|
||||||
if photo.image.url
|
|
||||||
remote_path = "#{photo.image.url}"
|
|
||||||
else
|
|
||||||
puts pod_url
|
|
||||||
remote_path = "#{pod_url}#{photo.remote_photo_path}/#{photo.remote_photo_name}"
|
|
||||||
end
|
|
||||||
|
|
||||||
# get path/filename
|
|
||||||
name_start = remote_path.rindex '/'
|
|
||||||
photo.remote_photo_path = "#{remote_path.slice(0, name_start)}/"
|
|
||||||
photo.remote_photo_name = remote_path.slice(name_start + 1, remote_path.length)
|
|
||||||
|
|
||||||
photo.save!
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
task :upload_photos_to_s3 do
|
task :upload_photos_to_s3 do
|
||||||
require File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment')
|
require File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment')
|
||||||
puts AppConfig.environment.s3.key
|
puts AppConfig.environment.s3.key
|
||||||
|
|
@ -72,60 +28,6 @@ namespace :migrations do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
# removes hashtags with uppercase letters and re-attaches
|
|
||||||
# the posts to the lowercase version
|
|
||||||
task :rewire_uppercase_hashtags => :environment do
|
|
||||||
evil_tags = ActsAsTaggableOn::Tag.where("lower(name) != name")
|
|
||||||
puts "found #{evil_tags.count} tags to convert..."
|
|
||||||
|
|
||||||
evil_tags.each_with_index do |tag, i|
|
|
||||||
good_tag = ActsAsTaggableOn::Tag.first_or_create_by(name: tag.name.mb_chars.downcase)
|
|
||||||
puts "++ '#{tag.name}' has #{tag.taggings.count} records attached"
|
|
||||||
|
|
||||||
taggings = tag.taggings
|
|
||||||
deleteme = []
|
|
||||||
|
|
||||||
taggings.each do |tagging|
|
|
||||||
if good_tag.taggings.where(:taggable_id => tagging.taggable_id).count > 0
|
|
||||||
# the same taggable is already tagged with the correct tag
|
|
||||||
# just delete the obsolete tagging it
|
|
||||||
deleteme << tagging
|
|
||||||
next
|
|
||||||
end
|
|
||||||
|
|
||||||
# the tagging exists only for the wrong tag, move it to the 'good tag'
|
|
||||||
good_tag.taggings << tagging
|
|
||||||
end
|
|
||||||
|
|
||||||
deleteme.each do |tagging|
|
|
||||||
tagging.destroy
|
|
||||||
end
|
|
||||||
|
|
||||||
rest = tag.taggings(true) # force reload
|
|
||||||
if rest.count > 0
|
|
||||||
puts "-- the tag #{tag.name} still has some taggings - aborting!"
|
|
||||||
break
|
|
||||||
end
|
|
||||||
|
|
||||||
# no more taggings left, delete the tag
|
|
||||||
tag.destroy
|
|
||||||
|
|
||||||
puts "-- converted '#{tag.name}' to '#{good_tag.name}'"
|
|
||||||
puts "\n## #{i+1} tags processed\n\n" if ((i+1) % 50 == 0)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
task :remove_uppercase_hashtags => :environment do
|
|
||||||
evil_tags = ActsAsTaggableOn::Tag.where("lower(name) != name")
|
|
||||||
evil_tags.each do |tag|
|
|
||||||
next if tag.taggings.count > 0 # non-ascii tags
|
|
||||||
|
|
||||||
puts "removing '#{tag.name}'..."
|
|
||||||
tag.destroy
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
CURRENT_QUEUES = %w(urgent high medium low default).freeze
|
CURRENT_QUEUES = %w(urgent high medium low default).freeze
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue