Fórum

Add new webcontent version programatically

Tamas Toth, modificado 9 Anos atrás.

Add new webcontent version programatically

New Member Postagens: 10 Data de Entrada: 23/07/13 Postagens Recentes
I would like to edit a webcontent (journalarticle) in Liferay and create a new version from that from a custom portlet. I call the JournalArticleLocalServiceUtil.addArticle() method with the following relevant parameters:

articleId = article.getArticleId();
autoArticleId = false;
version = article.getVersion()+0.1;


So the old articleId, and the version increased.

This code works in LR 6.1.30EE, but in 6.1.20EE and 6.1.1CE I got a DuplicateArticleIdException. Is this a bug in the earlier version? Is there a workaround or another method to create a new version of an existing webcontent programatically?

Minor question: what is the correct mode of increasing the version? The above +0.1 way creates from v1.1 v1.200000000000002, but simply v1.2 would be preferable.

Note: updateArticle() method with a new version does not work either, it throws ArticleVersionException. It seems the right behavoiur as it should update already existing content.
thumbnail
Andew Jardine, modificado 9 Anos atrás.

RE: Add new webcontent version programatically

Liferay Legend Postagens: 2416 Data de Entrada: 22/12/10 Postagens Recentes
Hey Tamas,

best way to sort through something like this is to see how Liferay itself does it. If you have the portal source, you can start by checking out the struts-config.xml file. In there look for "article" and you will eventually find a reference to the EditArticleAction class. If you open this class up you will see that it contains the java code for everything article related. Around line 704 (I am looking at Liferay 6.2CE but I doubt there is a HUGE difference -- just look for the // Update article comment) you will see the bit tht specifically updates the article. There is a lot of prep work done before mind you -- so probably worth giving the whole method, if not the class a study.

https://github.com/liferay/liferay-portal/blob/master/portal-impl/src/com/liferay/portlet/journal/action/EditArticleAction.java
Tamas Toth, modificado 9 Anos atrás.

RE: Add new webcontent version programatically (Resposta)

New Member Postagens: 10 Data de Entrada: 23/07/13 Postagens Recentes
Hi Andew,

thank you for your suggestion! I checked the class you pointed out, made some tries and find the solution:

The right method is to call JournalArticleLocalServiceUtil.updateArticle, but with the old version. Liferay automatically decides when to create a new version, and takes care of assigning the right version. So I overcomplicated a little bit. emoticon
thumbnail
Andew Jardine, modificado 9 Anos atrás.

RE: Add new webcontent version programatically

Liferay Legend Postagens: 2416 Data de Entrada: 22/12/10 Postagens Recentes
Tamas,

Great! glad you found the solution. There are parts of Liferay's API that are HUGE and often there is more than one way to perform the same action. Best thing to do is just what you have done -- find out how LIFERAY does it and follow their lead.