#!/usr/bin/env bash
set -euo pipefail

# WHP Bichon archival reconciliation
# Compares the per-mailbox archival status WHP has stored with what Bichon reports.
# Marks WHP rows as paused when Bichon's IMAP sync is failing; clears the paused
# state when Bichon is healthy again.
#
# Run daily via cron. flock and timeout are precautionary.

LOG=/var/log/whp/bichon-archival-sync.log
mkdir -p "$(dirname "$LOG")"
exec >>"$LOG" 2>&1
echo "=== $(date -u +%Y-%m-%dT%H:%M:%SZ) bichon-archival-sync starting ==="

php -d display_errors=0 /docker/whp/web/scripts/cli/bichon-archival-sync.php

echo "=== $(date -u +%Y-%m-%dT%H:%M:%SZ) bichon-archival-sync done ==="
