Skip to content

Commit

Permalink
Log SQL errors during context cache generation (#16508)
Browse files Browse the repository at this point in the history
### 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
  • Loading branch information
Mark-H authored Apr 10, 2024
1 parent 4965924 commit fe2df18
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions core/src/Revolution/mysql/modContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fe2df18

Please sign in to comment.