From 3b1c76d9f06a0d9f0e0e4220ea4e865f1c1275a5 Mon Sep 17 00:00:00 2001 From: azayati Date: Wed, 11 Dec 2024 14:07:41 +0100 Subject: [PATCH] fix: Fix NewsArticlesUpgrade plugin note issue - EXO-75949 --- .../news/upgrade/jcr/NewsArticlesUpgrade.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/data-upgrade-news/src/main/java/org/exoplatform/news/upgrade/jcr/NewsArticlesUpgrade.java b/data-upgrade-news/src/main/java/org/exoplatform/news/upgrade/jcr/NewsArticlesUpgrade.java index 5606498d..54ddaa65 100644 --- a/data-upgrade-news/src/main/java/org/exoplatform/news/upgrade/jcr/NewsArticlesUpgrade.java +++ b/data-upgrade-news/src/main/java/org/exoplatform/news/upgrade/jcr/NewsArticlesUpgrade.java @@ -215,7 +215,7 @@ public void processUpgrade(String oldVersion, String newVersion) { sessionProvider.close(); } } - if (notMigratedNewsArticlesCount == 0) { + if (totalNewsArticlesCount == migratedNewsArticlesCount) { LOG.info("End news articles migration successful migration: total={} succeeded={} error={}. It tooks {} ms.", totalNewsArticlesCount, migratedNewsArticlesCount, @@ -263,13 +263,14 @@ public boolean shouldProceedToUpgrade(String newVersion, public int manageNewsArticles(List newsArticlesNodes, Session session) throws Exception { int notMigratedNewsArticlesCount = 0; for (Node newsArticleNode : newsArticlesNodes) { - indexingService.unindex(NewsIndexingServiceConnector.TYPE, newsArticleNode.getUUID()); + String newsArticleNodeUUID = newsArticleNode.getUUID(); + indexingService.unindex(NewsIndexingServiceConnector.TYPE, newsArticleNodeUUID); News article = null; News draftArticle = null; try { News news = convertNewsNodeToNewEntity(newsArticleNode, null); NotePageProperties properties = news.getProperties(); - LOG.info("Migrating news article with id '{}' and title '{}'", newsArticleNode.getUUID(), news.getTitle()); + LOG.info("Migrating news article with id '{}' and title '{}'", newsArticleNodeUUID, news.getTitle()); Space space = spaceService.getSpaceById(news.getSpaceId()); // existing published and staged articles @@ -287,7 +288,7 @@ public int manageNewsArticles(List newsArticlesNodes, Session session) thr setArticleIllustration(pageVersion.getParent(), article.getSpaceId(), newsArticleNode, "notePage"); setArticleAttachments(pageVersion.getId(), newsArticleNode); /* upgrade news id for news targets and favorite metadatata items */ - setArticleMetadatasItems(article.getId(), newsArticleNode.getUUID()); + setArticleMetadatasItems(article.getId(), newsArticleNodeUUID); if (getStringProperty(newsArticleNode, "publication:currentState").equals("published")) { setArticleActivities(article, newsArticleNode); setArticleViews(article, newsArticleNode); @@ -304,13 +305,14 @@ public int manageNewsArticles(List newsArticlesNodes, Session session) thr if (!newsArticleNode.hasProperty(AuthoringPublicationConstant.LIVE_REVISION_PROP)) { // upgrade the drafts of not existing articles /* attachments will not be migrated for drafts */ + properties.setDraft(true); + news.setProperties(properties); draftArticle = newsService.createDraftArticleForNewPage(news, space.getGroupId(), news.getAuthor(), news.getCreationDate().getTime()); DraftPage draftPage = noteService.getDraftNoteById(draftArticle.getId(), draftArticle.getAuthor()); properties.setNoteId(Long.parseLong(draftPage.getId())); - properties.setDraft(true); if (news.getAuthor() != null) { noteService.saveNoteMetadata(properties, draftPage.getLang(), @@ -338,7 +340,7 @@ public int manageNewsArticles(List newsArticlesNodes, Session session) thr setArticleIllustration(pageVersion.getParent(), article.getSpaceId(), publishedNode, "notePage"); setArticleAttachments(pageVersion.getId(), publishedNode); /* upgrade news id for news targets and favorite metadatata items */ - setArticleMetadatasItems(article.getId(), newsArticleNode.getUUID()); + setArticleMetadatasItems(article.getId(), newsArticleNodeUUID); setArticleActivities(article, publishedNode); setArticleViews(article, newsArticleNode); Page publishedPage = noteService.getNoteById(article.getId()); @@ -362,14 +364,15 @@ public int manageNewsArticles(List newsArticlesNodes, Session session) thr newsArticleNode.remove(); session.save(); } catch (Exception e) { - LOG.warn("Error migrating news article with id '{}'. Continue to migrate other items", newsArticleNode.getUUID(), e); + notMigratedNewsArticlesCount++; + LOG.warn("Error migrating news article with id '{}'. Continue to migrate other items", newsArticleNodeUUID, e); if (article != null) { newsService.deleteArticle(article, article.getAuthor()); - setArticleMetadatasItems(newsArticleNode.getUUID(), article.getId()); + setArticleMetadatasItems(newsArticleNodeUUID, article.getId()); } else if (draftArticle != null) { newsService.deleteDraftArticle(draftArticle.getId(), draftArticle.getAuthor()); } - notMigratedNewsArticlesCount++; + } } return notMigratedNewsArticlesCount;