Skip to content

Commit 6dffaa7

Browse files
authored
isso: migrate: Handle deleted comments in Disqus migration (#994)
* isso: migrate: Handle deleted comments in Disqus migration Fixes #979
1 parent 50642b1 commit 6dffaa7

5 files changed

Lines changed: 46 additions & 5 deletions

File tree

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ Bugfixes & Improvements
2626
- Make language code handling more robust (`#983`_, ix5)
2727
- Prevent auto creation of invalid links in comments (`#995`_, pkvach)
2828
- Fix W3C Validation issues (`#999`_, pkvach)
29+
- Handle deleted comments in Disqus migration (`#994`_, pkvach)
2930

3031
.. _#951: https://github.com/posativ/isso/pull/951
3132
.. _#967: https://github.com/posativ/isso/pull/967
3233
.. _#983: https://github.com/posativ/isso/pull/983
3334
.. _#995: https://github.com/isso-comments/isso/pull/995
3435
.. _#999: https://github.com/isso-comments/isso/pull/999
36+
.. _#994: https://github.com/isso-comments/isso/pull/994
3537

3638
0.13.1.dev0 (2023-02-05)
3739
------------------------

isso/db/comments.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def __init__(self, db):
3838
'CREATE TABLE IF NOT EXISTS comments (',
3939
' tid REFERENCES threads(id), id INTEGER PRIMARY KEY, parent INTEGER,',
4040
' created FLOAT NOT NULL, modified FLOAT, mode INTEGER, remote_addr VARCHAR,',
41-
' text VARCHAR, author VARCHAR, email VARCHAR, website VARCHAR,',
41+
' text VARCHAR NOT NULL, author VARCHAR, email VARCHAR, website VARCHAR,',
4242
' likes INTEGER DEFAULT 0, dislikes INTEGER DEFAULT 0, voters BLOB NOT NULL,',
4343
' notification INTEGER DEFAULT 0);'])
4444
try:

isso/migrate.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,11 @@ def migrate(self):
9292
for post in tree.findall(Disqus.ns + 'post'):
9393
email = post.find('{0}author/{0}email'.format(Disqus.ns))
9494
ip = post.find(Disqus.ns + 'ipAddress')
95+
comment_text = post.find(Disqus.ns + 'message').text or ''
9596

9697
item = {
9798
'dsq:id': post.attrib.get(Disqus.internals + 'id'),
98-
'text': post.find(Disqus.ns + 'message').text,
99+
'text': comment_text,
99100
'author': post.find('{0}author/{0}name'.format(Disqus.ns)).text,
100101
'email': email.text if email is not None else '',
101102
'created': mktime(strptime(
@@ -146,11 +147,13 @@ def migrate(self):
146147
continue
147148

148149
email = post.find("{0}author/{0}email".format(Disqus.ns))
150+
comment_text = post.find(Disqus.ns + 'message').text or ''
151+
149152
print(" * {0} by {1} <{2}>".format(
150153
post.attrib.get(Disqus.internals + "id"),
151154
post.find("{0}author/{0}name".format(Disqus.ns)).text,
152155
email.text if email is not None else ""))
153-
print(textwrap.fill(post.find(Disqus.ns + "message").text,
156+
print(textwrap.fill(comment_text,
154157
initial_indent=" ", subsequent_indent=" "))
155158
print("")
156159

isso/tests/disqus.xml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,37 @@
113113
<thread dsq:id="7" />
114114
</post>
115115

116+
<!-- deleted post -->
117+
<post dsq:id="9">
118+
<id/>
119+
<message/>
120+
<createdAt>2013-10-10T19:20:29Z</createdAt>
121+
<isDeleted>true</isDeleted>
122+
<isSpam>false</isSpam>
123+
<author>
124+
<email>foo@bar.com</email>
125+
<name>peter</name>
126+
<isAnonymous>true</isAnonymous>
127+
</author>
128+
<ipAddress>127.0.0.1</ipAddress>
129+
<thread dsq:id="2" />
130+
</post>
131+
132+
<!-- reference to previous deleted post -->
133+
<post dsq:id="11">
134+
<message><![CDATA[<p>Hello, World.</p>]]></message>
135+
<createdAt>2013-10-11T06:52:33Z</createdAt>
136+
<isDeleted>false</isDeleted>
137+
<isSpam>false</isSpam>
138+
<author>
139+
<email>foo@bar.com</email>
140+
<name>user</name>
141+
<isAnonymous>false</isAnonymous>
142+
<username>user</username>
143+
</author>
144+
<ipAddress>127.0.0.1</ipAddress>
145+
<thread dsq:id="2" />
146+
<parent dsq:id="9" />
147+
</post>
148+
116149
</disqus>

isso/tests/test_migration.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def test_disqus_empty_id_workaround(self):
5656
Disqus(db, xml, empty_id=True).migrate()
5757

5858
self.assertEqual(
59-
len(db.execute("SELECT id FROM comments").fetchall()), 3)
59+
len(db.execute("SELECT id FROM comments").fetchall()), 5)
6060

6161
self.assertEqual(db.threads["/"]["title"], "Hello, World!")
6262
self.assertEqual(db.threads["/"]["id"], 1)
@@ -67,9 +67,12 @@ def test_disqus_empty_id_workaround(self):
6767
self.assertEqual(a["email"], "foo@bar.com")
6868
self.assertEqual(a["remote_addr"], "127.0.0.0")
6969

70-
b = db.comments.get(2)
70+
b = db.comments.get(3)
7171
self.assertEqual(b["parent"], a["id"])
7272

73+
deleted_comment = db.comments.get(2)
74+
self.assertEqual(deleted_comment["text"], "")
75+
7376
def test_wordpress(self):
7477

7578
xml = join(dirname(__file__), "wordpress.xml")

0 commit comments

Comments
 (0)