Repository navigation
Sync v2: write pgacc's payments into Admidio (accsync.php) - #2
Merged
Merged
Conversation
Replaces the old accsync.php and its cron wrapper lgfmail.sh (the other two scripts of that cron, registration.php and lgfmail.php, are not ported). A CLI script for a systemd timer: a deployment check, a fetch over verified TLS with a bearer token, validation of the whole JSON document, then one transaction that moves "paid until" (field 26) only forward and sets the amount (field 27) to the exact euros, for eligible members only. --dry-run rolls back. The writer's column grants are in pgacc/pgacc_accsync.sql; tests with MariaDB 12.3, PHP 8.5 and a local HTTPS server run in Docker and on GitHub Actions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On an SQL error the run rolls back; it no longer prints change lines for writes that were undone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s timeout; shared test harness Aligned with pgacc's client: the status line check is #^HTTP/\S+ 200( |$)# (accepts "HTTP/1.0 200" without a reason phrase), the timeout is a fixed 20 s (no timeout key in the secrets file), no method or max_redirects options (follow_location 0 stays); the 1 MiB cap and the timed_out check stay. Tests for these, the cap and a 4-digit status. The test harness is the same in both sync v2 branches: one schema with every Admidio table the add-ons use, one users file, every pgacc/*.sql applied, and run.sh runs each tests/*-test.php, each resetting its own data. README: the sync v2 section in the shared structure, with the certificate path convention. LICENSE: the imported files as a list. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…unts-only log - pgacc_accsync.sql: the writer reads and writes profile values only through the definer view pgacc_accsync_user_data (fields 26 and 27, WITH CHECK OPTION; the upserts work through it). No data privilege on adm_user_data any more; REFERENCES on its two key columns only keeps the unique key visible for the deployment check. The file first revokes all of the writer's privileges, so re-applying it leaves exactly these. - Validation rejects the whole document if any date is later than 31 December of next year (GREATEST would keep it for good). - A normal run prints only the counts (no ids or values in the journal); --dry-run still prints each change and skip. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…es the pinned cert
A stored field 26 value that is not an ISO date (e.g. "unknown",
"31.12.2027", "2027-1-5") sorted above every new date in the string
GREATEST and was never replaced, while the pgacc_members view (ISO only)
kept reporting the member as unpaid. The upsert now keeps the old value
only if it matches the view's rule '^[0-9]{4}-[0-9]{2}-[0-9]{2}$' and is
later; otherwise it takes the new value. Tests with non-ISO fixtures,
also for the dry-run change lines.
The "certificate for another name" refusal now pins the served
certificate as the cafile, so it fails only through verify_peer_name.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PHP's stream timeout applies to each read, so a peer trickling the response could keep the oneshot run alive far longer. The fetch now reads the response itself under one deadline and fails closed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
README: one pgacc section with both sync v2 flows; adm_names.php, the old accsync.php and lgfmail.sh removed and replaced; the certificate convention and the tests written once. LICENSE: only mail-alias-sync/adm_mail.php remains imported. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
If the response has a Content-Length header, it must be digits only and equal the body length; otherwise the fetch fails and nothing is written. Tests: a 200 body cut short by an early close, a longer body and a malformed value. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sync v2, reader side in Admidio:
pgacc/accsync.phpwrites pgacc's payments into the members' profiles. It replaces and removes the old mcrypt/mysql_*accsync.phpandlgfmail.sh; the old cron'sregistration.phpandlgfmail.phpare not ported. Counterpart: PPOE/pgacc#83.php pgacc/accsync.php [--dry-run] [--secrets=<file>], or theACCSYNC_SECRETSenv var.adm_user_data (usd_usr_id, usd_usf_id). If any is missing: exit 1.mbapi.php: https only,verify_peer/verify_peer_nameon, pgacc's certificate ascafile, no redirects, a fixed 20 s timeout, a status lineHTTP/<version> 200with or without reason phrase, 1 MiB limit, bearer token. The secrets file isaccsync-secrets.php; pgacc's certificate is/etc/admidio-addons/pgacc-tls.crt(convention: own/etc/<app>/sync-tls.{crt,key}, peer's/etc/<app>/<peer>-tls.crt, self-signed by the callee, handed to the caller through the inventory).[]is a no-op.GREATESTupsert), so a later date entered by hand stays;--dry-runalways rolls back.(usd_usr_id, usd_usf_id, usd_value), because MariaDB needs that forINSERT … ON DUPLICATE KEY UPDATE. The grants are column-level only (pgacc/pgacc_accsync.sql).Tests (red first): Docker with MariaDB 12.3, PHP 8.5 and a local HTTPS server with self-signed certificates, also in GitHub Actions. They cover:
Merging with #1: the test harness (
tests/schema.sqlwith every Admidio table both add-ons use,tests/users.sql,tests/grants.sh,compose.yaml,Dockerfile,run.shrunning eachtests/*-test.php,.github/workflows/tests.yml) is identical in both branches; each branch only adds its own test files andpgacc/*.sql. Whichever merges second merges cleanly except the README sections and the LICENSE list of imported files (keep onlymail-alias-sync/adm_mail.php).Astra review: not run yet (Codex usage limit; pending).
🤖 Generated with Claude Code