From 42324368e57f47f1138e372bc442bc6acdfc8d58 Mon Sep 17 00:00:00 2001
From: Tiago Salvado <9038083+tiagosalvado10@users.noreply.github.com>
Date: Thu, 28 Aug 2025 10:13:31 +0100
Subject: [PATCH] [MNT-25242] Add property to control if scope is cleaned
(#3520)
---
.../repo/jscript/RhinoScriptProcessor.java | 16 ++++++++++++++--
.../resources/alfresco/repository.properties | 3 +++
.../alfresco/script-services-context.xml | 3 +++
3 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/repository/src/main/java/org/alfresco/repo/jscript/RhinoScriptProcessor.java b/repository/src/main/java/org/alfresco/repo/jscript/RhinoScriptProcessor.java
index 714e86ae1e..00d29569ff 100644
--- a/repository/src/main/java/org/alfresco/repo/jscript/RhinoScriptProcessor.java
+++ b/repository/src/main/java/org/alfresco/repo/jscript/RhinoScriptProcessor.java
@@ -2,7 +2,7 @@
* #%L
* Alfresco Repository
* %%
- * Copyright (C) 2005 - 2016 Alfresco Software Limited
+ * Copyright (C) 2005 - 2025 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
@@ -124,6 +124,9 @@ public class RhinoScriptProcessor extends BaseProcessor implements ScriptProcess
/** Number of (bytecode) instructions that will trigger the observer */
private int observerInstructionCount = 100;
+ /** Flag to enable or disable scope cleaning at the end of each script execution */
+ private boolean cleanScope = true;
+
/** Custom context factory */
public static AlfrescoContextFactory contextFactory;
@@ -210,6 +213,15 @@ public class RhinoScriptProcessor extends BaseProcessor implements ScriptProcess
this.observerInstructionCount = observerInstructionCount;
}
+ /**
+ * @param cleanScope
+ * true to enable scope cleaning at the end of each script execution - set to false to disable this feature.
+ */
+ public void setCleanScope(boolean cleanScope)
+ {
+ this.cleanScope = cleanScope;
+ }
+
/**
* @see org.alfresco.service.cmr.repository.ScriptProcessor#reset()
*/
@@ -619,7 +631,7 @@ public class RhinoScriptProcessor extends BaseProcessor implements ScriptProcess
}
finally
{
- if (!secure)
+ if (!secure && cleanScope)
{
unsetScope(model, scope);
}
diff --git a/repository/src/main/resources/alfresco/repository.properties b/repository/src/main/resources/alfresco/repository.properties
index 016ac28b36..e9b55c5c3a 100644
--- a/repository/src/main/resources/alfresco/repository.properties
+++ b/repository/src/main/resources/alfresco/repository.properties
@@ -1394,6 +1394,9 @@ scripts.execution.maxMemoryUsedInBytes=-1
# Number of instructions that will trigger the observer
scripts.execution.observerInstructionCount=5000
+# Flag to control if the scope is cleaned at the end of script execution
+scripts.execution.clean.scope=true
+
# Default value being used in POST/size-details endpoint to partition a huge folder into smaller chunks
# so that we can compute more efficiently and consolidate all sizes into a single unit.
default.async.folder.items=1000
diff --git a/repository/src/main/resources/alfresco/script-services-context.xml b/repository/src/main/resources/alfresco/script-services-context.xml
index cbff40693a..460d8890ff 100644
--- a/repository/src/main/resources/alfresco/script-services-context.xml
+++ b/repository/src/main/resources/alfresco/script-services-context.xml
@@ -60,6 +60,9 @@
${scripts.execution.observerInstructionCount}
+
+ ${scripts.execution.clean.scope}
+