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:
@@ -378,18 +378,42 @@
|
||||
{{ retentionPolicySuccess }}
|
||||
</div>
|
||||
|
||||
<div class="border-t pt-4 mt-4">
|
||||
<button
|
||||
@click="handleManualCleanup"
|
||||
:disabled="cleaningUp"
|
||||
class="px-6 py-2 bg-orange-600 text-white rounded-md hover:bg-orange-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-orange-500 disabled:opacity-50 disabled:cursor-not-allowed font-medium"
|
||||
>
|
||||
{{ cleaningUp ? 'Running Cleanup...' : 'Run Cleanup Now' }}
|
||||
</button>
|
||||
<p class="text-xs text-gray-500 mt-2">
|
||||
Manually trigger the cleanup process to delete sermons according to the retention policy.
|
||||
This will also run automatically on a daily schedule.
|
||||
</p>
|
||||
<div class="border-t pt-4 mt-4 space-y-4">
|
||||
<div>
|
||||
<button
|
||||
@click="handleAutoArchive"
|
||||
:disabled="autoArchiving"
|
||||
class="px-6 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 disabled:opacity-50 disabled:cursor-not-allowed font-medium"
|
||||
>
|
||||
{{ autoArchiving ? 'Auto-Archiving...' : 'Run Auto-Archive Now' }}
|
||||
</button>
|
||||
<p class="text-xs text-gray-500 mt-2">
|
||||
Automatically archive sermons that are 1 day past their most recent date.
|
||||
This moves them to the "Previous Sermons" list on the home page.
|
||||
This also runs automatically on a daily schedule.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<button
|
||||
@click="handleManualCleanup"
|
||||
:disabled="cleaningUp"
|
||||
class="px-6 py-2 bg-orange-600 text-white rounded-md hover:bg-orange-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-orange-500 disabled:opacity-50 disabled:cursor-not-allowed font-medium"
|
||||
>
|
||||
{{ cleaningUp ? 'Running Cleanup...' : 'Run Cleanup Now' }}
|
||||
</button>
|
||||
<p class="text-xs text-gray-500 mt-2">
|
||||
Manually trigger the cleanup process to delete sermons according to the retention policy.
|
||||
This will also run automatically on a daily schedule.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="autoArchiveError" class="text-red-600 text-sm">
|
||||
{{ autoArchiveError }}
|
||||
</div>
|
||||
<div v-if="autoArchiveSuccess" class="text-green-600 text-sm">
|
||||
{{ autoArchiveSuccess }}
|
||||
</div>
|
||||
|
||||
<div v-if="cleanupError" class="text-red-600 text-sm">
|
||||
@@ -450,6 +474,9 @@ const retentionPolicy = ref('forever')
|
||||
const savingRetentionPolicy = ref(false)
|
||||
const retentionPolicyError = ref('')
|
||||
const retentionPolicySuccess = ref('')
|
||||
const autoArchiving = ref(false)
|
||||
const autoArchiveError = ref('')
|
||||
const autoArchiveSuccess = ref('')
|
||||
const cleaningUp = ref(false)
|
||||
const cleanupError = ref('')
|
||||
const cleanupSuccess = ref('')
|
||||
@@ -756,6 +783,27 @@ async function handleRetentionPolicyChange() {
|
||||
}
|
||||
}
|
||||
|
||||
async function handleAutoArchive() {
|
||||
autoArchiveError.value = ''
|
||||
autoArchiveSuccess.value = ''
|
||||
autoArchiving.value = true
|
||||
|
||||
try {
|
||||
const result = await $fetch('/api/sermons/auto-archive', {
|
||||
method: 'POST'
|
||||
})
|
||||
|
||||
autoArchiveSuccess.value = result.message
|
||||
|
||||
// Refresh sermon list after auto-archive
|
||||
await refreshSermons()
|
||||
} catch (e: any) {
|
||||
autoArchiveError.value = e.data?.message || 'Failed to run auto-archive'
|
||||
} finally {
|
||||
autoArchiving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function handleManualCleanup() {
|
||||
if (!confirm('Are you sure you want to run the cleanup process?\n\nThis will permanently delete all sermons older than the retention policy. This action cannot be undone.')) {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user