mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-11-30 12:14:36 -05:00
Merge pull request #6929 from AJ0070/fix-events-search-order-ties
fix: events list search results order ties by Id so pages don't repeat or skip events
This commit is contained in:
2 files changed
+34
-2
No files matched your search
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
// The Events list pages the search / advanced search results in PHP (array_slice) after
|
||||
// fetching them sorted by the chosen column only. Events with the same value in that column
|
||||
// (same Length, Frames, Cause...) can come back in a different order on each page request,
|
||||
// so they repeat on one page and are missing from another. The paged-in-SQL path already
|
||||
// orders ties by E.Id; the search path now does too.
|
||||
//
|
||||
// Run as: php tests/php/test_events_search_order_ties.php [root] (root defaults to the repo)
|
||||
|
||||
$root = isset($argv[1]) ? $argv[1] : __DIR__.'/../..';
|
||||
$source = file_get_contents($root.'/web/ajax/events.php');
|
||||
|
||||
$failures = 0;
|
||||
function check($n, $got, $want) {
|
||||
global $failures;
|
||||
if ($got === $want) echo "ok - $n\n";
|
||||
else { $failures++; echo "FAIL - $n (got ".var_export($got, true).", want ".var_export($want, true).")\n"; }
|
||||
}
|
||||
|
||||
// Every SELECT that builds the list of events groups by E.Id and must end its ORDER BY
|
||||
// with E.Id. Collect the PHP expression that follows each "GROUP BY E.Id" up to its ';'.
|
||||
preg_match_all('/GROUP BY E\.Id[^;]*;/s', $source, $m);
|
||||
check('found the event list queries', count($m[0]) >= 3, true);
|
||||
foreach ($m[0] as $i => $stmt) {
|
||||
$has_order = (strpos($stmt, 'ORDER BY') !== false);
|
||||
if (!$has_order) continue;
|
||||
check("query ".($i + 1)." orders ties by E.Id", (bool)preg_match("/'E\\.Id'\s*;\s*$/", $stmt) || (bool)preg_match('/\$order_by/', $stmt), true);
|
||||
check("query ".($i + 1)." has no ORDER BY without the tiebreak", (bool)preg_match("/\?\s*' ORDER BY '\s*\.\s*\\\$sort\s*:\s*''/", $stmt), false);
|
||||
}
|
||||
|
||||
echo $failures ? "\n$failures failed\n" : "\nall passed\n";
|
||||
exit($failures ? 1 : 0);
|
||||
+2
-2
@@ -346,7 +346,7 @@ function queryRequest($filter, $search, $advsearch, $sort, $offset, $order, $lim
|
||||
LEFT JOIN Tags AS T ON T.Id = ET.TagId
|
||||
'.$where.'
|
||||
GROUP BY E.Id, Monitor
|
||||
'.($sort?' ORDER BY '.$sort:'');
|
||||
'.' ORDER BY '.($sort ? $sort.', ' : '').'E.Id';
|
||||
|
||||
if ((int)($filter->limit()) and !$has_post_sql_conditions) {
|
||||
$sql .= ' LIMIT '.(int)($filter->limit());
|
||||
@@ -418,7 +418,7 @@ function queryRequest($filter, $search, $advsearch, $sort, $offset, $order, $lim
|
||||
LEFT JOIN Tags AS T ON T.Id = ET.TagId
|
||||
WHERE M.Deleted = false AND ('.$search_filter->sql().')
|
||||
GROUP BY E.Id'
|
||||
.($sort ? ' ORDER BY '.$sort : '');
|
||||
.' ORDER BY '.($sort ? $sort.', ' : '').'E.Id';
|
||||
|
||||
$filtered_rows = dbFetchAll($sql);
|
||||
ZM\Debug('Have ' . count($filtered_rows) . ' events matching search filter: '.$sql);
|
||||
|
||||
Reference in new issue
Block a user