Fórumok

Import web content maintaining the ID

thumbnail
Gabriel Bustos Padilla, módosítva 9 év-val korábban

Import web content maintaining the ID

Junior Member Bejegyzések: 63 Csatlakozás dátuma: 2013.03.06. Legújabb bejegyzések
Hi! I have a problem when I export and import a web content. In my portal_normal.vm of my theme I added the code below to insert a web content in my theme:

#set ($VOID = $velocityPortletPreferences.setValue('groupId', $themeDisplay.getScopeGroupId().toString()))
			#set ($VOID = $velocityPortletPreferences.setValue('articleId', '64397'))
			#set ($VOID = $velocityPortletPreferences.setValue('portletSetupShowBorders', 'false'))
			#set ($portlet_id = '56')
			#set ($my_portlet_id = "${portlet_id}_INSTANCE_1235")
			$theme.runtime($my_portlet_id, "", $velocityPortletPreferences.toString())
			$velocityPortletPreferences.reset()


The problem is that when I export the web content to other portal that uses the same Theme, the articleId changes and then, the code above does not works because the articleId (64397) change to other value (34657). There is any solution to avoid the change of the value of the article ID of the web content?

Thanks in advance
thumbnail
Kyle Joseph Stiemann, módosítva 9 év-val korábban

Moved to Portal Development Category.

Liferay Master Bejegyzések: 760 Csatlakozás dátuma: 2013.01.14. Legújabb bejegyzések
Moved to Liferay Portal - English - 3. Development Category.
thumbnail
Andew Jardine, módosítva 9 év-val korábban

RE: Import web content maintaining the ID

Liferay Legend Bejegyzések: 2416 Csatlakozás dátuma: 2010.12.22. Legújabb bejegyzések
It'd be a bit of a pain in the ass but you could try using the JournalArticleLocalServiceUtil class (loaded using the service locator) and execute the getByUrlTitle( groupId, String urlTitle) method to get the article before the web content embedded piece and then use the article id from the result in your web content preferences.

Not the prettiest, but I think that would do it.
thumbnail
David H Nebinger, módosítva 9 év-val korábban

RE: Import web content maintaining the ID

Liferay Legend Bejegyzések: 14919 Csatlakozás dátuma: 2006.09.02. Legújabb bejegyzések
Gabriel Bustos Padilla:
The problem is that when I export the web content to other portal that uses the same Theme, the articleId changes and then, the code above does not works because the articleId (64397) change to other value (34657). There is any solution to avoid the change of the value of the article ID of the web content?


No.

Seriously, there isn't. The reason is that the IDs are handed out from a counter value to ensure there is no collision in primary keys (ids). When the export takes place on instance A, where 64397 was the assigned ID, there is no reason to believe 64397 was available on instance B. The ID isn't even included in the extract.

The counter on B could be lower (because you haven't been creating articles there or importing all articles or ...) or it could be higher (you do more content creation in B and if you already had an article with ID 64397 you'd end up with a collision).

So content is exported from A and, when imported into B, new IDs are generated for everything imported (article, images, etc) and using hard coded ids will always fail.

You could, however, search for the id instead of just assuming it's there:

## initialize article service
#set ($journalArticleLocalService = $serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleLocalService"))

## get article id for a web content named "footer" (actually the function uses the url generated from the name)
#set ($articleId = $journalArticleLocalService.getArticleByUrlTitle($themeDisplay.getScopeGroupId(), "footer").getArticleId())


This was some code I found by searching google. The forum thread has other implementations if you're using a newer version of Liferay.
thumbnail
Gabriel Bustos Padilla, módosítva 9 év-val korábban

RE: Import web content maintaining the ID

Junior Member Bejegyzések: 63 Csatlakozás dátuma: 2013.03.06. Legújabb bejegyzések
Thanks for the answer. Finally I put like configuring parameters in theme the footer ID and Header ID web content. When I create a new portal, set the new values of the ariticleID of the webcontent and ready!
thumbnail
David H Nebinger, módosítva 9 év-val korábban

RE: Import web content maintaining the ID

Liferay Legend Bejegyzések: 14919 Csatlakozás dátuma: 2006.09.02. Legújabb bejegyzések
Gabriel Bustos Padilla:
Thanks for the answer. Finally I put like configuring parameters in theme the footer ID and Header ID web content. When I create a new portal, set the new values of the ariticleID of the webcontent and ready!


Same kind of thing works but with article titles. that way you're not dependent whatsoever on IDs, you just need to use a standard name for the header and footer.
thumbnail
Gabriel Bustos Padilla, módosítva 9 év-val korábban

RE: Import web content maintaining the ID

Junior Member Bejegyzések: 63 Csatlakozás dátuma: 2013.03.06. Legújabb bejegyzések
Same kind of thing works but with article titles. that way you're not dependent whatsoever on IDs, you just need to use a standard name for the header and footer.


This is the best solution, but I didn´t know that this would be possible, I will investigate then how to invoke by name, thanks!
thumbnail
Miroslav Ligas, módosítva 9 év-val korábban

RE: Import web content maintaining the ID

Regular Member Bejegyzések: 152 Csatlakozás dátuma: 2014.07.29. Legújabb bejegyzések
It might not be possible to move content with ID's. The problem is that the moved ID might be already taken on the destination system.

You can work the problem around with manual configuration:
- the ID will be configurable with the theme properties
- the theme will contain just the empty web content display portlet and you will configure it on the page

Or you can change the logic. If you use unique titles, you can find the necessary article with the usage of the Liferay API. From the journal article object you can then get the article Id.
thumbnail
Sushil Saini, módosítva 9 év-val korábban

RE: Import web content maintaining the ID

Regular Member Bejegyzések: 104 Csatlakozás dátuma: 2011.07.27. Legújabb bejegyzések
Hi Gabrial,

To solve the exactly same problem, I am using the manually defined article ids. By overriding the value of following Liferay portal property to false, Liferay will allow to define the manual article id at the time of content creation. Default value of this property is 'true'.

    
    #
    # Set this to true if article ids should always be autogenerated.
    #
    journal.article.force.autogenerate.id=false


In case of the manually defined article id, when you import and export the LAR file from one portal to another portal. Liferay will maintain the same article id.

Thanks
Sushil Kumar