feat: Implement automatic sermon archiving based on dates
Add intelligent auto-archiving system that automatically moves sermons to the "Previous Sermons" list when they are 1 day past their most recent date. Features: - Auto-archive logic that checks both primary and additional sermon dates - Finds the most recent date across all dates for a sermon - Archives sermon 1 day after the most recent date has passed - Manual trigger via "Run Auto-Archive Now" button on admin page - Automatic daily execution via scheduled cleanup task - Clear admin UI with explanatory text and status messages - Manual archive/unarchive functionality preserved Implementation: - Added getMostRecentSermonDate() helper to find latest date from primary and additional dates - Added autoArchiveOldSermons() function to database utils - Created /api/sermons/auto-archive endpoint for manual triggering - Integrated into daily cleanup plugin schedule - Updated admin UI with auto-archive button and status indicators - Added unarchiveSermon() function for completeness The system runs automatically every 24 hours and can be manually triggered by admins. Sermons are moved to the previous sermons dropdown on the home page exactly 1 day after their final presentation date, ensuring the main page always shows current and upcoming content while preserving access to past sermons. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { getSetting, deleteOldSermons, deleteExpiredSessions, getDatabase } from '../utils/database'
|
||||
import { getSetting, deleteOldSermons, deleteExpiredSessions, autoArchiveOldSermons, getDatabase } from '../utils/database'
|
||||
|
||||
// Map retention policy to days
|
||||
const retentionDaysMap: Record<string, number> = {
|
||||
@@ -12,6 +12,20 @@ const retentionDaysMap: Record<string, number> = {
|
||||
'10_years': 3650
|
||||
}
|
||||
|
||||
async function runSermonAutoArchive() {
|
||||
try {
|
||||
const result = autoArchiveOldSermons()
|
||||
|
||||
if (result.archivedCount > 0) {
|
||||
console.log(`[Sermon Auto-Archive] Archived ${result.archivedCount} sermon(s) that passed their most recent date`)
|
||||
} else {
|
||||
console.log(`[Sermon Auto-Archive] No sermons needed archiving`)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[Sermon Auto-Archive] Error running auto-archive:', error)
|
||||
}
|
||||
}
|
||||
|
||||
async function runSermonCleanup() {
|
||||
try {
|
||||
// Get the retention policy setting
|
||||
@@ -75,6 +89,7 @@ async function runPasswordResetCleanup() {
|
||||
|
||||
async function runAllCleanupTasks() {
|
||||
console.log('[Cleanup] Starting scheduled cleanup tasks')
|
||||
await runSermonAutoArchive()
|
||||
await runSermonCleanup()
|
||||
await runSessionCleanup()
|
||||
await runRateLimitCleanup()
|
||||
|
||||
Reference in New Issue
Block a user