- Added Upkeeping → Correct catalogue order.

It now recalculates video sort_order from created_at newest-first, so 
videos with corrected/original publish dates appear first in the 
homepage and public catalogue. I also updated 
catalogue/admin/latest-video ordering to use publish date as a 
tie-breaker after stored sort order.
This commit is contained in:
Ty Clifford
2026-06-25 11:58:57 -04:00
parent 7375613e63
commit 8a39bc02fa
5 changed files with 66 additions and 5 deletions
+23 -1
View File
@@ -59,6 +59,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if ($result['not_found']) $msg .= ', ' . $result['not_found'] . ' without a readable external count';
$msg .= '.';
}
if ($action === 'correct_catalogue_order') {
$result = media_correct_catalogue_sort_order();
$msg = 'Upkeeping checked ' . $result['checked'] . ' video' . ($result['checked'] === 1 ? '' : 's') . ': ';
$msg .= $result['updated'] . ' video' . ($result['updated'] === 1 ? '' : 's') . ' reordered newest-first by publish date.';
}
}
// Search + pagination
@@ -85,7 +91,7 @@ $list_stmt = $db->prepare("
LEFT JOIN video_sources vs ON vs.video_id = v.id
$where_sql
GROUP BY v.id
ORDER BY v.sort_order ASC, v.id DESC
ORDER BY v.sort_order ASC, datetime(v.created_at) DESC, v.created_at DESC, v.id DESC
LIMIT :limit OFFSET :offset
");
foreach ($bind as $k => $val) $list_stmt->bindValue($k, $val);
@@ -95,6 +101,7 @@ $list_stmt->execute();
$videos = $list_stmt->fetchAll();
$youtube_timestamp_candidates = media_youtube_timestamp_candidate_count();
$external_view_candidates = media_external_view_count_candidate_count();
$catalogue_order_candidates = media_catalogue_order_candidate_count();
$admin_total_views = total_video_views(false);
$qs = fn($p) => '?' . http_build_query(array_filter(['q' => $search, 'page' => $p]));
@@ -236,6 +243,21 @@ render_head('Admin — TyClifford.com', '
</button>
</form>
</div>
<div class="upkeep-row">
<div class="upkeep-copy">
<h2 class="card-title">Correct catalogue order</h2>
<p class="hint">
Rebuilds video sort order from the database publish dates so newer dated videos appear first in the homepage and public catalogue.
<?= $catalogue_order_candidates ?> video<?= $catalogue_order_candidates === 1 ? '' : 's' ?> can be reordered.
</p>
</div>
<form class="upkeep-form" method="post" action="index.php">
<input type="hidden" name="action" value="correct_catalogue_order">
<button class="btn btn-secondary btn-sm" type="submit">
Correct Order
</button>
</form>
</div>
<div class="upkeep-row">
<div class="upkeep-copy">
<h2 class="card-title">Correct external view counts</h2>