Merge pull request #5958 from AJ0070/console-sort-paged-pub

fix: keep console drag-sort order relative to other pages
This commit is contained in:
Isaac Connor authored and GitHub committed 2026-11-14 18:50:23 -05:00
commit 67de7dff30
2 files changed
+37 -1

No files matched your search

+24
View File
@@ -41,6 +41,14 @@ namespace {
$updates = array();
function zmDbConn() { global $conn; return $conn; }
$failNext = false;
$sequenceOf = array();
function dbFetchAll($sql, $col = null, $params = array()) {
global $sequenceOf;
$seqs = array();
foreach ($params as $id) if (isset($sequenceOf[$id])) $seqs[] = $sequenceOf[$id];
sort($seqs);
return $seqs;
}
function dbQuery($sql, $params = null) {
global $updates, $failNext;
if ($failNext) throw new \RuntimeException('update failed');
@@ -56,13 +64,28 @@ namespace {
eval($m[0]);
echo "ordered ids\n";
$sequenceOf = array('2' => 0, '3' => 1, '4' => 2);
saveMonitorSequence(array('4', 'monitor_id-3', '2'));
check('sequence follows position', $updates, array(array(0, '4'), array(1, '3'), array(2, '2')));
check('table locked then unlocked', $conn->log, array('LOCK TABLES Monitors WRITE', 'UNLOCK TABLES'));
echo "\nsecond page keeps its own slots\n";
$updates = array();
$conn->log = array();
$sequenceOf = array('11' => 10, '12' => 11, '13' => 12);
saveMonitorSequence(array('13', '11', '12'));
check('reordered within the page slots', $updates, array(array(10, '13'), array(11, '11'), array(12, '12')));
echo "\nduplicate sequences fall back to a run\n";
$updates = array();
$sequenceOf = array('5' => 3, '6' => 3);
saveMonitorSequence(array('6', '5'));
check('consecutive from the lowest', $updates, array(array(3, '6'), array(4, '5')));
echo "\nbad ids are skipped\n";
$updates = array();
$conn->log = array();
$sequenceOf = array('7' => 2);
saveMonitorSequence(array('', 'x', '7'));
check('only the valid id is written', $updates, array(array(2, '7')));
check('still unlocked', end($conn->log), 'UNLOCK TABLES');
@@ -70,6 +93,7 @@ namespace {
echo "\nunlocks when a write throws\n";
$conn->log = array();
$failNext = true;
$sequenceOf = array('1' => 0);
try {
saveMonitorSequence(array('1'));
} catch (\RuntimeException $e) {
+13 -1
View File
@@ -45,6 +45,7 @@ function saveMonitorSequence($monitor_ids) {
$dbConn = zmDbConn();
$dbConn->exec('LOCK TABLES Monitors WRITE');
try {
$ids = array();
for ( $i = 0; $i < count($monitor_ids); $i += 1 ) {
$monitor_id = $monitor_ids[$i];
$monitor_id = preg_replace('/^monitor_id-/', '', $monitor_id);
@@ -52,8 +53,19 @@ function saveMonitorSequence($monitor_ids) {
\ZM\Warning('Got '.$monitor_id.' from '.$monitor_ids[$i]);
continue;
}
dbQuery('UPDATE Monitors SET Sequence=? WHERE Id=?', array($i, $monitor_id));
$ids[] = $monitor_id;
} // end for each monitor_id
if ( $ids ) {
// A paginated table only posts the visible rows, so reuse the Sequence values those rows already held
$sequences = dbFetchAll('SELECT Sequence FROM Monitors WHERE Id IN ('.implode(',', array_fill(0, count($ids), '?')).') ORDER BY Sequence', 'Sequence', $ids);
if ( count(array_unique($sequences)) != count($ids) ) {
$first = $sequences ? $sequences[0] : 0;
$sequences = range($first, $first + count($ids) - 1);
}
foreach ( $ids as $i => $monitor_id ) {
dbQuery('UPDATE Monitors SET Sequence=? WHERE Id=?', array($sequences[$i], $monitor_id));
}
}
} finally {
$dbConn->exec('UNLOCK TABLES');
}