Message Boards

How to publish from staging to live programmatically

Carlos Barreiro, modified 2 Years ago.

How to publish from staging to live programmatically

New Member Posts: 16 Join Date: 11/25/19 Recent Posts

Hello, I have a staging and a live environments in two separate servers. I've defined a "publish template" and I want to make publications programmatically from staging to live with that template, but i'm having some problems.

I'm following this article, and it seems that i've got the ExportImportConfiguration instance properly. In the last step, it states that I should use the ExportImportLocalService or the StagingLocalService depending on what process I want to do, and that it only requires the ExportImportConfiguration as a parameter. The problem is that the example only covers the "ExportImportLocalService" case, and I should use the StagingLocalService one, using the publishStagingRequest method, which is requiring one more parameter, the stagingRequestId, but I dont know what is it.

I've seen in the same service that there is a createStagingRequest method, I guess that I should use it, but it requires a "checksum" parameter that I don't know where it comes from

If you could bring me some light i'd be pretty grateful

Regards!

thumbnail
Zsigmond Rab, modified 2 Years ago.

RE: How to publish from staging to live programmatically

Liferay Master Posts: 728 Join Date: 1/5/10 Recent Posts

Hi Carlos,

Have you tried something like this already?

File file = exportLayoutsAsFile(exportImportConfiguration);

String checksum = FileUtil.getMD5Checksum(file);

long stagingRequestId =
    StagingLocalService.createStagingRequest(userId, targetGroupId, checksum);

StagingLocalService.publishStagingRequest(userId, stagingRequestId, exportImportConfiguration);

I haven't tried this by myself, but there is similar logic in the source: https://github.com/liferay/liferay-portal/blob/master/modules/apps/export-import/export-import-service/src/main/java/com/liferay/exportimport/internal/background/task/LayoutRemoteStagingBackgroundTaskExecutor.java#L128-L144

Regards,

Zsigmond

Carlos Barreiro, modified 2 Years ago.

RE: How to publish from staging to live programmatically

New Member Posts: 16 Join Date: 11/25/19 Recent Posts

Hello Zsigmond, sorry for the delay, I couldn't try it until last week :) 

It seems that it's the way for creating the checksum, but, I don't know why, it was creating a large file, probably to publish all files instead of only the last uploaded files. The publish template is configured to only upload the last files so probably there is something that needs to be done before calling the !exportLayoutsAsFile" method so it takes into account the configuration of the template.

Anyways, I followed other path and it worked. I created a BackgroundTask pointing to the exportimportconfigurationid of the publish template, and finally it is publishing the files in the live environment without problems :)

Thanks and regards!