Permalink
Browse files

API CHANGE Suspend members instead of deleting them in Forum_Controll…

…er->markasspam(), and don't delete other posts by the same author, in order to make forum moderation less (human) error-prone. Log any moderation activity to the standard PHP error log for later debugging.
  • Loading branch information...
1 parent 912d8f2 commit e63bebe723c8678e1ba934d66a85564cec71dd47 @chillu chillu committed Aug 4, 2011
Showing with 29 additions and 28 deletions.
  1. +24 −26 code/Forum.php
  2. +5 −2 tests/ForumTest.php
View
50 code/Forum.php
@@ -565,6 +565,8 @@ function unsubscribe() {
* Must be logged in and have the correct permissions to do marking
*/
function markasspam() {
+ $currentUser = Member::currentUser();
+
if($this->canModerate() && isset($this->urlParams['ID'])) {
$post = DataObject::get_by_id('Post', $this->urlParams['ID']);
@@ -574,34 +576,30 @@ function markasspam() {
SpamProtectorManager::send_feedback($post, 'spam');
}
- // some posts do not have authors
+ // post was the start of a thread, Delete the whole thing
+ if($post->isFirstPost()) $post->Thread()->delete();
+
+ // Delete the current post
+ $post->delete();
+ SS_Log::log(sprintf(
+ 'Suspended post #%d as spam, by moderator "%s"',
+ $post->ID,
+ $currentUser->Email
+ ), SS_Log::NOTICE);
+
+ // Suspend the member (rather than deleting him),
+ // which gives him or a moderator the chance to revoke a decision.
if($author = $post->Author()) {
- $SQL_id = Convert::raw2sql($author->ID);
-
- // delete all threads and posts from that user
- $posts = DataObject::get('Post', "\"AuthorID\" = '$SQL_id'");
-
- if($posts) {
- foreach($posts as $post) {
- if($post->isFirstPost()) {
-
- // post was the start of a thread, Delete the whole thing
- $post->Thread()->delete();
- }
- else {
- if($post->ID) {
- $post->delete();
- }
- }
- }
- }
-
- // delete the authors account
- $author->delete();
- }
- else {
- $post->delete();
+ $author->SuspendedUntil = strtotime('+99 years', SS_Datetime::now()->Format('U'));
+ $author->write();
}
+
+ SS_Log::log(sprintf(
+ 'Suspended member "%s" (#%d) for spam activity, by moderator ',
+ $author->Email,
+ $author->ID,
+ $currentUser->Email
+ ), SS_Log::NOTICE);
}
}
View
7 tests/ForumTest.php
@@ -262,6 +262,8 @@ function testMarkAsSpamLink() {
$forum = $spampost->Forum();
$author = $spampost->Author();
+ $this->assertNull($author->SuspendedUntil);
+
$link = $forum->AbsoluteLink("markasspam") .'/'. $spampost->ID;
$c = new Forum_Controller($forum);
@@ -270,8 +272,9 @@ function testMarkAsSpamLink() {
// removes the post
$this->assertFalse(DataObject::get_by_id('Post', $spampost->ID));
- // removes the member
- $this->assertFalse(DataObject::get_by_id('Member', $author->ID));
+ // suspends the member
+ $author = DataObject::get_by_id('Member', $author->ID);
+ $this->assertNotNull($author->SuspendedUntil);
// does not effect the thread
$thread = DataObject::get_by_id('ForumThread', $spampost->Thread()->ID);

0 comments on commit e63bebe

Please sign in to comment.