Skip to content

Commit 954023b

Browse files
committed
rake task for deleting comments with external URIs in summary
1 parent a4866b8 commit 954023b

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

lib/tasks/spam.rake

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
namespace :spam do
2-
desc "Clean out objects marked as spam by curators"
2+
desc 'Clean out objects marked as spam by curators'
33
task clean_spam: :environment do
44
if Spam.where(cleaned: false, flagged_by_admin_or_curator: true).any?
55
object_types = Spam.where(cleaned: false, flagged_by_admin_or_curator: true).pluck(:spammable_type).uniq
@@ -10,4 +10,34 @@ namespace :spam do
1010
end
1111
end
1212
end
13+
14+
desc 'Delete comment objects with external URIs'
15+
16+
def extract_uris(value)
17+
URI.extract(value)
18+
end
19+
20+
def find_spam(items)
21+
items.select do |item|
22+
summary = item.summary
23+
uris = extract_uris(summary)
24+
return uris.length.positive?
25+
end
26+
27+
items
28+
end
29+
30+
task clean_comments: :environment do
31+
case_comments = find_spam(CaseComment.all)
32+
case_comments.delete_all if case_comments.length.positive?
33+
34+
document_comments = find_spam(DocumentComment.all)
35+
document_comments.delete_all if document_comments.length.positive?
36+
37+
point_comments = find_spam(PointComment.all)
38+
point_comments.delete_all if point_comments.length.positive?
39+
40+
topic_comments = find_spam(TopicComment.all)
41+
topic_comments.delete_all if topic_comments.length.positive?
42+
end
1343
end

0 commit comments

Comments
 (0)