From ca39826a115e273be547107079f601407b057cf7 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Wed, 19 Apr 2023 23:53:11 +0200 Subject: [PATCH] fix comment parent 75% --- lib/WPImport.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/WPImport.py b/lib/WPImport.py index 6ce7c0e..6dc6bb2 100644 --- a/lib/WPImport.py +++ b/lib/WPImport.py @@ -208,7 +208,6 @@ class WPimport: ## Add or update comment def _addOrUpdateComment(self, post, comment, title): - params = {"post": post} for i in comment: id_comment = [] comment_exist = False @@ -223,19 +222,21 @@ class WPimport: for j in result: comment_exist = True id_comment.append(j["id"]) - data = {"post": post, "content": i["content"], "date": i["date"], "author_name": i["author"], "status": "approved"} if comment_exist is True: for j in id_comment: try: - page = page = self._request.delete("http://{0}/wp-json/wp/v2/comments/{1}".format(self._wordpress, j), auth=self._basic) + params = {"force":1} + page = self._request.delete("http://{0}/wp-json/wp/v2/comments/{1}".format(self._wordpress, j), params=params, auth=self._basic) except Exception as err: self._logger.error("Connection error : {0}".format(err)) exit(1) if page.status_code == 200: self._logger.info("Comment deleted for {0}".format(title)) + self._logger.debug("Comment deleted : {0}".format(i)) else: self._logger.error("Comment not deleted for {0} due status code : {1}".format(title, page.status_code)) - + data = {"post": post, "content": i["content"], "date": i["date"], "author_name": i["author"], "status": "approved"} + if i["parent_id"] != -1: parent_id = int(i["parent_id"]) params = {"post": post, "author_name":comment[parent_id]["author"], "date":comment[parent_id]["date"]} @@ -257,6 +258,7 @@ class WPimport: exit(1) if page.status_code == 201: self._logger.info("Comment added for {0}".format(title)) + self._logger.debug("Data : {0}".format(data)) else: self._logger.error("Comment not added for {0} due status code : {1}".format(title, page.status_code)) self._logger.debug(page.content)