Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

fix another hashtag 'inconvenience' #3298

Merged
merged 1 commit into from May 24, 2012
Jump to file or symbol
Failed to load files and symbols.
+37 −2
Split
View
@@ -52,11 +52,11 @@ def publisher_opts
def construct_post_query
posts = StatusMessage
- if user.present?
+ if user.present?
posts = posts.owned_or_visible_by_user(user)
else
posts = posts.all_public
end
- posts.tagged_with(tag_name)
+ posts.tagged_with(tag_name, :any => true)
end
end
View
@@ -74,4 +74,39 @@ namespace :migrations do
}
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.find_or_create_by_name(tag.name.downcase)
+ puts "++ '#{tag.name}' has #{tag.taggings.count} records attached"
+ deleteme = []
+
+ tag.taggings.each do |tagging|
+ deleteme << tagging
+ end
+
+ deleteme.each do |tagging|
+ #tag.taggings.delete(tagging)
+ good_tag.taggings << tagging
@maxwell

maxwell May 24, 2012

Owner

dumb q. does this save the record? I can never remember what does and what doesn't

EDIT : it does

+ end
+
+ puts "-- converted '#{tag.name}' to '#{good_tag.name}' with #{deleteme.count} records"
+ puts "\n## #{i} tags processed\n\n" if (i % 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