mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 16:19:19 +02:00
Add periodic cleanup of orphaned drafts: cleanup job, just command, deploy cron
This commit is contained in:
32
justfile
32
justfile
@@ -319,6 +319,27 @@ deploy-list-backups:
|
||||
# List all existing backups on the server (most recent last).
|
||||
ssh xamxam "ls -lth /var/backups/xamxam/ 2>/dev/null || echo 'No backups yet.'"
|
||||
|
||||
[group('deploy')]
|
||||
deploy-cleanup-cron:
|
||||
# Install cron job for orphaned draft cleanup (every 4 hours, 24h threshold).
|
||||
# Creates /etc/cron.d/xamxam-cleanup and log file on the server.
|
||||
@echo "📋 Installing draft cleanup cron job…"
|
||||
rsync -v scripts/cleanup-drafts.php xamxam:/var/www/xamxam/scripts/cleanup-drafts.php
|
||||
ssh xamxam "chown www-data:xamxam /var/www/xamxam/scripts/cleanup-drafts.php && chmod 755 /var/www/xamxam/scripts/cleanup-drafts.php"
|
||||
rsync -v deploy/xamxam-cleanup.cron xamxam:/tmp/xamxam-cleanup.cron
|
||||
ssh -t xamxam "sudo install -o root -g root -m 644 /tmp/xamxam-cleanup.cron /etc/cron.d/xamxam-cleanup && rm -f /tmp/xamxam-cleanup.cron"
|
||||
ssh -t xamxam "sudo touch /var/log/xamxam-cleanup.log && sudo chown www-data:www-data /var/log/xamxam-cleanup.log && sudo chmod 644 /var/log/xamxam-cleanup.log"
|
||||
@echo "✅ Cleanup cron installed."
|
||||
@echo " Cron file: /etc/cron.d/xamxam-cleanup"
|
||||
@echo " Script: /var/www/xamxam/scripts/cleanup-drafts.php"
|
||||
@echo " Log file: /var/log/xamxam-cleanup.log"
|
||||
@echo ""
|
||||
@echo "Verify with: just deploy-check-cleanup-log"
|
||||
|
||||
[group('deploy')]
|
||||
deploy-check-cleanup-log:
|
||||
ssh xamxam "tail -20 /var/log/xamxam-cleanup.log 2>/dev/null || echo '(log file empty or missing — will be created on first cron run)'"
|
||||
|
||||
[group('deploy')]
|
||||
test-restore remote_gz_path:
|
||||
# Test-restore a production backup snapshot to a local temp DB and verify.
|
||||
@@ -351,8 +372,8 @@ deploy-migrate-storage dry_run='' target_host='xamxam':
|
||||
ssh {{target_host}} 'rm -f /var/www/xamxam/migrate-storage-paths.php'
|
||||
|
||||
[group('deploy')]
|
||||
deploy-all-first: deploy deploy-backup
|
||||
# One-shot: full initial deploy including backup cron.
|
||||
deploy-all-first: deploy deploy-backup deploy-cleanup-cron
|
||||
# One-shot: full initial deploy including backup and cleanup cron jobs.
|
||||
|
||||
# ============================================================================
|
||||
# Testing
|
||||
@@ -434,3 +455,10 @@ clean:
|
||||
@rm -f app/error.log
|
||||
@rm -rf app/storage/cache/rate_limit/*
|
||||
@rm -f /tmp/xamxam-*.log /tmp/xamxam-*.pid
|
||||
|
||||
[group('utils')]
|
||||
cleanup-drafts dry_run='':
|
||||
# List (dry-run) or delete orphaned draft theses older than 24h.
|
||||
# Pass --no-dry-run to actually delete:
|
||||
# just cleanup-drafts --no-dry-run
|
||||
@php -r 'define("APP_ROOT", getcwd()."/app");require APP_ROOT."/src/Database.php";$db=new Database();$dry="{{dry_run}}"!=="--no-dry-run";$res=$db->cleanupOrphanedDrafts(24,$dry);$c=count($res["candidates"]);if($c===0){echo"✅ No orphaned drafts found.\n";}elseif($dry){echo"🔍 Found {$c} orphaned draft(s):\n";foreach($res["candidates"]as$row){printf(" → #%d %s \"%s\" (submitted %s)\n",$row["id"],$row["identifier"],$row["title"],$row["submitted_at"]);}echo"\nRun \"just cleanup-drafts --no-dry-run\" to delete them.\n";}else{echo"🗑 Deleted {$res["deleted"]} orphaned draft(s).\n";}'
|
||||
|
||||
Reference in New Issue
Block a user