From 62e7aa24fe16cc9378d6f13bcd6a0a02e3dcf005 Mon Sep 17 00:00:00 2001 From: Nicolas Malin Date: Thu, 24 Oct 2024 00:30:16 +0200 Subject: [PATCH] Fixed: example/control/ManagePortalPages?parentPortalPageId=EXAMPLE works but reports an error (OFBIZ-13150) Error due to call the method as copyIfRequiredSystemPage groovy event where the function has been move on private helper function for PortalPageServices. To fix, we restore it on PortalPageMethods and call it from PortalPageServices through script invoker (to escape code duplication). Thanks to Jacques Le Roux for the issue --- .../ofbiz/common/PortalPageMethods.groovy | 22 +++++++++++ .../ofbiz/common/PortalPageServices.groovy | 39 +++++++------------ .../webcommon/WEB-INF/portal-controller.xml | 2 +- 3 files changed, 38 insertions(+), 25 deletions(-) diff --git a/framework/common/src/main/groovy/org/apache/ofbiz/common/PortalPageMethods.groovy b/framework/common/src/main/groovy/org/apache/ofbiz/common/PortalPageMethods.groovy index 8a57d83f116..34d401b1fe1 100644 --- a/framework/common/src/main/groovy/org/apache/ofbiz/common/PortalPageMethods.groovy +++ b/framework/common/src/main/groovy/org/apache/ofbiz/common/PortalPageMethods.groovy @@ -63,3 +63,25 @@ String setPortalPortletAttributes() { } return success() } + +/** + * Check if the page is a system page, then copy before allowing + */ +String copyIfRequiredSystemPage() { + GenericValue portalPage = from('PortalPage').where(parameters).cache().queryOne() + ?: from('PortalPage').where(portalPageId: parameters.parentPortalPageId).cache().queryOne() + Map serviceResult = [:] + if (portalPage && portalPage.ownerUserLoginId == '_NA_' && from('PortalPage') + .where(originalPortalPageId: portalPage.portalPageId, + ownerUserLoginId: userLogin.userLoginId) + .queryCount() == 0 ) { + // copy the portal page + serviceResult = run service: 'createPortalPage', with: [*: portalPage.getAllFields(), + portalPageId: null, + originalPortalPageId: portalPage.portalPageId, + ownerUserLoginId: userLogin.userLoginId] + run service: 'duplicatePortalPageDetails', with: [fromPortalPageId: portalPage.portalPageId, + toPortalPageId: serviceResult.portalPageId] + } + return serviceResult ? serviceResult.portalPageId : portalPage?.portalPageId +} diff --git a/framework/common/src/main/groovy/org/apache/ofbiz/common/PortalPageServices.groovy b/framework/common/src/main/groovy/org/apache/ofbiz/common/PortalPageServices.groovy index 6026ee3b52a..972aa253bda 100644 --- a/framework/common/src/main/groovy/org/apache/ofbiz/common/PortalPageServices.groovy +++ b/framework/common/src/main/groovy/org/apache/ofbiz/common/PortalPageServices.groovy @@ -18,10 +18,12 @@ */ package org.apache.ofbiz.common +import org.apache.ofbiz.base.util.GroovyUtil import org.apache.ofbiz.entity.GenericValue import org.apache.ofbiz.entity.condition.EntityCondition import org.apache.ofbiz.entity.condition.EntityConditionBuilder import org.apache.ofbiz.service.ServiceUtil +import org.codehaus.groovy.runtime.InvokerHelper /** * Moves a PortalPortlet from the actual portalPage to a different one @@ -33,12 +35,16 @@ Map movePortletToPortalPage() { return checkIsOwner } GenericValue sourcePortalPagePortlet = from('PortalPagePortlet').where(parameters).cache().queryOne() - GenericValue targetPortalPortlet = makeValue('PortalPagePortlet', [*: parameters, - portalPageId: copyIfRequiredSystemPage(), - columnNum: 1]) - delegator.setNextSubSeqId(targetPortalPortlet, 'portletSeqId', 5, 1) - targetPortalPortlet.create() - sourcePortalPagePortlet.remove() + String idOfcopyIfRequiredSystemPage = copyIfRequiredSystemPage() + if (idOfcopyIfRequiredSystemPage) { + GenericValue targetPortalPortlet = makeValue('PortalPagePortlet', [*: parameters, + portalPageId: idOfcopyIfRequiredSystemPage, + columnNum: 1]) + delegator.setNextSubSeqId(targetPortalPortlet, 'portletSeqId', 5, 1) + targetPortalPortlet.create() + sourcePortalPagePortlet.remove() + } + return success(sourcePortalPagePortlet) } /** @@ -348,23 +354,8 @@ private Map checkOwnerShip() { return success() } -/** - * Check if the page is a system page, then copy before allowing - */ private String copyIfRequiredSystemPage() { - GenericValue portalPage = from('PortalPage').where(parameters).cache().queryOne() - Map serviceResult = [:] - if (portalPage && portalPage.ownerUserLoginId == '_NA_' && from('PortalPage') - .where(originalPortalPageId: parameters.portalPageId, - ownerUserLoginId: userLogin.userLoginId) - .queryCount() == 0 ) { - // copy the portal page - serviceResult = run service: 'createPortalPage', with: [*: portalPage.getAllFields(), - portalPageId: null, - originalPortalPageId: portalPage.portalPageId, - ownerUserLoginId: userLogin.userLoginId] - run service: 'duplicatePortalPageDetails', with: [fromPortalPageId: parameters.portalPageId, - toPortalPageId: serviceResult.portalPageId] - } - return serviceResult ? serviceResult.portalPageId : portalPage?.portalPageId + Script script = InvokerHelper.createScript( + GroovyUtil.getScriptClassFromLocation('component://common/src/main/groovy/org/apache/ofbiz/common/PortalPageMethods.groovy'), binding) + return script.invokeMethod('copyIfRequiredSystemPage', null) as String } diff --git a/framework/common/webcommon/WEB-INF/portal-controller.xml b/framework/common/webcommon/WEB-INF/portal-controller.xml index 6ccf3355016..142516ca52c 100644 --- a/framework/common/webcommon/WEB-INF/portal-controller.xml +++ b/framework/common/webcommon/WEB-INF/portal-controller.xml @@ -58,7 +58,7 @@ under the License. - +