001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.sites.action;
016    
017    import com.liferay.portal.DuplicateGroupException;
018    import com.liferay.portal.GroupFriendlyURLException;
019    import com.liferay.portal.GroupNameException;
020    import com.liferay.portal.LayoutSetVirtualHostException;
021    import com.liferay.portal.LocaleException;
022    import com.liferay.portal.NoSuchGroupException;
023    import com.liferay.portal.NoSuchLayoutException;
024    import com.liferay.portal.RemoteExportException;
025    import com.liferay.portal.RemoteOptionsException;
026    import com.liferay.portal.RequiredGroupException;
027    import com.liferay.portal.kernel.dao.orm.QueryUtil;
028    import com.liferay.portal.kernel.exception.PortalException;
029    import com.liferay.portal.kernel.exception.SystemException;
030    import com.liferay.portal.kernel.servlet.SessionErrors;
031    import com.liferay.portal.kernel.staging.StagingUtil;
032    import com.liferay.portal.kernel.util.Constants;
033    import com.liferay.portal.kernel.util.GetterUtil;
034    import com.liferay.portal.kernel.util.HttpUtil;
035    import com.liferay.portal.kernel.util.ListUtil;
036    import com.liferay.portal.kernel.util.ParamUtil;
037    import com.liferay.portal.kernel.util.PrefsPropsUtil;
038    import com.liferay.portal.kernel.util.PropertiesParamUtil;
039    import com.liferay.portal.kernel.util.PropsKeys;
040    import com.liferay.portal.kernel.util.StringPool;
041    import com.liferay.portal.kernel.util.StringUtil;
042    import com.liferay.portal.kernel.util.UnicodeProperties;
043    import com.liferay.portal.kernel.util.UniqueList;
044    import com.liferay.portal.kernel.util.Validator;
045    import com.liferay.portal.liveusers.LiveUsers;
046    import com.liferay.portal.model.Group;
047    import com.liferay.portal.model.GroupConstants;
048    import com.liferay.portal.model.Layout;
049    import com.liferay.portal.model.LayoutConstants;
050    import com.liferay.portal.model.LayoutSet;
051    import com.liferay.portal.model.MembershipRequest;
052    import com.liferay.portal.model.MembershipRequestConstants;
053    import com.liferay.portal.model.Role;
054    import com.liferay.portal.model.Team;
055    import com.liferay.portal.security.auth.PrincipalException;
056    import com.liferay.portal.service.GroupLocalServiceUtil;
057    import com.liferay.portal.service.GroupServiceUtil;
058    import com.liferay.portal.service.LayoutLocalServiceUtil;
059    import com.liferay.portal.service.LayoutSetServiceUtil;
060    import com.liferay.portal.service.MembershipRequestLocalServiceUtil;
061    import com.liferay.portal.service.MembershipRequestServiceUtil;
062    import com.liferay.portal.service.RoleLocalServiceUtil;
063    import com.liferay.portal.service.ServiceContext;
064    import com.liferay.portal.service.ServiceContextFactory;
065    import com.liferay.portal.service.TeamLocalServiceUtil;
066    import com.liferay.portal.struts.PortletAction;
067    import com.liferay.portal.theme.ThemeDisplay;
068    import com.liferay.portal.util.PortalUtil;
069    import com.liferay.portal.util.WebKeys;
070    import com.liferay.portlet.asset.AssetCategoryException;
071    import com.liferay.portlet.asset.AssetTagException;
072    import com.liferay.portlet.sites.util.SitesUtil;
073    import com.liferay.portlet.trash.util.TrashUtil;
074    
075    import java.util.ArrayList;
076    import java.util.List;
077    
078    import javax.portlet.ActionRequest;
079    import javax.portlet.ActionResponse;
080    import javax.portlet.PortletConfig;
081    import javax.portlet.PortletRequest;
082    import javax.portlet.RenderRequest;
083    import javax.portlet.RenderResponse;
084    
085    import org.apache.struts.action.ActionForm;
086    import org.apache.struts.action.ActionForward;
087    import org.apache.struts.action.ActionMapping;
088    
089    /**
090     * @author Brian Wing Shun Chan
091     * @author Zsolt Berentey
092     */
093    public class EditGroupAction extends PortletAction {
094    
095            @Override
096            public void processAction(
097                            ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
098                            ActionRequest actionRequest, ActionResponse actionResponse)
099                    throws Exception {
100    
101                    ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
102                            WebKeys.THEME_DISPLAY);
103    
104                    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
105    
106                    String redirect = ParamUtil.getString(actionRequest, "redirect");
107                    String closeRedirect = ParamUtil.getString(
108                            actionRequest, "closeRedirect");
109    
110                    try {
111                            if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
112                                    Object[] returnValue = updateGroup(actionRequest);
113    
114                                    Group group = (Group)returnValue[0];
115                                    String oldFriendlyURL = (String)returnValue[1];
116                                    String oldStagingFriendlyURL = (String)returnValue[2];
117                                    long newRefererPlid = (Long)returnValue[3];
118    
119                                    redirect = HttpUtil.setParameter(
120                                            redirect, "doAsGroupId", group.getGroupId());
121                                    redirect = HttpUtil.setParameter(
122                                            redirect, "refererPlid", newRefererPlid);
123    
124                                    closeRedirect = updateCloseRedirect(
125                                            closeRedirect, group, themeDisplay, oldFriendlyURL,
126                                            oldStagingFriendlyURL);
127                            }
128                            else if (cmd.equals(Constants.DEACTIVATE) ||
129                                             cmd.equals(Constants.RESTORE)) {
130    
131                                    updateActive(actionRequest, cmd);
132                            }
133                            else if (cmd.equals(Constants.DELETE)) {
134                                    deleteGroups(actionRequest);
135                            }
136    
137                            sendRedirect(
138                                    portletConfig, actionRequest, actionResponse, redirect,
139                                    closeRedirect);
140                    }
141                    catch (Exception e) {
142                            if (e instanceof NoSuchGroupException ||
143                                    e instanceof PrincipalException) {
144    
145                                    SessionErrors.add(actionRequest, e.getClass());
146    
147                                    setForward(actionRequest, "portlet.sites_admin.error");
148                            }
149                            else if (e instanceof AssetCategoryException ||
150                                             e instanceof AssetTagException ||
151                                             e instanceof DuplicateGroupException ||
152                                             e instanceof GroupFriendlyURLException ||
153                                             e instanceof GroupNameException ||
154                                             e instanceof LayoutSetVirtualHostException ||
155                                             e instanceof LocaleException ||
156                                             e instanceof RemoteExportException ||
157                                             e instanceof RemoteOptionsException ||
158                                             e instanceof RequiredGroupException ||
159                                             e instanceof SystemException) {
160    
161                                    SessionErrors.add(actionRequest, e.getClass(), e);
162    
163                                    sendRedirect(
164                                            portletConfig, actionRequest, actionResponse, redirect,
165                                            closeRedirect);
166                            }
167                            else {
168                                    throw e;
169                            }
170                    }
171            }
172    
173            @Override
174            public ActionForward render(
175                            ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
176                            RenderRequest renderRequest, RenderResponse renderResponse)
177                    throws Exception {
178    
179                    try {
180                            ActionUtil.getGroup(renderRequest);
181                    }
182                    catch (Exception e) {
183                            if (e instanceof NoSuchGroupException ||
184                                    e instanceof PrincipalException) {
185    
186                                    SessionErrors.add(renderRequest, e.getClass());
187    
188                                    return mapping.findForward("portlet.sites_admin.error");
189                            }
190                            else {
191                                    throw e;
192                            }
193                    }
194    
195                    return mapping.findForward(
196                            getForward(renderRequest, "portlet.sites_admin.edit_site"));
197            }
198    
199            protected void deleteGroups(ActionRequest actionRequest) throws Exception {
200                    ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
201                            WebKeys.THEME_DISPLAY);
202    
203                    long[] deleteGroupIds = null;
204    
205                    long groupId = ParamUtil.getLong(actionRequest, "groupId");
206    
207                    if (groupId > 0) {
208                            deleteGroupIds = new long[] {groupId};
209                    }
210                    else {
211                            deleteGroupIds = StringUtil.split(
212                                    ParamUtil.getString(actionRequest, "deleteGroupIds"), 0L);
213                    }
214    
215                    for (long deleteGroupId : deleteGroupIds) {
216                            GroupServiceUtil.deleteGroup(deleteGroupId);
217    
218                            LiveUsers.deleteGroup(themeDisplay.getCompanyId(), deleteGroupId);
219                    }
220            }
221    
222            protected long getRefererGroupId(ThemeDisplay themeDisplay)
223                    throws Exception {
224    
225                    long refererGroupId = 0;
226    
227                    try {
228                            Layout refererLayout = LayoutLocalServiceUtil.getLayout(
229                                    themeDisplay.getRefererPlid());
230    
231                            refererGroupId = refererLayout.getGroupId();
232                    }
233                    catch (NoSuchLayoutException nsle) {
234                    }
235    
236                    return refererGroupId;
237            }
238    
239            protected List<Role> getRoles(PortletRequest portletRequest)
240                    throws Exception {
241    
242                    List<Role> roles = new ArrayList<Role>();
243    
244                    long[] siteRolesRoleIds = StringUtil.split(
245                            ParamUtil.getString(portletRequest, "siteRolesRoleIds"), 0L);
246    
247                    for (long siteRolesRoleId : siteRolesRoleIds) {
248                            if (siteRolesRoleId == 0) {
249                                    continue;
250                            }
251    
252                            Role role = RoleLocalServiceUtil.getRole(siteRolesRoleId);
253    
254                            roles.add(role);
255                    }
256    
257                    return roles;
258            }
259    
260            protected List<Team> getTeams(PortletRequest portletRequest)
261                    throws Exception {
262    
263                    List<Team> teams = new UniqueList<Team>();
264    
265                    long[] teamsTeamIds= StringUtil.split(
266                            ParamUtil.getString(portletRequest, "teamsTeamIds"), 0L);
267    
268                    for (long teamsTeamId : teamsTeamIds) {
269                            if (teamsTeamId == 0) {
270                                    continue;
271                            }
272    
273                            Team team = TeamLocalServiceUtil.getTeam(teamsTeamId);
274    
275                            teams.add(team);
276                    }
277    
278                    return teams;
279            }
280    
281            protected void updateActive(ActionRequest actionRequest, String cmd)
282                    throws Exception {
283    
284                    ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
285                            WebKeys.THEME_DISPLAY);
286    
287                    long groupId = ParamUtil.getLong(actionRequest, "groupId");
288    
289                    if ((groupId == themeDisplay.getDoAsGroupId()) ||
290                            (groupId == themeDisplay.getScopeGroupId()) ||
291                            (groupId == getRefererGroupId(themeDisplay))) {
292    
293                            throw new RequiredGroupException(
294                                    String.valueOf(groupId), RequiredGroupException.CURRENT_GROUP);
295                    }
296    
297                    Group group = GroupServiceUtil.getGroup(groupId);
298    
299                    boolean active = false;
300    
301                    if (cmd.equals(Constants.RESTORE)) {
302                            active = true;
303                    }
304    
305                    ServiceContext serviceContext = ServiceContextFactory.getInstance(
306                            Group.class.getName(), actionRequest);
307    
308                    GroupServiceUtil.updateGroup(
309                            groupId, group.getParentGroupId(), group.getName(),
310                            group.getDescription(), group.getType(), group.getFriendlyURL(),
311                            active, serviceContext);
312            }
313    
314            protected String updateCloseRedirect(
315                            String closeRedirect, Group group, ThemeDisplay themeDisplay,
316                            String oldFriendlyURL, String oldStagingFriendlyURL)
317                    throws PortalException, SystemException {
318    
319                    if (Validator.isNull(closeRedirect) || (group == null)) {
320                            return closeRedirect;
321                    }
322    
323                    String oldPath = null;
324                    String newPath = null;
325    
326                    if (Validator.isNotNull(oldFriendlyURL)) {
327                            oldPath = oldFriendlyURL;
328                            newPath = group.getFriendlyURL();
329    
330                            if (closeRedirect.contains(oldPath)) {
331                                    closeRedirect = PortalUtil.updateRedirect(
332                                            closeRedirect, oldPath, newPath);
333                            }
334                            else {
335                                    closeRedirect = PortalUtil.getGroupFriendlyURL(
336                                            group, false, themeDisplay);
337                            }
338                    }
339    
340                    if (Validator.isNotNull(oldStagingFriendlyURL)) {
341                            Group stagingGroup = group.getStagingGroup();
342    
343                            if (GroupLocalServiceUtil.fetchGroup(
344                                            stagingGroup.getGroupId()) == null) {
345    
346                                    oldPath = oldStagingFriendlyURL;
347                                    newPath = group.getFriendlyURL();
348                            }
349                            else {
350                                    oldPath = oldStagingFriendlyURL;
351                                    newPath = stagingGroup.getFriendlyURL();
352                            }
353    
354                            if (closeRedirect.contains(oldPath)) {
355                                    closeRedirect = PortalUtil.updateRedirect(
356                                            closeRedirect, oldPath, newPath);
357                            }
358                            else {
359                                    closeRedirect = PortalUtil.getGroupFriendlyURL(
360                                            group, false, themeDisplay);
361                            }
362                    }
363    
364                    return closeRedirect;
365            }
366    
367            protected Object[] updateGroup(ActionRequest actionRequest)
368                    throws Exception {
369    
370                    ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
371                            WebKeys.THEME_DISPLAY);
372    
373                    long userId = PortalUtil.getUserId(actionRequest);
374    
375                    long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
376    
377                    long parentGroupId = ParamUtil.getLong(
378                            actionRequest, "parentGroupSearchContainerPrimaryKeys",
379                            GroupConstants.DEFAULT_PARENT_GROUP_ID);
380                    String name = null;
381                    String description = null;
382                    int type = 0;
383                    String friendlyURL = null;
384                    boolean active = false;
385    
386                    ServiceContext serviceContext = ServiceContextFactory.getInstance(
387                            Group.class.getName(), actionRequest);
388    
389                    Group liveGroup = null;
390                    String oldFriendlyURL = null;
391                    String oldStagingFriendlyURL = null;
392    
393                    if (liveGroupId <= 0) {
394    
395                            // Add group
396    
397                            name = ParamUtil.getString(actionRequest, "name");
398                            description = ParamUtil.getString(actionRequest, "description");
399                            type = ParamUtil.getInteger(actionRequest, "type");
400                            friendlyURL = ParamUtil.getString(actionRequest, "friendlyURL");
401                            active = ParamUtil.getBoolean(actionRequest, "active");
402    
403                            liveGroup = GroupServiceUtil.addGroup(
404                                    parentGroupId, GroupConstants.DEFAULT_LIVE_GROUP_ID, name,
405                                    description, type, friendlyURL, true, active, serviceContext);
406    
407                            LiveUsers.joinGroup(
408                                    themeDisplay.getCompanyId(), liveGroup.getGroupId(), userId);
409                    }
410                    else {
411    
412                            // Update group
413    
414                            liveGroup = GroupLocalServiceUtil.getGroup(liveGroupId);
415    
416                            oldFriendlyURL = liveGroup.getFriendlyURL();
417    
418                            name = ParamUtil.getString(
419                                    actionRequest, "name", liveGroup.getName());
420                            description = ParamUtil.getString(
421                                    actionRequest, "description", liveGroup.getDescription());
422                            type = ParamUtil.getInteger(
423                                    actionRequest, "type", liveGroup.getType());
424                            friendlyURL = ParamUtil.getString(
425                                    actionRequest, "friendlyURL", liveGroup.getFriendlyURL());
426                            active = ParamUtil.getBoolean(
427                                    actionRequest, "active", liveGroup.getActive());
428    
429                            liveGroup = GroupServiceUtil.updateGroup(
430                                    liveGroupId, parentGroupId, name, description, type,
431                                    friendlyURL, active, serviceContext);
432    
433                            if (type == GroupConstants.TYPE_SITE_OPEN) {
434                                    List<MembershipRequest> membershipRequests =
435                                            MembershipRequestLocalServiceUtil.search(
436                                                    liveGroupId, MembershipRequestConstants.STATUS_PENDING,
437                                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS);
438    
439                                    for (MembershipRequest membershipRequest : membershipRequests) {
440                                            MembershipRequestServiceUtil.updateStatus(
441                                                    membershipRequest.getMembershipRequestId(),
442                                                    themeDisplay.translate(
443                                                            "your-membership-has-been-approved"),
444                                                    MembershipRequestConstants.STATUS_APPROVED,
445                                                    serviceContext);
446    
447                                            LiveUsers.joinGroup(
448                                                    themeDisplay.getCompanyId(),
449                                                    membershipRequest.getGroupId(),
450                                                    new long[] {membershipRequest.getUserId()});
451                                    }
452                            }
453                    }
454    
455                    // Settings
456    
457                    UnicodeProperties typeSettingsProperties =
458                            liveGroup.getTypeSettingsProperties();
459    
460                    String customJspServletContextName = ParamUtil.getString(
461                            actionRequest, "customJspServletContextName",
462                            typeSettingsProperties.getProperty("customJspServletContextName"));
463    
464                    typeSettingsProperties.setProperty(
465                            "customJspServletContextName", customJspServletContextName);
466    
467                    typeSettingsProperties.setProperty(
468                            "defaultSiteRoleIds",
469                            ListUtil.toString(
470                                    getRoles(actionRequest), Role.ROLE_ID_ACCESSOR,
471                                    StringPool.COMMA));
472                    typeSettingsProperties.setProperty(
473                            "defaultTeamIds",
474                            ListUtil.toString(
475                                    getTeams(actionRequest), Team.TEAM_ID_ACCESSOR,
476                                    StringPool.COMMA));
477    
478                    String[] analyticsTypes = PrefsPropsUtil.getStringArray(
479                            themeDisplay.getCompanyId(), PropsKeys.ADMIN_ANALYTICS_TYPES,
480                            StringPool.NEW_LINE);
481    
482                    for (String analyticsType : analyticsTypes) {
483                            if (analyticsType.equalsIgnoreCase("google")) {
484                                    String googleAnalyticsId = ParamUtil.getString(
485                                            actionRequest, "googleAnalyticsId",
486                                            typeSettingsProperties.getProperty("googleAnalyticsId"));
487    
488                                    typeSettingsProperties.setProperty(
489                                            "googleAnalyticsId", googleAnalyticsId);
490                            }
491                            else {
492                                    String analyticsScript = ParamUtil.getString(
493                                            actionRequest, SitesUtil.ANALYTICS_PREFIX + analyticsType,
494                                            typeSettingsProperties.getProperty(analyticsType));
495    
496                                    typeSettingsProperties.setProperty(
497                                            SitesUtil.ANALYTICS_PREFIX + analyticsType,
498                                            analyticsScript);
499                            }
500                    }
501    
502                    String publicRobots = ParamUtil.getString(
503                            actionRequest, "publicRobots",
504                            liveGroup.getTypeSettingsProperty("false-robots.txt"));
505                    String privateRobots = ParamUtil.getString(
506                            actionRequest, "privateRobots",
507                            liveGroup.getTypeSettingsProperty("true-robots.txt"));
508    
509                    typeSettingsProperties.setProperty("false-robots.txt", publicRobots);
510                    typeSettingsProperties.setProperty("true-robots.txt", privateRobots);
511    
512                    int trashEnabled = ParamUtil.getInteger(
513                            actionRequest, "trashEnabled",
514                            GetterUtil.getInteger(
515                                    typeSettingsProperties.getProperty("trashEnabled"),
516                                    TrashUtil.TRASH_DEFAULT_VALUE));
517    
518                    typeSettingsProperties.setProperty(
519                            "trashEnabled", String.valueOf(trashEnabled));
520    
521                    int trashEntriesMaxAgeCompany = PrefsPropsUtil.getInteger(
522                            themeDisplay.getCompanyId(), PropsKeys.TRASH_ENTRIES_MAX_AGE);
523    
524                    int defaultTrashEntriesMaxAgeGroup = GetterUtil.getInteger(
525                            typeSettingsProperties.getProperty("trashEntriesMaxAge"),
526                            trashEntriesMaxAgeCompany);
527    
528                    int trashEntriesMaxAgeGroup = ParamUtil.getInteger(
529                            actionRequest, "trashEntriesMaxAge",
530                            defaultTrashEntriesMaxAgeGroup);
531    
532                    if (trashEntriesMaxAgeGroup != trashEntriesMaxAgeCompany) {
533                            typeSettingsProperties.setProperty(
534                                    "trashEntriesMaxAge", String.valueOf(trashEntriesMaxAgeGroup));
535                    }
536                    else {
537                            typeSettingsProperties.remove("trashEntriesMaxAge");
538                    }
539    
540                    int contentSharingWithChildrenEnabled = ParamUtil.getInteger(
541                            actionRequest, "contentSharingWithChildrenEnabled",
542                            GetterUtil.getInteger(
543                                    typeSettingsProperties.getProperty(
544                                            "contentSharingWithChildrenEnabled"),
545                                    SitesUtil.CONTENT_SHARING_WITH_CHILDREN_DEFAULT_VALUE));
546    
547                    typeSettingsProperties.setProperty(
548                            "contentSharingWithChildrenEnabled",
549                            String.valueOf(contentSharingWithChildrenEnabled));
550    
551                    UnicodeProperties formTypeSettingsProperties =
552                            PropertiesParamUtil.getProperties(
553                                    actionRequest, "TypeSettingsProperties--");
554    
555                    typeSettingsProperties.putAll(formTypeSettingsProperties);
556    
557                    // Virtual hosts
558    
559                    LayoutSet publicLayoutSet = liveGroup.getPublicLayoutSet();
560    
561                    String publicVirtualHost = ParamUtil.getString(
562                            actionRequest, "publicVirtualHost",
563                            publicLayoutSet.getVirtualHostname());
564    
565                    LayoutSetServiceUtil.updateVirtualHost(
566                            liveGroup.getGroupId(), false, publicVirtualHost);
567    
568                    LayoutSet privateLayoutSet = liveGroup.getPrivateLayoutSet();
569    
570                    String privateVirtualHost = ParamUtil.getString(
571                            actionRequest, "privateVirtualHost",
572                            privateLayoutSet.getVirtualHostname());
573    
574                    LayoutSetServiceUtil.updateVirtualHost(
575                            liveGroup.getGroupId(), true, privateVirtualHost);
576    
577                    // Staging
578    
579                    if (liveGroup.hasStagingGroup()) {
580                            Group stagingGroup = liveGroup.getStagingGroup();
581    
582                            oldStagingFriendlyURL = stagingGroup.getFriendlyURL();
583    
584                            friendlyURL = ParamUtil.getString(
585                                    actionRequest, "stagingFriendlyURL",
586                                    stagingGroup.getFriendlyURL());
587    
588                            GroupServiceUtil.updateFriendlyURL(
589                                    stagingGroup.getGroupId(), friendlyURL);
590    
591                            LayoutSet stagingPublicLayoutSet =
592                                    stagingGroup.getPublicLayoutSet();
593    
594                            publicVirtualHost = ParamUtil.getString(
595                                    actionRequest, "stagingPublicVirtualHost",
596                                    stagingPublicLayoutSet.getVirtualHostname());
597    
598                            LayoutSetServiceUtil.updateVirtualHost(
599                                    stagingGroup.getGroupId(), false, publicVirtualHost);
600    
601                            LayoutSet stagingPrivateLayoutSet =
602                                    stagingGroup.getPrivateLayoutSet();
603    
604                            privateVirtualHost = ParamUtil.getString(
605                                    actionRequest, "stagingPrivateVirtualHost",
606                                    stagingPrivateLayoutSet.getVirtualHostname());
607    
608                            LayoutSetServiceUtil.updateVirtualHost(
609                                    stagingGroup.getGroupId(), true, privateVirtualHost);
610                    }
611    
612                    liveGroup = GroupServiceUtil.updateGroup(
613                            liveGroup.getGroupId(), typeSettingsProperties.toString());
614    
615                    // Layout set prototypes
616    
617                    if (!liveGroup.isStaged()) {
618                            long privateLayoutSetPrototypeId = ParamUtil.getLong(
619                                    actionRequest, "privateLayoutSetPrototypeId");
620                            long publicLayoutSetPrototypeId = ParamUtil.getLong(
621                                    actionRequest, "publicLayoutSetPrototypeId");
622    
623                            boolean privateLayoutSetPrototypeLinkEnabled = ParamUtil.getBoolean(
624                                    actionRequest, "privateLayoutSetPrototypeLinkEnabled",
625                                    privateLayoutSet.isLayoutSetPrototypeLinkEnabled());
626                            boolean publicLayoutSetPrototypeLinkEnabled = ParamUtil.getBoolean(
627                                    actionRequest, "publicLayoutSetPrototypeLinkEnabled",
628                                    publicLayoutSet.isLayoutSetPrototypeLinkEnabled());
629    
630                            if ((privateLayoutSetPrototypeId == 0) &&
631                                    (publicLayoutSetPrototypeId == 0) &&
632                                    !privateLayoutSetPrototypeLinkEnabled &&
633                                    !publicLayoutSetPrototypeLinkEnabled) {
634    
635                                    long layoutSetPrototypeId = ParamUtil.getLong(
636                                            actionRequest, "layoutSetPrototypeId");
637                                    int layoutSetVisibility = ParamUtil.getInteger(
638                                            actionRequest, "layoutSetVisibility");
639                                    boolean layoutSetPrototypeLinkEnabled = ParamUtil.getBoolean(
640                                            actionRequest, "layoutSetPrototypeLinkEnabled",
641                                            (layoutSetPrototypeId > 0));
642    
643                                    if (layoutSetVisibility == _LAYOUT_SET_VISIBILITY_PRIVATE) {
644                                            privateLayoutSetPrototypeId = layoutSetPrototypeId;
645    
646                                            privateLayoutSetPrototypeLinkEnabled =
647                                                    layoutSetPrototypeLinkEnabled;
648                                    }
649                                    else {
650                                            publicLayoutSetPrototypeId = layoutSetPrototypeId;
651    
652                                            publicLayoutSetPrototypeLinkEnabled =
653                                                    layoutSetPrototypeLinkEnabled;
654                                    }
655                            }
656    
657                            SitesUtil.updateLayoutSetPrototypesLinks(
658                                    liveGroup, publicLayoutSetPrototypeId,
659                                    privateLayoutSetPrototypeId,
660                                    publicLayoutSetPrototypeLinkEnabled,
661                                    privateLayoutSetPrototypeLinkEnabled);
662                    }
663    
664                    // Staging
665    
666                    String redirect = ParamUtil.getString(actionRequest, "redirect");
667    
668                    long refererPlid = GetterUtil.getLong(
669                            HttpUtil.getParameter(redirect, "refererPlid", false));
670    
671                    if (!privateLayoutSet.isLayoutSetPrototypeLinkActive() &&
672                            !publicLayoutSet.isLayoutSetPrototypeLinkActive()) {
673    
674                            if ((refererPlid > 0) && liveGroup.hasStagingGroup() &&
675                                    (themeDisplay.getScopeGroupId() != liveGroup.getGroupId())) {
676    
677                                    Layout firstLayout = LayoutLocalServiceUtil.fetchFirstLayout(
678                                            liveGroup.getGroupId(), false,
679                                            LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
680    
681                                    if (firstLayout == null) {
682                                            firstLayout = LayoutLocalServiceUtil.fetchFirstLayout(
683                                                    liveGroup.getGroupId(), true,
684                                                    LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
685                                    }
686    
687                                    if (firstLayout != null) {
688                                            refererPlid = firstLayout.getPlid();
689                                    }
690                                    else {
691                                            refererPlid = 0;
692                                    }
693                            }
694    
695                            StagingUtil.updateStaging(actionRequest, liveGroup);
696                    }
697    
698                    return new Object[] {
699                            liveGroup, oldFriendlyURL, oldStagingFriendlyURL, refererPlid};
700            }
701    
702            private static final int _LAYOUT_SET_VISIBILITY_PRIVATE = 1;
703    
704    }