Foren

Using default.user.public.layouts in portal-ext.properties not working.

Marcus Iorio, geändert vor 12 Jahren.

Using default.user.public.layouts in portal-ext.properties not working.

New Member Beiträge: 24 Beitrittsdatum: 26.01.12 Neueste Beiträge
My continued quest to import a lar file via the portal-ext.properties file. emoticon

Goal is to export a lar file at the organization level from Server A, then import the .lar file via portal-ext.properties from Server B.

No issues with the export. I go to Manage-> Control Panel -> Organizations -> click on the Organization I want to export -> click on 'Manage Pages' from the popup menu -> click on 'Export/Import' link --> then click the 'Export' Button. All Good.

portal-ext.properties on Server B would like:
include-and-override=portal-ide.properties
default.user.public.layouts.lar=C:/lars/MarcTest-201202022159.lar

I've tested this, and it doesn't import.

So is default.user.public.layouts.lar the right syntax to be importing a organization lar.

I tried: default.organization.public.layouts.lar -> no workie

From all the research I have done, there hasn't been a solid example on how to do this.

Has anyone had any luck getting the import from the portal-ext.properties to work?

Thanks,
-Marcus
thumbnail
Samuel Kong, geändert vor 12 Jahren.

RE: Using default.user.public.layouts in portal-ext.properties not working.

Liferay Legend Beiträge: 1902 Beitrittsdatum: 10.03.08 Neueste Beiträge
Marcus, what version of Liferay Portal are you using?
Marcus Iorio, geändert vor 12 Jahren.

RE: Using default.user.public.layouts in portal-ext.properties not working.

New Member Beiträge: 24 Beitrittsdatum: 26.01.12 Neueste Beiträge
Hello Samuel,
liferay-portal-6.0.6
Thanks!
thumbnail
Sandeep Nair, geändert vor 12 Jahren.

RE: Using default.user.public.layouts in portal-ext.properties not working.

Liferay Legend Beiträge: 1744 Beitrittsdatum: 06.11.08 Neueste Beiträge
Are you trying to login with a user who has already logged in to Liferay before this property was set. If so the pages will not be part of his public pages. This will work for any new user created after the property was set and is logging in for the first time(this is more important because logic in ServicePreAction checks if user has public pages already available if not then only create new pages).

For existing users you will have to delete their public pages as admin and then the user has to login once again.

Regards,
Sandeep
Marcus Iorio, geändert vor 12 Jahren.

RE: Using default.user.public.layouts in portal-ext.properties not working.

New Member Beiträge: 24 Beitrittsdatum: 26.01.12 Neueste Beiträge
Hello Sandeep,

"Are you trying to login with a user who has already logged in to Liferay before this property was set."
I thought this was an action that would fire when I started the server.

Just to state the goal here: (which may not be achievable with using portal-ext.properties)
My firm has 5 test regions, two data centers with over 5+ web servers in each datacenter. So you can see why we can't use the internal 'staging' 'prod' cms provided by Liferay.

So my initial test is to see if I can Export a lar for public pages at the 'organization' level from server A, put the file in a directory on server B, and have the instance of Liferay on server B read in the lar automatically upon startup. Thus adding or updating any changes to that organization's public pages on server B that were made on server A.

I can't expect someone to go into each test region, log into liferay and make those updates 5 times. Not to mention 10+ servers in our data centers.

So, once we can export a lar from server A and then have server B import it automatically, we will have a plan on how to proceed with our test regions and production servers.

I have been researching this for some time now, with not much luck. I'm just hoping someone else had the same issue and was able to resolve it, and can share their solution.

Thanks,
Marcus
thumbnail
Sandeep Nair, geändert vor 12 Jahren.

RE: Using default.user.public.layouts in portal-ext.properties not working.

Liferay Legend Beiträge: 1744 Beitrittsdatum: 06.11.08 Neueste Beiträge
Oh those properties are for user pages only. It will not work for organization.

I believe there is scheduled staging available, so that you can fix a time and the changes are published to other server on a daily basis at an appropriate time

Regards,
Sandeep
thumbnail
Samuel Kong, geändert vor 12 Jahren.

RE: Using default.user.public.layouts in portal-ext.properties not working.

Liferay Legend Beiträge: 1902 Beitrittsdatum: 10.03.08 Neueste Beiträge
Marcus Iorio:
"Are you trying to login with a user who has already logged in to Liferay before this property was set."
I thought this was an action that would fire when I started the server.


I've tested this and it works as expected. As Sandeep noted, the specified LAR is only used when you create a new user logins. It has no effect on users that already exists. This property will not update any existing data on your target server.

If you're having problems getting this to work, please make sure that when you are on the export page that you select all the data under "What would you like to export? ".

Just to state the goal here: (which may not be achievable with using portal-ext.properties)
My firm has 5 test regions, two data centers with over 5+ web servers in each datacenter. So you can see why we can't use the internal 'staging' 'prod' cms provided by Liferay.

So my initial test is to see if I can Export a lar for public pages at the 'organization' level from server A, put the file in a directory on server B, and have the instance of Liferay on server B read in the lar automatically upon startup. Thus adding or updating any changes to that organization's public pages on server B that were made on server A.

I can't expect someone to go into each test region, log into liferay and make those updates 5 times. Not to mention 10+ servers in our data centers.

So, once we can export a lar from server A and then have server B import it automatically, we will have a plan on how to proceed with our test regions and production servers.

