mirror of
https://github.com/pelican-dev/panel.git
synced 2025-09-08 09:58:37 +02:00
Remove leftovers from activity log batch (#1649)
This commit is contained in:
parent
8f277aaca0
commit
7ace3978d8
@ -21,7 +21,6 @@ use Illuminate\Support\Str;
|
|||||||
* \App\Models\ActivityLog.
|
* \App\Models\ActivityLog.
|
||||||
*
|
*
|
||||||
* @property int $id
|
* @property int $id
|
||||||
* @property string|null $batch
|
|
||||||
* @property string $event
|
* @property string $event
|
||||||
* @property string $ip
|
* @property string $ip
|
||||||
* @property string|null $description
|
* @property string|null $description
|
||||||
@ -43,7 +42,6 @@ use Illuminate\Support\Str;
|
|||||||
* @method static Builder|ActivityLog whereActorId($value)
|
* @method static Builder|ActivityLog whereActorId($value)
|
||||||
* @method static Builder|ActivityLog whereActorType($value)
|
* @method static Builder|ActivityLog whereActorType($value)
|
||||||
* @method static Builder|ActivityLog whereApiKeyId($value)
|
* @method static Builder|ActivityLog whereApiKeyId($value)
|
||||||
* @method static Builder|ActivityLog whereBatch($value)
|
|
||||||
* @method static Builder|ActivityLog whereDescription($value)
|
* @method static Builder|ActivityLog whereDescription($value)
|
||||||
* @method static Builder|ActivityLog whereEvent($value)
|
* @method static Builder|ActivityLog whereEvent($value)
|
||||||
* @method static Builder|ActivityLog whereId($value)
|
* @method static Builder|ActivityLog whereId($value)
|
||||||
@ -76,7 +74,6 @@ class ActivityLog extends Model implements HasIcon, HasLabel
|
|||||||
/** @var array<array-key, string[]> */
|
/** @var array<array-key, string[]> */
|
||||||
public static array $validationRules = [
|
public static array $validationRules = [
|
||||||
'event' => ['required', 'string'],
|
'event' => ['required', 'string'],
|
||||||
'batch' => ['nullable', 'uuid'],
|
|
||||||
'ip' => ['required', 'string'],
|
'ip' => ['required', 'string'],
|
||||||
'description' => ['nullable', 'string'],
|
'description' => ['nullable', 'string'],
|
||||||
'properties' => ['array'],
|
'properties' => ['array'],
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
use App\Services\Activity\ActivityLogBatchService;
|
|
||||||
use App\Services\Activity\ActivityLogTargetableService;
|
use App\Services\Activity\ActivityLogTargetableService;
|
||||||
|
|
||||||
class ActivityLogServiceProvider extends ServiceProvider
|
class ActivityLogServiceProvider extends ServiceProvider
|
||||||
@ -14,7 +13,6 @@ class ActivityLogServiceProvider extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
public function register(): void
|
public function register(): void
|
||||||
{
|
{
|
||||||
$this->app->scoped(ActivityLogBatchService::class);
|
|
||||||
$this->app->scoped(ActivityLogTargetableService::class);
|
$this->app->scoped(ActivityLogTargetableService::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,60 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Services\Activity;
|
|
||||||
|
|
||||||
use Ramsey\Uuid\Uuid;
|
|
||||||
|
|
||||||
class ActivityLogBatchService
|
|
||||||
{
|
|
||||||
protected int $transaction = 0;
|
|
||||||
|
|
||||||
protected ?string $uuid = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the UUID of the batch, or null if there is not a batch currently
|
|
||||||
* being executed.
|
|
||||||
*/
|
|
||||||
public function uuid(): ?string
|
|
||||||
{
|
|
||||||
return $this->uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Starts a new batch transaction. If there is already a transaction present
|
|
||||||
* this will be nested.
|
|
||||||
*/
|
|
||||||
public function start(): void
|
|
||||||
{
|
|
||||||
if ($this->transaction === 0) {
|
|
||||||
$this->uuid = Uuid::uuid4()->toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->transaction++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ends a batch transaction, if this is the last transaction in the stack
|
|
||||||
* the UUID will be cleared out.
|
|
||||||
*/
|
|
||||||
public function end(): void
|
|
||||||
{
|
|
||||||
$this->transaction = max(0, $this->transaction - 1);
|
|
||||||
|
|
||||||
if ($this->transaction === 0) {
|
|
||||||
$this->uuid = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Executes the logic provided within the callback in the scope of an activity
|
|
||||||
* log batch transaction.
|
|
||||||
*/
|
|
||||||
public function transaction(\Closure $callback): mixed
|
|
||||||
{
|
|
||||||
$this->start();
|
|
||||||
$result = $callback($this->uuid());
|
|
||||||
$this->end();
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
}
|
|
@ -24,7 +24,6 @@ class ActivityLogService
|
|||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
protected AuthFactory $manager,
|
protected AuthFactory $manager,
|
||||||
protected ActivityLogBatchService $batch,
|
|
||||||
protected ActivityLogTargetableService $targetable,
|
protected ActivityLogTargetableService $targetable,
|
||||||
protected ConnectionInterface $connection
|
protected ConnectionInterface $connection
|
||||||
) {}
|
) {}
|
||||||
@ -201,7 +200,6 @@ class ActivityLogService
|
|||||||
|
|
||||||
$this->activity = new ActivityLog([
|
$this->activity = new ActivityLog([
|
||||||
'ip' => Request::ip(),
|
'ip' => Request::ip(),
|
||||||
'batch_uuid' => $this->batch->uuid(),
|
|
||||||
'properties' => Collection::make([]),
|
'properties' => Collection::make([]),
|
||||||
'api_key_id' => $this->targetable->apiKeyId(),
|
'api_key_id' => $this->targetable->apiKeyId(),
|
||||||
]);
|
]);
|
||||||
|
@ -26,7 +26,6 @@ class ActivityLogTransformer extends BaseClientTransformer
|
|||||||
// the front-end for each entry to improve rendering performance since there
|
// the front-end for each entry to improve rendering performance since there
|
||||||
// is nothing else sufficiently unique to key off at this point.
|
// is nothing else sufficiently unique to key off at this point.
|
||||||
'id' => sha1((string) $model->id),
|
'id' => sha1((string) $model->id),
|
||||||
'batch' => $model->batch,
|
|
||||||
'event' => $model->event,
|
'event' => $model->event,
|
||||||
'is_api' => !is_null($model->api_key_id),
|
'is_api' => !is_null($model->api_key_id),
|
||||||
'ip' => $this->canViewIP($model->actor) ? $model->ip : null,
|
'ip' => $this->canViewIP($model->actor) ? $model->ip : null,
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('activity_logs', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('batch');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('activity_logs', function (Blueprint $table) {
|
||||||
|
$table->string('batch', 36)->nullable();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user