Skip to content

P3.1: batch processing foundation — BatchService + auto-attach + 3 enum cases + 13 tests#116

Draft
sjelfull wants to merge 1 commit into
p2.9-real-api-testsfrom
p3.1-batch-api-foundation
Draft

P3.1: batch processing foundation — BatchService + auto-attach + 3 enum cases + 13 tests#116
sjelfull wants to merge 1 commit into
p2.9-real-api-testsfrom
p3.1-batch-api-foundation

Conversation

@sjelfull
Copy link
Copy Markdown
Owner

@sjelfull sjelfull commented May 14, 2026

P3.1: BatchService foundation — open/close/run API for grouping audit rows

Adds BatchService, the core infrastructure for grouping related audit rows under a parent record. A "batch" is an audit row with event BatchStarted/BatchCompleted/BatchFailed that acts as a parent for all rows recorded while the batch is open. The service is the foundation for P3.2 (ResaveElements), P3.3 (CP UI), and P3.4 (Feed Me).

Auto-attachment is wired into AuditRecorder::record(): after the overrides loop and before EVENT_BEFORE_RECORD, if BatchService::currentBatchId() is non-null and $record->parentId is null, the recorder sets the parent automatically. Callers don't need to know about batches — any audit row recorded while a batch is open inherits the parent ID.

What changed

  • src/services/BatchService.php (new, 243 LOC) — open(string $title, array $metadata = []) opens a batch and returns its ID; close(int $batchId, ?string $summary, bool $failed) closes it; run(string $title, callable $callback) wraps open/close around a callback; currentBatchId() returns the active batch ID or null.
  • src/events/BatchStartedEvent.php (new, 20 LOC) — event fired after a batch row is persisted. Observational only (not cancellable).
  • src/events/BatchEndedEvent.php (new, 25 LOC) — event fired after a batch is closed. Carries $failed flag.
  • src/enums/AuditEvent.php (+5 LOC) — adds BatchStarted, BatchCompleted, BatchFailed cases.
  • src/services/AuditRecorder.php (+9 LOC) — auto-attach hook: sets $record->parentId from currentBatchId() when not already set.
  • src/Audit.php (+3 LOC) — registers BatchService in the service container.
  • src/translations/en/audit.php (+5 entries) — batch state labels.
  • tests/Feature/BatchServiceTest.php (new, 304 LOC, +13 tests) — covers open/close/run, auto-attach, nested batch behavior, event firing, and failure path.
  • tests/Feature/EnumCoverageTest.php — updated to include the 3 new enum cases.

Tests

  • +13 tests, +BatchService coverage
  • ECS clean
  • PHPStan clean
  • Fresh-DB green

Stacked on

p2.9-real-api-tests (#115)

@sjelfull
Copy link
Copy Markdown
Owner Author

sjelfull commented May 14, 2026

This change is part of the following stack:

Change managed by git-spice.

This was referenced May 14, 2026
@sjelfull sjelfull force-pushed the p2.9-real-api-tests branch from 49bb901 to fe6c741 Compare May 14, 2026 09:25
@sjelfull sjelfull force-pushed the p3.1-batch-api-foundation branch from f80a04b to baada5e Compare May 14, 2026 09:25
@sjelfull sjelfull force-pushed the p2.9-real-api-tests branch from fe6c741 to 49bb901 Compare May 15, 2026 17:33
@sjelfull sjelfull force-pushed the p3.1-batch-api-foundation branch from baada5e to f80a04b Compare May 15, 2026 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant