0

I need to create the delete functionality to delete the contents trought my custom portlet.

I've tested the following sentences but all of them, delete the latest version of the content, but the rest still there.

JournalArticleLocalServiceUtil.deleteArticle(themeDisplay.getCompanyId(), article.getArticleId(), sc);
JournalArticleLocalServiceUtil.deleteJournalArticle(article);
JournalArticleLocalServiceUtil.deleteArticle(article);
JournalArticleLocalServiceUtil.deleteArticle(article, SLASH, sc);
JournalArticleServiceUtil.deleteArticle(themeDisplay.getCompanyGroupId(), article.getArticleId(), SLASH, sc);

Is there any method in Liferay API to delete all the versions or I have to loop over the version and delete it one by one?

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • Have you tried `JournalArticleLocalServiceUtil.deleteArticle( long groupId, String articleId, ServiceContext serviceContext)`, based on method comments in source file, it seems this method deletes all resources related to article.? – Pankaj Kathiriya May 11 '16 at 14:31
  • Yeah Pankajkumar,, i've tried it. In fact, is the first example i posted, but delete the lastest version only – Iñigo Boyano Ferrer May 11 '16 at 14:42
  • First example you posted have first parameter as companyId, but this method has groupId. Have you passed companyId by mistake? – Pankaj Kathiriya May 11 '16 at 15:04
  • Sorry, i was testing with differents Id's,this is the last example. – Iñigo Boyano Ferrer May 12 '16 at 06:33
  • As @PankajkumarKathiriya said, if you saw the api, that one should fit your needs. ** deleteArticle(long groupId, String articleId, ServiceContext serviceContext) ** Maybe you're using a different groupId? Try with themeDisplay.getScopeGroupId() to retrieve the groupId https://github.com/liferay/liferay-portal/blob/6.2.3-ga4/portal-impl/src/com/liferay/portlet/journal/service/impl/JournalArticleLocalServiceImpl.java – Jorge May 13 '16 at 19:00

1 Answers1

1

I had the same problem and solved it with this code:

List<JournalArticle> versiones=JournalArticleLocalServiceUtil.getArticles(groupId, articleId);
for (int j = 0; j < versiones.size(); j++) {
   JournalArticle version=versiones.get(j);
   JournalArticleLocalServiceUtil.deleteArticle(groupId, version.getArticleId(), version.getVersion(), null,null)
}
andymrg
  • 204
  • 4
  • 14