I have been researching this for some time now, with not much luck. I'm just hoping someone else had the same issue and was able to resolve it, and can share their solution.

Thanks,
Marcus


What you probably want to do is just simply export your LAR from server A and then import the LAR on server B. You can automate this process by:

1) Create a class and add this class to the "global.startup.events" property so that it will be triggered when the portal starts up.
2) From this class, you can call LayoutLocalServiceUtil.importLayouts() to import your LAR.
Marcus Iorio, geändert vor 12 Jahren.

RE: Using default.user.public.layouts in portal-ext.properties not working. (Antwort)

New Member Beiträge: 24 Beitrittsdatum: 26.01.12 Neueste Beiträge
SOLVED.
Here's our solution. It works well.
Created a new liferay project
- selected plugin type as 'Hook'
Click Finish
Expand new hook project
Right click on Java Resources: src
- New -> Package
- name it com.XXXX.importLar (XXXX should be your domain)
Right click on Package
- New -> class
Name it ImportLar
Here's the code for ImportLar.java:

package com.xxxxxxxx.importlar;
import java.util.HashMap;
import java.util.Map;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;

import com.liferay.portal.kernel.events.ActionException;
import com.liferay.portal.kernel.events.SimpleAction;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.lar.PortletDataHandlerKeys;
import com.liferay.portal.service.LayoutLocalServiceUtil;
import com.liferay.portal.kernel.lar.UserIdStrategy;

public class ImportLar extends SimpleAction
{
public void getLar() throws PortalException, SystemException, IOException {

Map<String, String[]> parameterMap = new HashMap<String, String[]>();
parameterMap.put( PortletDataHandlerKeys.DATA_STRATEGY, new String[] {PortletDataHandlerKeys.DATA_STRATEGY_MIRROR});
parameterMap.put( PortletDataHandlerKeys.USER_ID_STRATEGY, new String[] {UserIdStrategy.CURRENT_USER_ID});
parameterMap.put( PortletDataHandlerKeys.DELETE_MISSING_LAYOUTS, new String[] {Boolean.FALSE.toString()});
parameterMap.put( PortletDataHandlerKeys.PERMISSIONS, new String[] {Boolean.FALSE.toString()});
parameterMap.put( PortletDataHandlerKeys.PORTLET_DATA, new String[] {Boolean.TRUE.toString()});
parameterMap.put( PortletDataHandlerKeys.PORTLET_DATA_ALL, new String[] {Boolean.TRUE.toString()});
parameterMap.put( PortletDataHandlerKeys.PORTLET_DATA_CONTROL_DEFAULT, new String[] {Boolean.FALSE.toString()});
parameterMap.put( PortletDataHandlerKeys.PORTLET_SETUP, new String[] {Boolean.TRUE.toString()});
parameterMap.put( PortletDataHandlerKeys.USER_PERMISSIONS, new String[] {Boolean.FALSE.toString()});
parameterMap.put( PortletDataHandlerKeys.PORTLET_ARCHIVED_SETUPS, new String[] {Boolean.FALSE.toString()});
parameterMap.put( PortletDataHandlerKeys.CATEGORIES, new String[] {Boolean.FALSE.toString()});
parameterMap.put( PortletDataHandlerKeys.PORTLET_USER_PREFERENCES, new String[] {Boolean.TRUE.toString()});


String[][] larFileNames = {
//{"lars directory on server","Organization ID"}
//Example: {"C:\\lars\\xxxxxxxx.lar","#####"}
{"C:\\lars\\xxxxxxxx.lar","#####"}
};

for (int i=0;i<larFileNames.length;i++) {

String larFileName = larFileNames[0];
Long larOrganizationID = Long.valueOf(larFileNames[1]);

File larFileCheck = new File(larFileName);
boolean larFileExists = larFileCheck.exists();

if (larFileExists){

System.out.println(larFileName);
System.out.println(larOrganizationID);

RandomAccessFile larFile = new RandomAccessFile(larFileName, "r");

byte[] byteLarFile = new byte[(int)larFile.length()];
larFile.read(byteLarFile);
larFile.close();

LayoutLocalServiceUtil.importLayouts( 10870, larOrganizationID , false, parameterMap, byteLarFile);

File larFileDelete = new File(larFileName);

boolean success = larFileDelete.delete();
if (!success){
System.out.println("File Deletion Failed.");
}else{
System.out.println("File Deletion Passed.");
}

}
}
}

@Override
public void run(String[] arg0) throws ActionException {
// TODO Auto-generated method stub
System.out.println("Begin Import lar hook execute");
try {
getLar();
} catch (PortalException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SystemException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("End Import lar hook execute");
}
}

Make sure you update:
package com.xxxxxxxx.importlar; to match your Package name
{"C:\\lars\\xxxxxxxx.lar","#####"} to match your lar file name / organization ID and lar location on your server.

Build it, add it to your server.
Thanks to all for the ideas that led to our solution.
-Marcus
John Gordon, geändert vor 11 Jahren.

RE: Using default.user.public.layouts in portal-ext.properties not working.

New Member Beiträge: 3 Beitrittsdatum: 05.11.12 Neueste Beiträge
I'm trying to do this also. Many thanks for the code sample! However, it looks like the lar import will only happen when the portal is started up -- a restart of the server ,correct? I'd like to avoid having to restart my environment in order to just import a lar file. Is there some way I can register my hook to be run every 5 minutes or so?

I've created a post describing my needs a bit more.
Thanks!