From 951f32a3dc44e87a2d082938835b0f1bdc3c7ffd Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Fri, 19 Nov 2021 13:08:16 +0100 Subject: [PATCH] IDEMPIERE-5045 Applying packins is leaving open records in AD_Session (Processed=N) (#986) --- .../org/adempiere/plugin/utils/AdempiereActivator.java | 9 ++++++++- .../plugin/utils/Incremental2PackActivator.java | 9 ++++++++- .../plugin/utils/PackInApplicationActivator.java | 10 ++++++++-- .../adempiere/plugin/utils/Version2PackActivator.java | 9 ++++++++- 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/AdempiereActivator.java b/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/AdempiereActivator.java index 2f3a639f55..e0bb67f63d 100644 --- a/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/AdempiereActivator.java +++ b/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/AdempiereActivator.java @@ -95,8 +95,13 @@ public class AdempiereActivator extends AbstractActivator { protected void packIn() { URL packout = context.getBundle().getEntry("/META-INF/2Pack.zip"); if (packout != null && service != null) { + MSession localSession = null; //Create Session to be able to create records in AD_ChangeLog - MSession.get(Env.getCtx(), true); + if (Env.getContextAsInt(Env.getCtx(), Env.AD_SESSION_ID) <= 0) { + localSession = MSession.get(Env.getCtx(), true); + localSession.setWebSession("AdempiereActivator"); + localSession.saveEx(); + } FileOutputStream zipstream = null; try { // copy the resource to a temporary file to process it with 2pack @@ -119,6 +124,8 @@ public class AdempiereActivator extends AbstractActivator { zipstream.close(); } catch (Exception e2) {} } + if (localSession != null) + localSession.logout(); } } } diff --git a/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/Incremental2PackActivator.java b/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/Incremental2PackActivator.java index b42f15c606..9d0afc6e03 100644 --- a/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/Incremental2PackActivator.java +++ b/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/Incremental2PackActivator.java @@ -209,8 +209,13 @@ public class Incremental2PackActivator extends AbstractActivator { protected boolean packIn(URL packout) { if (packout != null && service != null) { + MSession localSession = null; //Create Session to be able to create records in AD_ChangeLog - MSession.get(Env.getCtx(), true); + if (Env.getContextAsInt(Env.getCtx(), Env.AD_SESSION_ID) <= 0) { + localSession = MSession.get(Env.getCtx(), true); + localSession.setWebSession("Incremental2PackActivator"); + localSession.saveEx(); + } String path = packout.getPath(); String suffix = "_"+path.substring(path.lastIndexOf("2Pack_")); logger.log(Level.WARNING, "Installing " + getName() + " " + path + " ..."); @@ -237,6 +242,8 @@ public class Incremental2PackActivator extends AbstractActivator { zipstream.close(); } catch (Exception e2) {} } + if (localSession != null) + localSession.logout(); } logger.log(Level.WARNING, getName() + " " + packout.getPath() + " installed"); } diff --git a/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/PackInApplicationActivator.java b/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/PackInApplicationActivator.java index 1baa1189d7..09d75d65f1 100644 --- a/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/PackInApplicationActivator.java +++ b/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/PackInApplicationActivator.java @@ -96,11 +96,15 @@ public class PackInApplicationActivator extends AbstractActivator{ return; } + MSession localSession = null; try { if (getDBLock()) { //Create Session to be able to create records in AD_ChangeLog - if (Env.getContextAsInt(Env.getCtx(), Env.AD_SESSION_ID) <= 0) - MSession.get(Env.getCtx(), true); + if (Env.getContextAsInt(Env.getCtx(), Env.AD_SESSION_ID) <= 0) { + localSession = MSession.get(Env.getCtx(), true); + localSession.setWebSession("PackInApplicationActivator"); + localSession.saveEx(); + } for(File zipFile : fileArray) { currentFile = zipFile; if (!packIn(zipFile)) { @@ -125,6 +129,8 @@ public class PackInApplicationActivator extends AbstractActivator{ addLog(Level.WARNING, e.getLocalizedMessage()); } finally { releaseLock(); + if (localSession != null) + localSession.logout(); } if (filesToProcess.size() > 0) { diff --git a/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/Version2PackActivator.java b/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/Version2PackActivator.java index f0f3290e54..9de8767664 100644 --- a/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/Version2PackActivator.java +++ b/org.adempiere.plugin.utils/src/org/adempiere/plugin/utils/Version2PackActivator.java @@ -146,10 +146,15 @@ public class Version2PackActivator extends AbstractActivator{ } }); + MSession localSession = null; try { if (getDBLock()) { //Create Session to be able to create records in AD_ChangeLog - MSession.get(Env.getCtx(), true); + if (Env.getContextAsInt(Env.getCtx(), Env.AD_SESSION_ID) <= 0) { + localSession = MSession.get(Env.getCtx(), true); + localSession.setWebSession("Version2PackActivator"); + localSession.saveEx(); + } for(TwoPackEntry entry : list) { if (!packIn(entry.url)) { // stop processing further packages if one fail @@ -163,6 +168,8 @@ public class Version2PackActivator extends AbstractActivator{ e.printStackTrace(); } finally { releaseLock(); + if (localSession != null) + localSession.logout(); } }