Reconcile Activity Log with Spatie upstream

Merged
BI
1h ago
+744-284

This reconciles Activity Log with Spatie's main branch through 741ce06abfb91a96d2ee056706a6564ae8a3a71f. It fixes a case where an activity could be attributed to the wrong user and brings the tests and guide up to date.

Causer resolution

A custom activity model can start with a causer already assigned. If a tap() callback removed that causer, log() could assign the authenticated user in its place. The logger now treats the preassigned causer as resolved before the callback runs. The callback's choice survives the write, including when it makes the activity anonymous.

The resolver also accepts Spatie's model: named argument when called from a subclass. Its support for resolving scalar IDs is preserved.

Tests and documentation

The tests follow the upstream cases for late causer resolution, backed-enum log names, cleanup retention, optional insert columns, and custom timestamps. Overlapping cases are consolidated under the upstream test names, retaining Hypervel's assertions for coroutine and transaction behavior.

The transaction tests exercise nested savepoints, ordering, and writes to a dedicated audit database. The activity connection owns the write. Immediate writes on the same connection can commit or roll back with the subject. A separate audit database can record an activity independently of the subject transaction. The guide explains when an application needs an outbox to tie delivery to the domain commit.

The package suite, MySQL, MariaDB and PostgreSQL integration tests, formatting, and static analysis passed locally.

[!NOTE]

Reconcile activity log package with Spatie upstream

  • Fixes ActivityLogger.useDefaultCauserIfNoneWasGiven to resolve the default causer based on the current activity's causer ID, and mark the decision resolved even when the causer is already set or the resolver returns none. A reused logger no longer re-resolves a default causer after that decision.
  • Adds a transaction-focused test suite in ActivityTransactionsTest.php covering buffered and immediate writes, savepoints, subject-vs-activity connections, insert failures, and timestamp handling. Moves related coverage out of ActivityBufferTest.php and reorganizes facade-registration and causer tests into ActivityLoggerTest.php.
  • Updates docs (README, activity-log.md) to describe activity-connection ownership of writes, buffering behavior, outbox use for cross-database delivery, and enum log-name casting. Adds clarifying comments to buffer, cleanup, and persistence code without changing logic.
  • Test model User.getAuthPassword now reads the attribute named by getAuthPasswordName() instead of a fixed name.

Macroscope summarized 1928d4d.

Summary by CodeRabbit

  • Bug Fixes
    • Default causers are now resolved when an activity is logged, and existing or explicitly selected causers are preserved. This also improves causer handling when reusing a logger or changing the causer in a callback.
  • Documentation
    • Expanded activity-log guidance on configuration, custom models, buffering, database connections, transactions, and logger behavior.
    • Added an example of using an enum for activity log names.