Repository navigation
Add the Activity Log package - #155
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
PR Summary by QodoAdd Activity Log package (hypervel/activity-log)
AI Description
Merge Risk
|
Code Review by Qodo
1.
|
[Medium impact] The PR appears safe to merge, with the previous enum-collection failure addressed and no new blocking findings. SummaryAdds optional
Reviews (5) · Last reviewed commit: "Use Eloquent cast serialization for sele..." · Reviewed by Greptile |
Bind buffered inserts and transaction callbacks to the connection that owns the activity. Flush eligible rows in call order across savepoints, keep each coroutine's buffer independent, and preserve per-statement hooks and binary bindings. Read cleanup batches from the writer. Use the model's extraction overrides for both sides of a change. Keep raw values intact, distinguish typed JSON values, and handle partial models and explicitly selected relationships. Track actual restores so ordinary updates and restore events each produce the intended history. Preserve explicit and preassigned causers during nested lookups, restore logging status after callbacks, and support backed-enum log names. Update the generated facade and its type coverage, declare the Composer helper conflict, and document connection selection and buffering behavior. Exercise these paths in package and integration tests, including scoped connections, real queue-worker completion, and competing database writes.
A partially selected model can have a foreign ID without its morph type. The temporary relation used for eager loading then points at the source table, where an unrelated row can have the same ID. Mark that relation at construction so lazy reads and touches cannot use the source row. Keep eager loading and custom typed relations on their existing paths. Report an omitted type through the normal strict-mode handler at read time without running unrelated cached cast setters. Use the same marker when collecting activity changes so an unknown target stays out of the audit. Cover projected reads, explicit queries, touches, strict access, and association, including preservation of an unrelated cached JSON value.
Add a Credits section linking to Spatie's Laravel Activity Log and list it in the table of contents, following the other ported package guides.
Keep a selected JSON column or parent path intact when another selector names one of its children. Compare nested cast values by their contents so unrelated updates leave them out of the log and scalar type changes remain visible. Reject invalid relation paths before invoking base model helpers. Use the activity model's insert attributes after preparing timestamps on a snapshot. Custom insert hooks can choose the final columns in either persistence mode while generated IDs stay available to the caller. Respect application transactions inside database tests and flush eligible rows inside the wrapping transaction. If a failed batch leaves rows in memory, let the wrapper discard them on rollback. Cover the write order, failed batch, and finalization against a real transaction manager. Explain the primary key requirement when cleaning keyless activity models and clarify the environment settings and JSON selections in the guide.
|
On the job-attempt flush mentioned in the review summary, Foundation registers an active listener for JobAttempted in registerDeferHandler(). That makes the worker dispatch the event. I verified with a real queue worker that the Activity Log observer writes the buffered row before the attempt returns. |
Let collections serialize their own items when comparing old and new activity values. Reading the raw item list bypassed the collection's Arrayable conversion, and loose object equality could hide a change from a number to a string in a public field. Compare object values through their JSON representation. Keep the fast path for identical values, early exit for arrays, and interval handling. Exercise public-field, Arrayable and JSON-serializable mapped items on both an unrelated update and a change in scalar type. Give both Arrayable test fixtures the return shape their contract expects.
Read the selected value on the model that owns it and honor its cast serializer before comparing or recording changes. A non-backed enum collection can now be audited by case name, including when it is reached through a relation or JSON path. Reuse each JSON root across sibling paths in a snapshot. Let collection roots expose their mapped items in the same form they would record for a whole-column selection. Preserve raw selections and getter overrides. Enum cases and dates returned by getters still use their configured audit formats, while scalar values returned by getters are recorded as supplied.
This adds
hypervel/activity-log, an optional package for recording application activity in a database. An entry can describe an action, the model it affected, who performed it, and any properties the application wants to keep.Models can also use
LogsActivityto record Eloquent events. The model chooses which attributes to log and whether to keep only changes. By default, the logger reads the model as it was at the event. Applications that need database-generated values can opt into a refresh inside the writing transaction.Persistence
Activities are saved immediately by default. Applications can opt into buffering to insert rows in batches. Each coroutine owns its buffer and its current causer. For an activity recorded on a connection with an open transaction, a rollback discards the buffered entry. After commit, a later batch writes it. Applications that need the activity and the domain change to commit together can use immediate writes on the same connection.
Installation and use
Composer discovers the service provider. The application publishes the migration before running it, so it can choose the appropriate morph keys and indexes. The package includes a cleanup command with configurable retention and optional scheduling. The guide covers installation, querying, model events, transaction behavior, and differences from Spatie’s Laravel Activity Log.
Verification
The package tests cover model changes, causer resolution, coroutine isolation, buffer flushing, and rollback. The migration and row-locking tests ran against MySQL, MariaDB, and PostgreSQL. A clean application installed the split package, published and ran the migration, and recorded an activity through the helper.
Summary by cubic
Adds
hypervel/activity-log, an optional package for recording application activity in a database. Activities log an action, the affected model, who performed it, and arbitrary properties through a helper or automatic model event logging.Persistence
refreshBeforeLogging()opts into a refresh inside the writing transaction, and restores are logged separately from updates.Safety and installation
spatie/laravel-activitylog; applications publish the migration to choose morph keys and indexes, and the package ships a cleanup command with configurable retention.Written for commit 68ab5cf. Summary will update on new commits.
Note
Add the Hypervel Activity Log package with model, logger, buffering, and cleanup
Introduces a new
hypervel/activity-logpackage that records model events and manual activity to anactivity_logtable. It is modeled after spatie/laravel-activitylog and conflicts with that package in Composer.ActivityEloquent model with subject/causer morph relations and query scopes (inLog,causedBy,forSubject,forEvent), plus theLogsActivity,CausesActivity, andHasActivitymodel concerns and theactivity()helper and facade.LogActivityAction(description placeholders, subject hooks, before-logging callbacks) andCleanActivityLogAction(batched deletion older than a retention cutoff) with anactivity-log:cleanconsole command and scheduled cleanup.ActivityBufferfor transaction-aware activity buffering, flushed at application termination and after non-sync job attempts.MorphTorelations built before the morph type is known now return as eager-loading placeholders (no query, default value returned) in MorphTo.php, andSoftDeletesexposes an is-restoring flag in SoftDeletes.php.spatie/laravel-activitylog, so projects using that package cannot install both. TheMorphToplaceholder change altersmorphTobehavior when the morph type attribute is missing — see HasRelationships.php.Macroscope summarized 68ab5cf.