diff --git a/TODO.md b/TODO.md index 5c5c76a..06de3e4 100644 --- a/TODO.md +++ b/TODO.md @@ -36,6 +36,13 @@ - [x] `templates/admin/acces.php` — archive button, archived links collapsible section - [x] `scripts/setup-server.sh` — provision `/var/log/xamxam.log` with correct ownership +## Fix remote 500s and broken TFE pages (post-deploy) +- [x] `migrations/pending/008_share_links_is_archived.sql` — `ALTER TABLE share_links ADD COLUMN is_archived` (missing on remote; breaks `acces.php`) +- [x] `migrations/pending/009_admin_audit_log.sql` — `CREATE TABLE admin_audit_log` (missing on remote) +- [x] `migrations/pending/010_smtp_notify_email.sql` — `ALTER TABLE smtp_settings ADD COLUMN notify_email` (missing on remote; breaks `parametres.php` via `SmtpRelay::getSettings()`) +- [x] `migrations/pending/011_thesis_files_sort_and_label.sql` — `ALTER TABLE thesis_files ADD COLUMN sort_order / display_label` (missing on remote; breaks every public TFE detail page) +- [x] `justfile` — added `deploy-migrate` recipe: SSHes to remote and runs `php migrations/run.php` + ## Replace browser dialogs with `` modals - [x] `admin/index.php` — `alert()` (no selection) → ``; `confirm()` bulk publish/unpublish → ``; `confirm()` bulk delete → ``; `confirm()` single delete → ``; inline `confirm()` on Dépublier button removed (no confirmation needed for reversible action) - [x] `admin/tags.php` — `confirm()` merge → ``; `confirm()` delete → `` diff --git a/app/migrations/pending/008_share_links_is_archived.sql b/app/migrations/pending/008_share_links_is_archived.sql new file mode 100644 index 0000000..b918553 --- /dev/null +++ b/app/migrations/pending/008_share_links_is_archived.sql @@ -0,0 +1,5 @@ +-- Migration 008: add is_archived to share_links +-- Required by ShareLink::listActive() / listArchived() / archive() / validateLink(). +ALTER TABLE share_links ADD COLUMN is_archived INTEGER NOT NULL DEFAULT 0; + +CREATE INDEX IF NOT EXISTS idx_share_links_archived ON share_links(is_archived); diff --git a/app/migrations/pending/009_admin_audit_log.sql b/app/migrations/pending/009_admin_audit_log.sql new file mode 100644 index 0000000..3f60b7f --- /dev/null +++ b/app/migrations/pending/009_admin_audit_log.sql @@ -0,0 +1,18 @@ +-- Migration 009: create admin_audit_log table +-- Mirrors every admin action logged to /var/log/xamxam.log. +-- Best-effort: application never fails if this table is absent, but the +-- table must exist for AdminLogger::insertDb() to write audit records. +CREATE TABLE IF NOT EXISTS admin_audit_log ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + created_at DATETIME DEFAULT CURRENT_TIMESTAMP, + ip TEXT NOT NULL, + user_agent TEXT, + resource TEXT NOT NULL, + action TEXT NOT NULL, + status TEXT NOT NULL, + context TEXT +); + +CREATE INDEX IF NOT EXISTS idx_admin_audit_log_created_at ON admin_audit_log(created_at); +CREATE INDEX IF NOT EXISTS idx_admin_audit_log_resource ON admin_audit_log(resource); +CREATE INDEX IF NOT EXISTS idx_admin_audit_log_action ON admin_audit_log(action); diff --git a/app/migrations/pending/010_smtp_notify_email.sql b/app/migrations/pending/010_smtp_notify_email.sql new file mode 100644 index 0000000..c5202cc --- /dev/null +++ b/app/migrations/pending/010_smtp_notify_email.sql @@ -0,0 +1,4 @@ +-- Migration 010: add notify_email to smtp_settings +-- Required by SmtpRelay::getSettings() which SELECTs this column. +-- Absence of this column causes a fatal SQL error on parametres.php. +ALTER TABLE smtp_settings ADD COLUMN notify_email TEXT NOT NULL DEFAULT ''; diff --git a/app/migrations/pending/011_thesis_files_sort_and_label.sql b/app/migrations/pending/011_thesis_files_sort_and_label.sql new file mode 100644 index 0000000..7dabbb9 --- /dev/null +++ b/app/migrations/pending/011_thesis_files_sort_and_label.sql @@ -0,0 +1,5 @@ +-- Migration 011: add sort_order and display_label to thesis_files +-- Required by Database::getThesisFiles() which runs ORDER BY sort_order. +-- Absence of sort_order causes a fatal SQL error on every public TFE detail page. +ALTER TABLE thesis_files ADD COLUMN sort_order INTEGER NOT NULL DEFAULT 0; +ALTER TABLE thesis_files ADD COLUMN display_label TEXT; diff --git a/app/storage/logs/admin.log b/app/storage/logs/admin.log index e6a8d9e..94b822a 100644 --- a/app/storage/logs/admin.log +++ b/app/storage/logs/admin.log @@ -1 +1,4 @@ {"timestamp":"2026-05-04T15:36:30+00:00","ip":"127.0.0.1","user_agent":"Mozilla/5.0 (X11; Linux x86_64; rv:150.0) Gecko/20100101 Firefox/150.0","resource":"system","action":"maintenance_on","status":"success"} +{"timestamp":"2026-05-04T15:53:38+00:00","ip":"127.0.0.1","user_agent":"Mozilla/5.0 (X11; Linux x86_64; rv:150.0) Gecko/20100101 Firefox/150.0","resource":"system","action":"maintenance_off","status":"success"} +{"timestamp":"2026-05-04T15:53:44+00:00","ip":"127.0.0.1","user_agent":"Mozilla/5.0 (X11; Linux x86_64; rv:150.0) Gecko/20100101 Firefox/150.0","resource":"system","action":"maintenance_on","status":"success"} +{"timestamp":"2026-05-04T16:11:57+00:00","ip":"127.0.0.1","user_agent":"Mozilla/5.0 (X11; Linux x86_64; rv:150.0) Gecko/20100101 Firefox/150.0","resource":"system","action":"maintenance_off","status":"success"} diff --git a/app/storage/maintenance.flag b/app/storage/maintenance.flag deleted file mode 100644 index cb8489c..0000000 --- a/app/storage/maintenance.flag +++ /dev/null @@ -1 +0,0 @@ -2026-05-04T15:36:30+00:00 \ No newline at end of file diff --git a/justfile b/justfile index 77bc449..cb0fe84 100644 --- a/justfile +++ b/justfile @@ -60,6 +60,11 @@ deploy: app/ xamxam:/var/www/xamxam/ ssh xamxam "mkdir -p /var/www/xamxam/var/{cache,logs,tmp}" +[group('deploy')] +deploy-migrate: + # Run pending DB migrations on the remote production database + ssh xamxam "cd /var/www/xamxam && php migrations/run.php /var/www/xamxam/storage/xamxam.db" + [group('deploy')] deploy-db: @ssh xamxam '[ ! -f /var/www/xamxam/storage/xamxam.db ]' || (echo "ERROR: remote database already exists. Remove it manually if you intend to overwrite." && exit 1)