Skip to content
Merged
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
"ext-ftp": "*"
},
"replace": {
"hypervel/activity-log": "self.version",
"hypervel/ai": "self.version",
"hypervel/api-client": "self.version",
"hypervel/attributes": "self.version",
Expand Down Expand Up @@ -249,12 +250,14 @@
"aws/aws-sdk-php": "<3.369.1",
"intervention/image": "<4.2 || >=5.0",
"league/flysystem-ftp": "<3.13",
"league/flysystem-sftp-v3": "<3.13"
"league/flysystem-sftp-v3": "<3.13",
"spatie/laravel-activitylog": "*"
},
"minimum-stability": "stable",
"prefer-stable": true,
"autoload": {
"psr-4": {
"Hypervel\\ActivityLog\\": "src/activity-log/src/",
"Hypervel\\Ai\\": "src/ai/src/",
"Hypervel\\ApiClient\\": "src/api-client/src/",
"Hypervel\\Auth\\": "src/auth/src/",
Expand Down Expand Up @@ -350,6 +353,7 @@
"Hypervel\\Workbench\\": "src/workbench/src/"
},
"files": [
"src/activity-log/src/helpers.php",
"src/ai/src/functions.php",
"src/coordinator/src/functions.php",
"src/coroutine/src/functions.php",
Expand Down Expand Up @@ -430,6 +434,7 @@
"Socialite": "Hypervel\\Socialite\\Socialite"
},
"providers": [
"Hypervel\\ActivityLog\\ActivityLogServiceProvider",
"Hypervel\\Ai\\AiServiceProvider",
"Hypervel\\Auth\\AuthServiceProvider",
"Hypervel\\Auth\\Passwords\\PasswordResetServiceProvider",
Expand Down
25 changes: 25 additions & 0 deletions src/activity-log/LICENSE.md
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.
25 changes: 25 additions & 0 deletions src/activity-log/README.md
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
72 changes: 72 additions & 0 deletions src/activity-log/composer.json
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"
]
}
}
}
89 changes: 89 additions & 0 deletions src/activity-log/config/activity-log.php
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,
],
];
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');
}
};
Loading
Loading