File tree Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Original file line number Diff line number Diff line change 1
1
namespace :spam do
2
- desc " Clean out objects marked as spam by curators"
2
+ desc ' Clean out objects marked as spam by curators'
3
3
task clean_spam : :environment do
4
4
if Spam . where ( cleaned : false , flagged_by_admin_or_curator : true ) . any?
5
5
object_types = Spam . where ( cleaned : false , flagged_by_admin_or_curator : true ) . pluck ( :spammable_type ) . uniq
@@ -10,4 +10,34 @@ namespace :spam do
10
10
end
11
11
end
12
12
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
13
43
end
You can’t perform that action at this time.
0 commit comments