From 784ebe75321304fe3f83cddaf3cb1030410fb5ed Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 22 May 2011 21:24:27 -0700 Subject: Leave the "updated" field alone when importing comments so that if Akismet marks them as spam, we don't immediately flush them out of the database on the next visit to Admin > Content > Comments. Also warn the user about Akismet, and fix up the G2 import code to reimport deleted comments. --- modules/g2_import/helpers/g2_import.php | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'modules/g2_import/helpers') diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php index c79a8d36..5c690da4 100644 --- a/modules/g2_import/helpers/g2_import.php +++ b/modules/g2_import/helpers/g2_import.php @@ -908,9 +908,14 @@ class g2_import_Core { array("id" => $g2_comment_id, "exception" => (string)$e)); } - if (self::map($g2_comment->getId())) { - // Already imported - return; + if ($id = self::map($g2_comment->getId())) { + if (ORM::factory("comment", $id)->loaded()) { + // Already imported and still exists + return; + } + // This comment was already imported, but now it no longer exists. Import it again, per + // ticket #1736. + self::clear_map($g2_comment_id); } $item_id = self::map($g2_comment->getParentId()); @@ -948,10 +953,11 @@ class g2_import_Core { self::set_map($g2_comment->getId(), $comment->id, "comment"); // Backdate the creation date. We can't do this at creation time because - // Comment_Model::save() will override it. + // Comment_Model::save() will override it. Leave the updated date alone + // so that if the comments get marked as spam, they don't immediately get + // flushed (see ticket #1736) db::update("comments") ->set("created", $g2_comment->getDate()) - ->set("updated", $g2_comment->getDate()) ->where("id", "=", $comment->id) ->execute(); } @@ -1306,6 +1312,16 @@ class g2_import_Core { self::$map[$g2_id] = $g3_id; } + /** + * Remove all map entries associated with the given Gallery 2 id. + */ + static function clear_map($g2_id) { + db::build() + ->delete("g2_maps") + ->where("g2_id", "=", $g2_id) + ->execute(); + } + static function log($msg) { message::warning($msg); Kohana_Log::add("alert", $msg); -- cgit v1.2.3 From f567bdde2817a52afbd436421b61adad8f4a9fd8 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 22 May 2011 21:36:16 -0700 Subject: Clear any existing, matching g2_map rows before mapping new rows. This is an extra query, but should keep duplicate rows out of the database and let new rows supercede old ones. Fixes #1737. --- modules/g2_import/helpers/g2_import.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'modules/g2_import/helpers') diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php index 5c690da4..8a5d2c5f 100644 --- a/modules/g2_import/helpers/g2_import.php +++ b/modules/g2_import/helpers/g2_import.php @@ -915,7 +915,6 @@ class g2_import_Core { } // This comment was already imported, but now it no longer exists. Import it again, per // ticket #1736. - self::clear_map($g2_comment_id); } $item_id = self::map($g2_comment->getParentId()); @@ -1298,6 +1297,7 @@ class g2_import_Core { * Associate a Gallery 2 id with a Gallery 3 item id. */ static function set_map($g2_id, $g3_id, $resource_type, $g2_url=null) { + self::clear_map($g2_id, $resource_type); $g2_map = ORM::factory("g2_map"); $g2_map->g3_id = $g3_id; $g2_map->g2_id = $g2_id; @@ -1315,10 +1315,11 @@ class g2_import_Core { /** * Remove all map entries associated with the given Gallery 2 id. */ - static function clear_map($g2_id) { + static function clear_map($g2_id, $resource_type) { db::build() ->delete("g2_maps") ->where("g2_id", "=", $g2_id) + ->where("resource_type", "=", $resource_type) ->execute(); } -- cgit v1.2.3