This commit is contained in:
Timo Stollenwerk 2012-01-13 14:40:26 +01:00
parent 07cde3ca7b
commit cce409a729
1 changed files with 34 additions and 24 deletions

View File

@ -18,7 +18,13 @@ from plone.app.discussion.interfaces import IConversation, IReplies, IComment
def DT2dt(DT):
"""Convert a Zope DateTime (with timezone) into a Python datetime (GMT)."""
DT = DT.toZone('GMT')
return datetime(DT.year(), DT.month(), DT.day(), DT.hour(), DT.minute(), int(DT.second()))
return datetime(
DT.year(),
DT.month(),
DT.day(),
DT.hour(),
DT.minute(),
int(DT.second()))
class View(BrowserView):
@ -32,11 +38,11 @@ class View(BrowserView):
self.total_comments_migrated = 0
self.total_comments_deleted = 0
dry_run = self.request.has_key("dry_run")
dry_run = "dry_run" in self.request
# This is for testing only.
# Do not use transactions during a test.
test = self.request.has_key("test")
test = "test" in self.request
if not test:
transaction.begin() # pragma: no cover
@ -50,7 +56,8 @@ class View(BrowserView):
context.plone_log(msg)
out.append(msg)
def migrate_replies(context, in_reply_to, replies, depth=0, just_delete=0):
def migrate_replies(context, in_reply_to, replies,
depth=0, just_delete=0):
# Recursive function to migrate all direct replies
# of a comment. Returns True if there are no replies to
# this comment left, and therefore the comment can be removed.
@ -102,7 +109,8 @@ class View(BrowserView):
# migrate all talkbacks of the reply
talkback = getattr(reply, 'talkback', None)
no_replies_left = migrate_replies(context,
no_replies_left = migrate_replies(
context,
new_in_reply_to,
talkback.getReplies(),
depth=depth + 1,
@ -180,9 +188,11 @@ class View(BrowserView):
% (self.total_comments_migrated, count_comments_old))
if self.total_comments_migrated != count_comments_old:
log("%s comments could not be migrated."
% (count_comments_old - self.total_comments_migrated)) # pragma: no cover
log("Please make sure your portal catalog is up-to-date.") # pragma: no cover
log("%s comments could not be migrated." %
(count_comments_old - \
self.total_comments_migrated)) # pragma: no cover
log("Please make sure your " +
"portal catalog is up-to-date.") # pragma: no cover
if dry_run and not test:
transaction.abort() # pragma: no cover