Repository navigation
Add the Activity Log package #804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4ccf678
Add the Activity Log package
binaryfire 32e3012
Add Activity Log package tests
binaryfire f4b97dc
Add Activity Log database integration tests
binaryfire 8734ad5
Document Activity Log
binaryfire 06b4207
Preserve Activity Log ordering, database targets, and model snapshots
binaryfire eac4859
Prevent unresolved morph relations from querying the source table
binaryfire 03eca42
Credit Spatie in the Activity Log guide
binaryfire ac8515d
Preserve selected JSON values and buffered activity insert behavior
binaryfire f4af587
Compare mapped activity values as they are recorded
binaryfire 68ab5cf
Use Eloquent cast serialization for selected activity values
binaryfire File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| The MIT License (MIT) | ||
|
|
||
| Copyright (c) Spatie bvba <info@spatie.be> | ||
|
|
||
| Copyright (c) SonicStack | ||
|
|
||
| Copyright (c) Hypervel | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in | ||
| all copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| THE SOFTWARE. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| Activity Log for Hypervel | ||
| === | ||
|
|
||
| Documentation: https://hypervel.org/docs/activity-log | ||
|
|
||
| ## Differences From Spatie Laravel Activity Log | ||
|
|
||
| - Public names use `ActivityLog` and `activity-log` casing. The global | ||
| `activity()` helper is retained. | ||
| - `activity(null)` selects the configured default. Empty string and `"0"` are | ||
| distinct log names. `useLog(null)` and `inLog(null)` explicitly set a null name. | ||
| - Automatic model logging uses the event's in-memory snapshot without another | ||
| subject query. `refreshBeforeLogging()` provides an explicit, | ||
| transaction-only refresh for database-generated values. | ||
| - Dotted relation attributes retain the configured key even when traversal | ||
| resolves a snake-case, camel-case, or dynamic-relation alias. | ||
| - Optional buffering is coroutine-scoped, transaction-aware, and flushed in | ||
| bounded batches at Hypervel lifecycle boundaries. | ||
| - `setLogStatus()` is replaced by `enableLogging()`, `disableLogging()`, and | ||
| `withoutLogging()`. Tests reset callbacks through `flushState()` rather than | ||
| the upstream test-only `clearBeforeLoggingCallbacks()` alias. | ||
| - This package cannot be installed alongside `spatie/laravel-activitylog` | ||
| because both packages provide `activity()` and use the same default table. | ||
|
|
||
| Ported from: https://github.com/spatie/laravel-activitylog | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| { | ||
| "name": "hypervel/activity-log", | ||
| "type": "library", | ||
| "description": "Coroutine-safe activity logging for Hypervel applications.", | ||
| "license": "MIT", | ||
| "keywords": [ | ||
| "php", | ||
| "swoole", | ||
| "activity-log", | ||
| "hypervel" | ||
| ], | ||
| "authors": [ | ||
| { | ||
| "name": "Albert Chen", | ||
| "email": "albert@hypervel.org" | ||
| }, | ||
| { | ||
| "name": "Raj Siva-Rajah", | ||
| "homepage": "https://github.com/binaryfire" | ||
| } | ||
| ], | ||
| "support": { | ||
| "issues": "https://github.com/hypervel/components/issues", | ||
| "source": "https://github.com/hypervel/components" | ||
| }, | ||
| "autoload": { | ||
| "psr-4": { | ||
| "Hypervel\\ActivityLog\\": "src/" | ||
| }, | ||
| "files": [ | ||
| "src/helpers.php" | ||
| ] | ||
| }, | ||
| "require": { | ||
| "php": "^8.4", | ||
| "hypervel/attributes": "^0.4", | ||
| "hypervel/auth": "^0.4", | ||
| "hypervel/collections": "^0.4", | ||
| "hypervel/conditionable": "^0.4", | ||
| "hypervel/config": "^0.4", | ||
| "hypervel/console": "^0.4", | ||
| "hypervel/container": "^0.4", | ||
| "hypervel/context": "^0.4", | ||
| "hypervel/contracts": "^0.4", | ||
| "hypervel/coroutine": "^0.4", | ||
| "hypervel/database": "^0.4", | ||
| "hypervel/events": "^0.4", | ||
| "hypervel/foundation": "^0.4", | ||
| "hypervel/macroable": "^0.4", | ||
| "hypervel/queue": "^0.4", | ||
| "hypervel/support": "^0.4", | ||
| "laravel/serializable-closure": "^2.0.11", | ||
| "nesbot/carbon": "^3.13.1", | ||
| "symfony/console": "^8.1.10" | ||
| }, | ||
| "conflict": { | ||
| "spatie/laravel-activitylog": "*" | ||
| }, | ||
| "config": { | ||
| "sort-packages": true | ||
| }, | ||
| "extra": { | ||
| "branch-alias": { | ||
| "dev-main": "0.4-dev" | ||
| }, | ||
| "hypervel": { | ||
| "providers": [ | ||
| "Hypervel\\ActivityLog\\ActivityLogServiceProvider" | ||
| ] | ||
| } | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| use Hypervel\ActivityLog\Actions\CleanActivityLogAction; | ||
| use Hypervel\ActivityLog\Actions\LogActivityAction; | ||
| use Hypervel\ActivityLog\Models\Activity; | ||
|
|
||
| return [ | ||
| /* | ||
| * If set to false, no activities will be saved to the database. | ||
| */ | ||
| 'enabled' => (bool) env('ACTIVITY_LOG_ENABLED', true), | ||
|
|
||
| /* | ||
| * When the clean command is executed, all activities older than | ||
| * the number of days specified here will be deleted. | ||
| */ | ||
| 'clean_after_days' => 365, | ||
|
|
||
| /* | ||
| * The clean command deletes old activities in batches of this size. | ||
| */ | ||
| 'clean_batch_size' => (int) env('ACTIVITY_LOG_CLEAN_BATCH_SIZE', 1000), | ||
|
|
||
| /* | ||
| * Enable cleanup to delete activities using the retention and batch size | ||
| * above. Otherwise, activities remain until you run activity-log:clean. | ||
| */ | ||
| 'cleanup' => [ | ||
| 'enabled' => (bool) env('ACTIVITY_LOG_CLEANUP_ENABLED', false), | ||
| 'schedule' => env('ACTIVITY_LOG_CLEANUP_SCHEDULE', '9 4 * * *'), | ||
| ], | ||
|
|
||
| /* | ||
| * If no log name is passed to the activity() helper | ||
| * we use this default log name. | ||
| */ | ||
| 'default_log_name' => 'default', | ||
|
|
||
| /* | ||
| * You can specify an auth driver here that gets user models. | ||
| * If this is null we'll use the current Hypervel auth driver. | ||
| */ | ||
| 'default_auth_driver' => null, | ||
|
|
||
| /* | ||
| * If set to true, the subject relationship on activities | ||
| * will include soft deleted models. | ||
| */ | ||
| 'include_soft_deleted_subjects' => false, | ||
|
|
||
| /* | ||
| * This model will be used to log activity. | ||
| * It should implement the activity contract and extend Hypervel's | ||
| * Eloquent model. | ||
| */ | ||
| 'activity_model' => Activity::class, | ||
|
|
||
| /* | ||
| * These attributes will be excluded from logging for all models. | ||
| * Model-specific exclusions via logExcept() are merged with these. | ||
| */ | ||
| 'default_except_attributes' => [], | ||
|
|
||
| /* | ||
| * When enabled, activities are buffered in memory and inserted in bounded | ||
| * batches at Hypervel lifecycle boundaries. This can significantly reduce | ||
| * the number of database queries when many activities are logged during a | ||
| * single request or job. | ||
| * | ||
| * Only enable this if your application logs a high volume of activities | ||
| * per request or job. The returned in-memory activity never receives the | ||
| * ID generated by the later bulk insert. | ||
| */ | ||
| 'buffer' => [ | ||
| 'enabled' => (bool) env('ACTIVITY_LOG_BUFFER_ENABLED', false), | ||
| 'batch_size' => (int) env('ACTIVITY_LOG_BUFFER_BATCH_SIZE', 500), | ||
| ], | ||
|
|
||
| /* | ||
| * These action classes can be overridden to customize how activities | ||
| * are logged and cleaned. Your custom classes must extend the originals. | ||
| */ | ||
| 'actions' => [ | ||
| 'log_activity' => LogActivityAction::class, | ||
| 'clean_log' => CleanActivityLogAction::class, | ||
| ], | ||
| ]; |
44 changes: 44 additions & 0 deletions
44
src/activity-log/database/publish/2026_08_04_000000_create_activity_log_table.php
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| use Hypervel\Database\Migrations\Migration; | ||
| use Hypervel\Database\Schema\Blueprint; | ||
| use Hypervel\Support\Facades\Schema; | ||
|
|
||
| return new class extends Migration { | ||
| /** | ||
| * Run the migrations. | ||
| */ | ||
| public function up(): void | ||
| { | ||
| Schema::create('activity_log', function (Blueprint $table): void { | ||
| $table->id(); | ||
| $table->string('log_name')->nullable(); | ||
| $table->text('description'); | ||
| $table->nullableMorphs('subject', 'activity_log_subject'); | ||
| $table->string('event')->nullable(); | ||
| $table->nullableMorphs('causer', 'activity_log_causer'); | ||
| $table->jsonb('attribute_changes')->nullable(); | ||
| $table->jsonb('properties')->nullable(); | ||
| $table->timestamps(); | ||
|
|
||
| $table->index( | ||
| ['created_at', 'id'], | ||
| 'activity_log_created_at_id_index', | ||
| ); | ||
| $table->index( | ||
| ['log_name', 'created_at', 'id'], | ||
| 'activity_log_name_created_at_id_index', | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Reverse the migrations. | ||
| */ | ||
| public function down(): void | ||
| { | ||
| Schema::dropIfExists('activity_log'); | ||
| } | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.