Recent Bloggers

Saurang Suthar
Posts: 5
Stars: 0
Date: 7/4/17
Jyoti Verma
Posts: 3
Stars: 0
Date: 6/28/17
Pankti Patel
Posts: 1
Stars: 0
Date: 5/26/17
Chandrika Baraiya
Posts: 5
Stars: 0
Date: 5/26/17
Atith Patel
Posts: 5
Stars: 0
Date: 5/22/17
Nisarg Pujara
Posts: 6
Stars: 0
Date: 5/10/17
Pranavsinh Parmar
Posts: 4
Stars: 0
Date: 5/3/17
Ankit Prajapati
Posts: 5
Stars: 0
Date: 5/3/17
Pratik Solanki
Posts: 5
Stars: 0
Date: 4/7/17
Chirag Patel
Posts: 4
Stars: 0
Date: 3/30/17
« Back

Enable Liferay staging programmatically

As we know Liferay provides staging functionality with which we can assemble, test and review new versions of a website before it goes to production. With a staging functionality, clone of a site gets created in which one is a staging site and other is a live site. User can only edit content of staging site and not of a live site. After doing all required changes and reviewing content, user can publish content to live site with “Publish to Live” button that Liferay provides out of the box.

 

Liferay provides two type of staging:

            1. local live staging.

            2. remote live staging.

 

In the local live staging, staging environment and local environment are hosted on same server. In the remote staging, staging environment and local environment are hosted on different server instance may be on different physical machines.

 

You can find more information about staging feature in liferay and how to enable it in control panel from here.

 

In this blog, I have covered that how we can enable staging in liferay programmatically.

 

Liferay by default staged some of the portlet like web content, document and media etc. To enable staging programmatically, below is the Liferay API.

 

StagingLocalServiceUtil.enableLocalStaging(long userId, Group
 liveGroup, boolean branchingPublic, boolean branchingPrivate, ServiceContext serviceContext)

 

Explanation For the Parameters :

 

  1. userId : It is current userId.
  2. liveGroup : It is group(site) object for that you need to enable staging feature.
  3. branchingPublic : set this to true if you want to enable page versioning for the public pages.
  4. branchingPrivate: set this to true if you want to enable page versioning for the private pages.

After adding this method into your code, you are able to enable staging for your site.

 

If you want to add more portlet in staged portlet category other than Liferay default staged portlets, then you have to set it into serviceContext’s attribute.

 

For example, if you want stage blog portlet then you need to set serviceContext’s attribute as shown below:

 

ServiceContext serviceContext = ServiceContextFactory.getInstance(Group.class.getName(), actionRequest);
serviceContext.setAttribute(StagingConstants.STAGED_PORTLET+"161", true); // add blog portlet in staged portlet list

 

Explanation :

 

In the above code, I have set attribute name as StagingConstants.STAGED_PORTLET+"161” to true in which StagingConstants.STAGED_PORTLET is liferay constant prefix and 161 is portlet id (here blog portlet id).

 

So you can add other portlet by the same way setting StagingConstants.STAGED_PORTLET+”portletId” attribute to true in serviceContext.

 

You can check that portlet is staged successfully by going into site’s control panel where you can see check mark against blog portlet.

 

One more thing, if you need to enable main variation for the staging site then you could do it by following code :

 

LayoutSetBranch layoutSetBranch =  LayoutSetBranchLocalServiceUtil.getLayoutSetBranch(groupId, false, LayoutSetBranchConstants.MASTER_BRANCH_NAME);
        
LayoutSetBranchLocalServiceUtil.updateLayoutSetBranch(layoutSetBranch);

 

Complete  code for Enabling Liferay Staging :

 

ServiceContext serviceContext = ServiceContextFactory.getInstance(Group.class.getName(), actionRequest);
serviceContext.setAttribute(StagingConstants.STAGED_PORTLET+"161", true);

StagingLocalServiceUtil.enableLocalStaging(long userId, Group liveGroup, boolean branchingPublic, boolean branchingPrivate, ServiceContext serviceContext);

LayoutSetBranch layoutSetBranch =  LayoutSetBranchLocalServiceUtil.getLayoutSetBranch(groupId, false, LayoutSetBranchConstants.MASTER_BRANCH_NAME);
        
LayoutSetBranchLocalServiceUtil.updateLayoutSetBranch(layoutSetBranch);

 

For more implementation details or support you may contact us at enquiry@surekhatech.com.

Comments
Trackback URL:

No comments yet. Be the first.

Contact Us

Loading

Get in touch

Headquarter :
302, Landmark,
Nr. Titanium City Center,
Prahlad Nagar Road,
Ahmedabad, India - 380015.