From 9644dcc48021b4ad9546debd399460eddd2f0612 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 2 Jan 2009 18:54:37 +0000 Subject: 1) Removed the published boolean database field 2) Replaced it with a string field (state) which contains the state of the comment. i.e. published, unpublished, spam. Unsure if we want to create constants in comments.php to standardize the valid values... thoughts? 3) synchronized the spamfilter and comment unit tests with the current functionality --- modules/comment/controllers/comments.php | 5 ++-- modules/comment/helpers/comment.php | 2 +- modules/comment/helpers/comment_block.php | 2 +- modules/comment/helpers/comment_installer.php | 6 +--- modules/spam_filter/libraries/SpamFilter.php | 2 +- .../spam_filter/tests/SpamFilter_Helper_Test.php | 32 ++++++++++++++++++++++ .../spam_filter/tests/Spam_Filter_Helper_Test.php | 32 ---------------------- 7 files changed, 39 insertions(+), 42 deletions(-) create mode 100644 modules/spam_filter/tests/SpamFilter_Helper_Test.php delete mode 100644 modules/spam_filter/tests/Spam_Filter_Helper_Test.php diff --git a/modules/comment/controllers/comments.php b/modules/comment/controllers/comments.php index fcef1832..e19a2ec1 100644 --- a/modules/comment/controllers/comments.php +++ b/modules/comment/controllers/comments.php @@ -30,7 +30,7 @@ class Comments_Controller extends REST_Controller { $comments = ORM::factory("comment") ->where("item_id", $item->id) - ->where("published", 1) + ->where("state", "published") ->orderby("created", "desc") ->find_all(); @@ -68,7 +68,8 @@ class Comments_Controller extends REST_Controller { print json_encode( array("result" => "success", - "resource" => $comment->published ? url::site("comments/{$comment->id}") : NULL, + "resource" => $comment->state == "published" ? url::site("comments/{$comment->id}") : + NULL, "form" => comment::get_add_form($item)->__toString())); } else { print json_encode( diff --git a/modules/comment/helpers/comment.php b/modules/comment/helpers/comment.php index 82f31747..c0864fee 100644 --- a/modules/comment/helpers/comment.php +++ b/modules/comment/helpers/comment.php @@ -54,7 +54,7 @@ class comment_Core { if (module::is_installed("spam_filter") && TEST_MODE == 0) { SpamFilter::instance()->check_comment($comment); } else { - $comment->published = true; + $comment->state = "published"; } $comment->save(); diff --git a/modules/comment/helpers/comment_block.php b/modules/comment/helpers/comment_block.php index ce748036..9a104baf 100644 --- a/modules/comment/helpers/comment_block.php +++ b/modules/comment/helpers/comment_block.php @@ -32,7 +32,7 @@ class comment_block_Core { $view = new View("comments.html"); $view->comments = ORM::factory("comment") ->where("item_id", $theme->item()->id) - ->where("published", 1) + ->where("state", "published") ->orderby("created", "ASC") ->find_all(); diff --git a/modules/comment/helpers/comment_installer.php b/modules/comment/helpers/comment_installer.php index 3e7b2f49..dbbb511f 100644 --- a/modules/comment/helpers/comment_installer.php +++ b/modules/comment/helpers/comment_installer.php @@ -23,10 +23,6 @@ class comment_installer { $version = module::get_version("comment"); if ($version == 0) { - /** - * @todo change published flag to char(xx) with values published, unpublished, moderation - * unreviewed, spam - */ $db->query("CREATE TABLE IF NOT EXISTS `comments` ( `id` int(9) NOT NULL auto_increment, `author` varchar(128) default NULL, @@ -35,7 +31,7 @@ class comment_installer { `created` int(9) NOT NULL, `item_id` int(9) NOT NULL, `url` varchar(255) default NULL, - `published` boolean default 1, + `state` char(15) default 'unpublished', `ip_addr` char(15) default NULL, `user_agent` varchar(255) default NULL, `spam_signature` varchar(255) default NULL, diff --git a/modules/spam_filter/libraries/SpamFilter.php b/modules/spam_filter/libraries/SpamFilter.php index 7b826a21..3485bf75 100644 --- a/modules/spam_filter/libraries/SpamFilter.php +++ b/modules/spam_filter/libraries/SpamFilter.php @@ -56,7 +56,7 @@ class SpamFilter_Core { $this->_is_initialized(); $is_valid = $this->driver->check_comment($comment); - $comment->published = $is_valid; + $comment->state = $is_valid ? "published" : "spam"; return $is_valid; } diff --git a/modules/spam_filter/tests/SpamFilter_Helper_Test.php b/modules/spam_filter/tests/SpamFilter_Helper_Test.php new file mode 100644 index 00000000..7f6bf5c0 --- /dev/null +++ b/modules/spam_filter/tests/SpamFilter_Helper_Test.php @@ -0,0 +1,32 @@ +assert_equal($expected, spam_filter::get_driver_names()); + } +} \ No newline at end of file diff --git a/modules/spam_filter/tests/Spam_Filter_Helper_Test.php b/modules/spam_filter/tests/Spam_Filter_Helper_Test.php deleted file mode 100644 index 8abd8ed6..00000000 --- a/modules/spam_filter/tests/Spam_Filter_Helper_Test.php +++ /dev/null @@ -1,32 +0,0 @@ -assert_equal($expected, spam_filter::get_driver_names()); - } -} \ No newline at end of file -- cgit v1.2.3