Blog Sections Open
Sanitizing Stored TV IDs Before getDocuments Queries in Evolution CMS
A defensive API fix for avoiding SQL errors when malformed TV values are passed into getDocuments.
Some of the most painful Evolution CMS bugs came from small data-shape problems hiding in old TVs. This case involved a TV that used to store comma-separated resource IDs as text, later changed to a listbox, and one stale value like 22, was enough to break output through getDocuments().
The underlying problem
A malformed ID list was being passed from a TV into template logic and eventually into the API. Because getDocuments() did not guard against dirty values in the incoming array, the bad record triggered an SQL error. Worse, the broken document was buried somewhere inside a large content set.
The fix
The historical patch was simple and sensible: normalize the incoming IDs first, cast them to integers, and discard anything that does not become a valid non-zero identifier before building the query.
foreach ($ids as $id) {
if (intval($id) != 0) $newIds[] = intval($id);
}
$ids = $newIds;Why this matters
This is a classic Evo engineering lesson: a tiny defensive check in a low-level API boundary can save hours of debugging later. It also documents a very real migration hazard when TVs change type but old stored values do not fully match the new format.
Related posts
Understanding Checkbox TV Value Formats in Evolution CMS
Updating TV Values for a Specific Resource Through the Evolution API
Caching Dynamic Snippets in Evolution CMS Without Losing Dynamic Output
A historical best-practices article about isolating dynamic regions while keeping page caching effective.
Measuring CacheAccelerator Gains on News Pages with Heavy Ditto and Jot Usage
A historical performance note about where page-level caching helps and where Jot-heavy pages still need structural optimization.