This commit is contained in:
Timo Stollenwerk 2012-01-13 14:40:26 +01:00
parent 07cde3ca7b
commit cce409a729

View File

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