Skip to content

Commit 2df2d0f

Browse files
author
Tom Copeland
committed
Can't delete tons of messages at once due to PL/SQL trigger. Utility method to disallow anon postings.
1 parent f29e44d commit 2df2d0f

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

app/models/forum.rb

+8-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,14 @@ class Forum < ActiveRecord::Base
2424
belongs_to :posted_by, :class_name => 'User', :foreign_key => 'posted_by'
2525

2626
def delete_all_messages
27-
sql = "delete from forum where group_forum_id = #{self.group_forum_id}"
28-
puts "Running '#{sql}'..."
29-
Forum.connection.execute(sql)
27+
#sql = "delete from forum where group_forum_id = #{self.group_forum_id}"
28+
#puts "Running '#{sql}'..."
29+
#Forum.connection.execute(sql)
30+
Forum.find_each(:batch_size => 100, :conditions => ["group_forum_id = ?", group_forum_id]) do |f|
31+
puts "Deleting #{f.subject}"
32+
f.destroy
33+
end
34+
nil
3035
end
3136
end
3237

app/models/forum_group.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ class ForumGroup < ActiveRecord::Base
1616

1717
set_table_name "forum_group_list"
1818
set_primary_key "group_forum_id"
19-
19+
2020
belongs_to :group
2121
has_many :forums, :foreign_key => "group_forum_id"
2222

23+
def disallow_anonymous_postings!
24+
self.update_attribute :allow_anonymous, false
25+
end
26+
2327
end
2428

0 commit comments

Comments
 (0)