From c637b45b0ab1e5a569b7085cec32e472e8776a7b Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 17 Mar 2023 15:36:01 -0700 Subject: [PATCH] AutoClean - Optionally allow explicit cleanup --- CRM/Utils/AutoClean.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/CRM/Utils/AutoClean.php b/CRM/Utils/AutoClean.php index b02c67479f..527862caf5 100644 --- a/CRM/Utils/AutoClean.php +++ b/CRM/Utils/AutoClean.php @@ -26,6 +26,13 @@ class CRM_Utils_AutoClean { protected $callback; protected $args; + /** + * Have we run this cleanup method yet? + * + * @var bool + */ + protected $isDone = FALSE; + /** * Call a cleanup function when the current context shuts down. * @@ -144,6 +151,21 @@ class CRM_Utils_AutoClean { } public function __destruct() { + $this->cleanup(); + } + + /** + * Explicitly apply the cleanup. + * + * Use this if you want to do the cleanup work immediately. + * + * @return void + */ + public function cleanup(): void { + if ($this->isDone) { + return; + } + $this->isDone = TRUE; \Civi\Core\Resolver::singleton()->call($this->callback, $this->args); } -- 2.25.1