From e97bcbad88a5b2b6b9a712d13bb66cfba8eb796c Mon Sep 17 00:00:00 2001 From: Mathieu Lutfy Date: Sat, 1 Jul 2023 23:25:32 -0400 Subject: [PATCH] clearTempTables: fix condition for user_job check, move check inside the loop --- CRM/Core/Config.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/CRM/Core/Config.php b/CRM/Core/Config.php index 2aa80a0cfe..771fce371e 100644 --- a/CRM/Core/Config.php +++ b/CRM/Core/Config.php @@ -377,10 +377,6 @@ class CRM_Core_Config extends CRM_Core_Config_MagicMerge { $tableDAO = CRM_Core_DAO::executeQuery($query); $tables = []; while ($tableDAO->fetch()) { - $tables[] = $tableDAO->tableName; - } - if (!empty($tables)) { - $table = implode(',', $tables); // If a User Job references the table do not drop it. This is a bit quick & dirty, but we don't want to // get into calling more sophisticated functions in a cache clear, and the table names are pretty unique // (ex: "civicrm_tmp_d_dflt_1234abcd5678efgh"), and the "metadata" may continue to evolve for the next @@ -388,11 +384,15 @@ class CRM_Core_Config extends CRM_Core_Config_MagicMerge { // TODO: Circa v5.60+, consider a more precise cleanup. Discussion: https://github.com/civicrm/civicrm-core/pull/24538 // A separate process will reap the UserJobs but here the goal is just not to delete them during cache clearing // if they are still referenced. - if (!CRM_Core_DAO::executeQuery("SELECT count(*) FROM civicrm_user_job WHERE metadata LIKE '%" . $tableDAO->tableName . "%'")) { - // drop leftover temporary tables - CRM_Core_DAO::executeQuery("DROP TABLE $table"); + if (!CRM_Core_DAO::singleValueQuery("SELECT count(*) FROM civicrm_user_job WHERE metadata LIKE '%" . $tableDAO->tableName . "%'")) { + $tables[] = $tableDAO->tableName; } } + if (!empty($tables)) { + $table = implode(',', $tables); + // drop leftover temporary tables + CRM_Core_DAO::executeQuery("DROP TABLE $table"); + } } /** -- 2.25.1