From e4b7c9e17d57482d97aac41b54346a81bd32d82b Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Mon, 13 Mar 2023 14:38:00 +0100 Subject: [PATCH] IDEMPIERE-5628 Record ID Check Issue - implement setCrossTenantSafe (#1724) * IDEMPIERE-5628 Record ID Check Issue - implement setCrossTenantSafe * - remove table exceptions --- .../src/org/compiere/model/MRecentItem.java | 14 ++++++++++++-- .../src/org/compiere/model/MSession.java | 5 +++++ .../org/compiere/model/MShippingTransaction.java | 10 +++++++--- org.adempiere.base/src/org/compiere/model/PO.java | 4 +--- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/model/MRecentItem.java b/org.adempiere.base/src/org/compiere/model/MRecentItem.java index 4c430bc9ad..cc84cdbd43 100644 --- a/org.adempiere.base/src/org/compiere/model/MRecentItem.java +++ b/org.adempiere.base/src/org/compiere/model/MRecentItem.java @@ -228,7 +228,12 @@ public class MRecentItem extends X_AD_RecentItem implements ImmutablePOSupport ri.setAD_Role_ID(AD_Role_ID); ri.setAD_Window_ID(AD_Window_ID); ri.setAD_Tab_ID(AD_Tab_ID); - ri.saveEx(); + try { + PO.setCrossTenantSafe(); + ri.saveEx(); + } finally { + PO.clearCrossTenantSafe(); + } } else { if ( ric.getAD_Role_ID() != AD_Role_ID || ric.getAD_Window_ID() != AD_Window_ID @@ -237,7 +242,12 @@ public class MRecentItem extends X_AD_RecentItem implements ImmutablePOSupport ri.setAD_Role_ID(AD_Role_ID); ri.setAD_Window_ID(AD_Window_ID); ri.setAD_Tab_ID(AD_Tab_ID); - ri.saveEx(); + try { + PO.setCrossTenantSafe(); + ri.saveEx(); + } finally { + PO.clearCrossTenantSafe(); + } } else { DB.executeUpdateEx("UPDATE AD_RecentItem SET Updated=getDate() WHERE AD_RecentItem_ID=?", new Object[] {ric.getAD_RecentItem_ID()}, null); } diff --git a/org.adempiere.base/src/org/compiere/model/MSession.java b/org.adempiere.base/src/org/compiere/model/MSession.java index 8e4e060636..21db4ec7ed 100644 --- a/org.adempiere.base/src/org/compiere/model/MSession.java +++ b/org.adempiere.base/src/org/compiere/model/MSession.java @@ -351,6 +351,7 @@ public class MSession extends X_AD_Session implements ImmutablePOSupport + ": " + OldValue + " -> " + NewValue); try { + PO.setCrossTenantSafe(); MChangeLog cl = new MChangeLog(getCtx(), AD_ChangeLog_ID, TrxName, getAD_Session_ID(), AD_Table_ID, AD_Column_ID, Record_ID, AD_Client_ID, AD_Org_ID, @@ -365,6 +366,10 @@ public class MSession extends X_AD_Session implements ImmutablePOSupport + ", AD_Table_ID=" + AD_Table_ID + ", AD_Column_ID=" + AD_Column_ID, e); return null; } + finally + { + PO.clearCrossTenantSafe(); + } log.log(Level.SEVERE, "AD_ChangeLog_ID=" + AD_ChangeLog_ID + ", AD_Session_ID=" + getAD_Session_ID() + ", AD_Table_ID=" + AD_Table_ID + ", AD_Column_ID=" + AD_Column_ID); diff --git a/org.adempiere.base/src/org/compiere/model/MShippingTransaction.java b/org.adempiere.base/src/org/compiere/model/MShippingTransaction.java index 4e94c37b79..67302038fc 100644 --- a/org.adempiere.base/src/org/compiere/model/MShippingTransaction.java +++ b/org.adempiere.base/src/org/compiere/model/MShippingTransaction.java @@ -107,9 +107,13 @@ public class MShippingTransaction extends X_M_ShippingTransaction msg.append(getErrorMessage()); msg.append("\nAction: " + getAction()); history.setTextMsg(msg.toString()); - - history.saveEx(); - + try { + PO.setCrossTenantSafe(); + history.saveEx(); + } finally { + PO.clearCrossTenantSafe(); + } + setProcessed(processed); return processed; } diff --git a/org.adempiere.base/src/org/compiere/model/PO.java b/org.adempiere.base/src/org/compiere/model/PO.java index 85886a4539..bc54b23170 100644 --- a/org.adempiere.base/src/org/compiere/model/PO.java +++ b/org.adempiere.base/src/org/compiere/model/PO.java @@ -5520,9 +5520,7 @@ public abstract class PO * @return true if all the foreign keys are valid */ private void checkRecordIDCrossTenant() { - // exclude read-only high-traffic tables - if ( MChangeLog.Table_Name.equals(get_TableName()) - || MRecentItem.Table_Name.equals(get_TableName())) + if (isSafeCrossTenant.get()) return; int idxRecordId = p_info.getColumnIndex("Record_ID"); if (idxRecordId < 0)