From fe2df183eabfebfd66c2c6f2788f2b93c40d4d1b Mon Sep 17 00:00:00 2001 From: Mark Hamstra Date: Wed, 10 Apr 2024 16:08:44 +0200 Subject: [PATCH] Log SQL errors during context cache generation (#16508) ### What does it do? Checks for errors loading resources in the generation of the context cache. ### Why is it needed? This is used in the aliasMap and resourceMap, but would fail silently if the query failed. In the specific case preceding this PR, the problem was a borked migration, but it took too much sleuthing to figure out where it was failing exactly due to this information not being available. ### How to test Make sure no message gets logged in normal use. ### Related issue(s)/PR(s) N/a --- core/src/Revolution/mysql/modContext.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/core/src/Revolution/mysql/modContext.php b/core/src/Revolution/mysql/modContext.php index 6c52522b185..e22ce3c17ea 100644 --- a/core/src/Revolution/mysql/modContext.php +++ b/core/src/Revolution/mysql/modContext.php @@ -196,8 +196,14 @@ public static function getResourceCacheMapStmt(&$context) } $criteria = new xPDOCriteria($context->xpdo, $sql, $bindings, false); - if ($criteria && $criteria->stmt && $criteria->stmt->execute()) { - $stmt =& $criteria->stmt; + if ($criteria && $criteria->stmt) { + if ($criteria->stmt->execute()) { + $stmt =& $criteria->stmt; + } + + if ($criteria->stmt->errorCode() !== '00000') { + $context->xpdo->log(modX::LOG_LEVEL_ERROR, '[modContext_mysql] Encountered error loading resources for cache map generation: ' . $criteria->stmt->errorCode() . ' // ' . print_r($criteria->stmt->errorInfo(), true)); + } } // output warning if query is too slow