Skip to content

Commit

Permalink
Prune Logs not Configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
RMartinOscar committed Oct 28, 2024
1 parent 40f6cf9 commit f022908
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 51 deletions.
6 changes: 3 additions & 3 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use App\Console\Commands\Schedule\ProcessRunnableCommand;
use App\Jobs\NodeStatistics;
use App\Models\ActivityLog;
use App\Models\WebhookConfiguration;
use App\Models\Webhook;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Database\Console\PruneCommand;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
Expand Down Expand Up @@ -50,8 +50,8 @@ protected function schedule(Schedule $schedule): void
$schedule->command(PruneCommand::class, ['--model' => [ActivityLog::class]])->daily();
}

if (config('webhook.prune_days')) {
$schedule->command(PruneCommand::class, ['--model' => [WebhookConfiguration::class]])->daily();
if (config('panel.webhook.prune_days')) {
$schedule->command(PruneCommand::class, ['--model' => [Webhook::class]])->daily();
}
}
}
2 changes: 1 addition & 1 deletion app/Filament/Pages/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ private function miscSettings(): array
->minValue(1)
->maxValue(365)
->suffix('Days')
->default(env('APP_WEBHOOK_PRUNE_DAYS', config('webhook.prune_days'))),
->default(env('APP_WEBHOOK_PRUNE_DAYS', config('panel.webhook.prune_days'))),
]),
];
}
Expand Down
10 changes: 9 additions & 1 deletion app/Models/Webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

namespace App\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\MassPrunable;
use Illuminate\Database\Eloquent\Model;

class Webhook extends Model
{
use HasFactory;
use HasFactory, MassPrunable;

protected $fillable = ['payload', 'successful_at', 'event', 'endpoint'];

Expand All @@ -18,4 +21,9 @@ public function casts()
'successful_at' => 'datetime',
];
}

public function prunable(): Builder
{
return static::where('created_at', '<=', Carbon::now()->subDays(config('panel.webhook.prune_days')));
}
}
41 changes: 1 addition & 40 deletions app/Models/WebhookConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,12 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\MassPrunable;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\File;

/**
* @property int $id
* @property string $endpoint
* @property string $description
* @property array $events
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property \Illuminate\Support\Carbon|null $deleted_at
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Webhook> $webhooks
* @property-read int|null $webhooks_count
*
* @method static \Database\Factories\WebhookConfigurationFactory factory($count = null, $state = [])
* @method static \Illuminate\Database\Eloquent\Builder|WebhookConfiguration newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|WebhookConfiguration newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|WebhookConfiguration onlyTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|WebhookConfiguration query()
* @method static \Illuminate\Database\Eloquent\Builder|WebhookConfiguration whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|WebhookConfiguration whereDeletedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|WebhookConfiguration whereDescription($value)
* @method static \Illuminate\Database\Eloquent\Builder|WebhookConfiguration whereEndpoint($value)
* @method static \Illuminate\Database\Eloquent\Builder|WebhookConfiguration whereEvents($value)
* @method static \Illuminate\Database\Eloquent\Builder|WebhookConfiguration whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|WebhookConfiguration whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|WebhookConfiguration withTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|WebhookConfiguration withoutTrashed()
*
* @mixin \Eloquent
*/
class WebhookConfiguration extends Model
{
use HasFactory, MassPrunable, SoftDeletes;
use HasFactory, SoftDeletes;

/**
* Blacklisted events.
Expand Down Expand Up @@ -160,12 +129,4 @@ public static function discoverCustomEvents(): array

return $events;
}

/**
* Get the prunable model query.
*/
public function prunable(): Builder
{
return static::where('created_at', '<=', Carbon::now()->subDays(config('webhook.prune_days')));
}
}
12 changes: 12 additions & 0 deletions config/panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,16 @@
'key_limit' => env('API_KEYS_LIMIT', 25),
'key_expire_time' => env('API_KEYS_EXPIRE_TIME', 720),
],

/*
|--------------------------------------------------------------------------
| Webhook Settings
|--------------------------------------------------------------------------
|
| This section controls Webhook configurations
*/

'webhook' => [
'prune_days' => env('APP_WEBHOOK_PRUNE_DAYS', 30),
],
];
6 changes: 0 additions & 6 deletions config/webhook.php

This file was deleted.

0 comments on commit f022908

Please sign in to comment.