Fórum

Remove old versions for database upgrade

Adam Brown, modificado 6 Anos atrás.

Remove old versions for database upgrade

Junior Member Postagens: 27 Data de Entrada: 17/07/17 Postagens Recentes
We're moving from Liferay 6.2 to 7 and need to upgrade the database. Using Oracle 12c, if that makes any difference.

We have lots and lots of revisions. An insane amount. The journal.articles.index.all.versions property can remove old versions in the index. However, I want to actually remove those old versions so they aren't updated to the 7.0 version. I would also like to disable saving old versions, if that's possible.

To pull all the old stuff out, I've heard of only one way to do this, but I can't find any examples. The way I heard is to create a new database (still 6.2 compatible), run a migration tool, exclude all but the newest versions, and done. That way, we can upgrade only what we want to 7. Is this a real thing?

Any thoughts?

Thanks!
thumbnail
David H Nebinger, modificado 6 Anos atrás.

RE: Remove old versions for database upgrade

Liferay Legend Postagens: 14919 Data de Entrada: 02/09/06 Postagens Recentes
IIRC there was a marketplace plugin for version cleanups? I could be wrong, though.
Adam Brown, modificado 6 Anos atrás.

RE: Remove old versions for database upgrade

Junior Member Postagens: 27 Data de Entrada: 17/07/17 Postagens Recentes
All I could find was this: https://web.liferay.com/marketplace/-/mp/application/36783149

Hasn't been updated in quite a while. Not quite the bulk operation either.

This looks promising though: https://web.liferay.com/web/mitesh/blog/-/blogs/how-to-clean-previous-version-of-documents-from-document-and-media
thumbnail
Olaf Kock, modificado 6 Anos atrás.

RE: Remove old versions for database upgrade

Liferay Legend Postagens: 6403 Data de Entrada: 23/09/08 Postagens Recentes
In addition to this cleanup, you'll need Antonio's Oracle interface for Liferay 7, already during the upgrade process, and definitely later during operation.
thumbnail
Alberto Chaparro, modificado 6 Anos atrás.

RE: Remove old versions for database upgrade

Liferay Master Postagens: 549 Data de Entrada: 25/04/11 Postagens Recentes
Hi Adam,

To cleanup articles you can create a groovy script which calls the API to remove intermediate versions before the upgrade.
thumbnail
Daniel Tyger, modificado 6 Anos atrás.

RE: Remove old versions for database upgrade

Regular Member Postagens: 105 Data de Entrada: 06/02/13 Postagens Recentes
Alberto Chaparro:
Hi Adam,

To cleanup articles you can create a groovy script which calls the API to remove intermediate versions before the upgrade.


Alberto - can you share such a script / sample?
thumbnail
Alberto Chaparro, modificado 6 Anos atrás.

RE: Remove old versions for database upgrade

Liferay Master Postagens: 549 Data de Entrada: 25/04/11 Postagens Recentes
Hi Daniel,

You can do something like this:

Get the number of JournalArticleResource:
		int articlesResourcesCount =
			JournalArticleResourceLocalServiceUtil.
				getJournalArticleResourcesCount();


Run through the JournalArticleResources:
List<journalarticleresource> journalArticleResources =
				JournalArticleResourceLocalServiceUtil.
					getJournalArticleResources(start, end);</journalarticleresource>


Run through the list of JournalArticleResource to get the related JournalArticle (using a Dynamic query due to the performance):
				DynamicQuery dq =
					DynamicQueryFactoryUtil.forClass(JournalArticle.class)
						.setProjection(ProjectionFactoryUtil.projectionList()
							.add(ProjectionFactoryUtil.property("id"))
							.add(ProjectionFactoryUtil.property("version"))
							.add(ProjectionFactoryUtil.property("status")))
						.add(PropertyFactoryUtil.forName("groupId")
							.eq(journalArticeResource.getGroupId()))
						.add(PropertyFactoryUtil.forName("articleId")
							.eq(journalArticeResource.getArticleId()))
						.addOrder(OrderFactoryUtil.asc("version"));


Run through the list of JournalArticle and remove the articles you consider depending on the version, status, etc.:
					JournalArticleLocalServiceUtil.deleteArticle(
						groupId, articleId, version, null, null);


(This examples are from 6.0.x but the API are still available, maybe they have a few more parameters)

I hope it helps.

Regards.
thumbnail
Daniel Tyger, modificado 6 Anos atrás.

RE: Remove old versions for database upgrade

Regular Member Postagens: 105 Data de Entrada: 06/02/13 Postagens Recentes
Alberto Chaparro:

You can do something like this:
...
I hope it helps.

Regards.


Thank you, very kindly Alberto!
thumbnail
Daniel Tyger, modificado 5 Anos atrás.

RE: Remove old versions for database upgrade

Regular Member Postagens: 105 Data de Entrada: 06/02/13 Postagens Recentes
Alberto Chaparro:
Hi Daniel,
You can do something like this:
(These examples are from 6.0.x but the API are still available, maybe they have a few more parameters)
Regards.

I know it's been a while, but... for anyone else who wants a complete script that accomplishes this in Liferay 6.2:
https://web.liferay.com/web/daniel.tyger/blog/-/blogs/pre-upgrade-scripting-6-2-dxp-pt-3-web-content-version-cleanup
thumbnail
David H Nebinger, modificado 5 Anos atrás.

RE: Remove old versions for database upgrade

Liferay Legend Postagens: 14919 Data de Entrada: 02/09/06 Postagens Recentes
Nice job, Daniel!
thumbnail
Alberto Chaparro, modificado 5 Anos atrás.

RE: Remove old versions for database upgrade

Liferay Master Postagens: 549 Data de Entrada: 25/04/11 Postagens Recentes
Never is too late Daniel, this is an amazing job!

Thank you so much for sharing!
Adam Brown, modificado 6 Anos atrás.

RE: Remove old versions for database upgrade

Junior Member Postagens: 27 Data de Entrada: 17/07/17 Postagens Recentes
Olaf Kock:
In addition to this cleanup, you'll need Antonio's Oracle interface for Liferay 7, already during the upgrade process, and definitely later during operation.


We're using EE, I forgot to mention. So we're covered.

Thanks for pointing out the groovy script!

Also, is there any way to disable versioning in Liferay 6 or 7?
thumbnail
Alberto Chaparro, modificado 6 Anos atrás.

RE: Remove old versions for database upgrade

Liferay Master Postagens: 549 Data de Entrada: 25/04/11 Postagens Recentes
Hi Adam,

No, there is no way to disable versioning in journal articles yet.

Regards.