Skip to content

Commit

Permalink
LPS-128221 prevent the case when layout group does not exist anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosapmf authored and brianchandotcom committed Feb 23, 2021
1 parent 06f15d0 commit 296e135
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.liferay.layout.internal.upgrade.v1_0_0.UpgradeLayoutPermissions;
import com.liferay.layout.internal.upgrade.v1_1_0.UpgradeCompanyId;
import com.liferay.layout.internal.upgrade.v1_2_1.UpgradeLayoutAsset;
import com.liferay.portal.kernel.service.GroupLocalService;
import com.liferay.portal.kernel.service.LayoutLocalService;
import com.liferay.portal.kernel.upgrade.UpgradeCTModel;
import com.liferay.portal.upgrade.registry.UpgradeStepRegistrator;
Expand Down Expand Up @@ -55,7 +56,8 @@ public void register(Registry registry) {
"1.2.0", "1.2.1",
new UpgradeLayoutAsset(
_assetCategoryLocalService, _assetEntryLocalService,
_assetTagLocalService, _layoutLocalService));
_assetTagLocalService, _groupLocalService,
_layoutLocalService));
}

@Reference
Expand All @@ -70,6 +72,9 @@ public void register(Registry registry) {
@Reference
private AssetTagLocalService _assetTagLocalService;

@Reference
private GroupLocalService _groupLocalService;

@Reference
private LayoutLocalService _layoutLocalService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
import com.liferay.portal.kernel.dao.orm.Property;
import com.liferay.portal.kernel.dao.orm.PropertyFactoryUtil;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.model.Group;
import com.liferay.portal.kernel.model.Layout;
import com.liferay.portal.kernel.model.LayoutConstants;
import com.liferay.portal.kernel.service.GroupLocalService;
import com.liferay.portal.kernel.service.LayoutLocalService;
import com.liferay.portal.kernel.upgrade.UpgradeProcess;

Expand All @@ -36,11 +38,13 @@ public UpgradeLayoutAsset(
AssetCategoryLocalService assetCategoryLocalService,
AssetEntryLocalService assetEntryLocalService,
AssetTagLocalService assetTagLocalService,
GroupLocalService groupLocalService,
LayoutLocalService layoutLocalService) {

_assetCategoryLocalService = assetCategoryLocalService;
_assetEntryLocalService = assetEntryLocalService;
_assetTagLocalService = assetTagLocalService;
_groupLocalService = groupLocalService;
_layoutLocalService = layoutLocalService;
}

Expand Down Expand Up @@ -73,6 +77,12 @@ private void _updateAsset(Layout layout) throws PortalException {
return;
}

Group group = _groupLocalService.fetchGroup(layout.getGroupId());

if (group == null) {
return;
}

long[] assetCategoryIds = _assetCategoryLocalService.getCategoryIds(
Layout.class.getName(), layout.getPlid());
String[] assetTagNames = _assetTagLocalService.getTagNames(
Expand All @@ -85,6 +95,7 @@ private void _updateAsset(Layout layout) throws PortalException {
private final AssetCategoryLocalService _assetCategoryLocalService;
private final AssetEntryLocalService _assetEntryLocalService;
private final AssetTagLocalService _assetTagLocalService;
private final GroupLocalService _groupLocalService;
private final LayoutLocalService _layoutLocalService;

}

0 comments on commit 296e135

Please sign in to comment.