Skip to content

Commit

Permalink
fix: Fix NewsArticlesUpgrade plugin note issue - EXO-75949
Browse files Browse the repository at this point in the history
  • Loading branch information
azayati committed Dec 11, 2024
1 parent 21ed033 commit 3b1c76d
Showing 1 changed file with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -263,13 +263,14 @@ public boolean shouldProceedToUpgrade(String newVersion,
public int manageNewsArticles(List<Node> 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
Expand All @@ -287,7 +288,7 @@ public int manageNewsArticles(List<Node> 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);
Expand All @@ -304,13 +305,14 @@ public int manageNewsArticles(List<Node> 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(),
Expand Down Expand Up @@ -338,7 +340,7 @@ public int manageNewsArticles(List<Node> 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());
Expand All @@ -362,14 +364,15 @@ public int manageNewsArticles(List<Node> 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;
Expand Down

0 comments on commit 3b1c76d

Please sign in to comment.