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