Add enable/disable

This commit is contained in:
myrmidex 2025-07-10 11:01:01 +02:00
parent fc155d7962
commit 8f7dbf993d
10 changed files with 195 additions and 0 deletions

View file

@ -4,6 +4,7 @@
use App\Jobs\ArticleDiscoveryJob;
use App\Models\Feed;
use App\Models\Setting;
use Illuminate\Console\Command;
class FetchNewArticlesCommand extends Command
@ -14,6 +15,12 @@ class FetchNewArticlesCommand extends Command
public function handle(): int
{
if (!Setting::isArticleProcessingEnabled()) {
$this->info('Article processing is disabled. Article discovery skipped.');
return self::SUCCESS;
}
if (!Feed::where('is_active', true)->exists()) {
$this->info('No active feeds found. Article discovery skipped.');

View file

@ -0,0 +1,28 @@
<?php
namespace App\Http\Controllers;
use App\Models\Setting;
use Illuminate\Http\Request;
class SettingsController extends Controller
{
public function index()
{
$articleProcessingEnabled = Setting::isArticleProcessingEnabled();
return view('pages.settings.index', compact('articleProcessingEnabled'));
}
public function update(Request $request)
{
$request->validate([
'article_processing_enabled' => 'boolean',
]);
Setting::setArticleProcessingEnabled($request->boolean('article_processing_enabled'));
return redirect()->route('settings.index')
->with('success', 'Settings updated successfully.');
}
}

View file

@ -2,6 +2,7 @@
namespace App\Jobs;
use App\Models\Setting;
use App\Services\Log\LogSaver;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
@ -17,6 +18,12 @@ public function __construct()
public function handle(): void
{
if (!Setting::isArticleProcessingEnabled()) {
LogSaver::info('Article processing is disabled. Article discovery skipped.');
return;
}
LogSaver::info('Starting article discovery for all active feeds');
ArticleDiscoveryForFeedJob::dispatchForAllActiveFeeds();

44
app/Models/Setting.php Normal file
View file

@ -0,0 +1,44 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Setting extends Model
{
protected $fillable = ['key', 'value'];
public static function get(string $key, mixed $default = null): mixed
{
$setting = static::where('key', $key)->first();
return $setting ? $setting->value : $default;
}
public static function set(string $key, mixed $value): void
{
static::updateOrCreate(['key' => $key], ['value' => $value]);
}
public static function getBool(string $key, bool $default = false): bool
{
$value = static::get($key, $default);
return filter_var($value, FILTER_VALIDATE_BOOLEAN);
}
public static function setBool(string $key, bool $value): void
{
static::set($key, $value ? '1' : '0');
}
public static function isArticleProcessingEnabled(): bool
{
return static::getBool('article_processing_enabled', true);
}
public static function setArticleProcessingEnabled(bool $enabled): void
{
static::setBool('article_processing_enabled', $enabled);
}
}

View file

@ -0,0 +1,23 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('settings', function (Blueprint $table) {
$table->id();
$table->string('key')->unique();
$table->text('value');
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('settings');
}
};

View file

@ -19,5 +19,7 @@ public function run(): void
'name' => 'Test User',
'email' => 'test@example.com',
]);
$this->call(SettingsSeeder::class);
}
}

View file

@ -0,0 +1,21 @@
<?php
namespace Database\Seeders;
use App\Models\Setting;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class SettingsSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
Setting::updateOrCreate(
['key' => 'article_processing_enabled'],
['value' => '1']
);
}
}

View file

@ -0,0 +1,56 @@
@extends('layouts.app')
@section('content')
<div class="max-w-7xl mx-auto py-6 sm:px-6 lg:px-8">
<div class="px-4 py-6 sm:px-0">
<div class="flex justify-between items-center mb-6">
<h1 class="text-2xl font-semibold text-gray-900">Settings</h1>
</div>
@if(session('success'))
<div class="bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded mb-4">
{{ session('success') }}
</div>
@endif
<div class="bg-white shadow overflow-hidden sm:rounded-md">
<div class="px-4 py-5 sm:p-6">
<form action="{{ route('settings.update') }}" method="POST">
@csrf
@method('PUT')
<div class="mb-6">
<h3 class="text-lg leading-6 font-medium text-gray-900 mb-4">Article Processing</h3>
<div class="flex items-center justify-between">
<div class="flex-1">
<label class="text-sm font-medium text-gray-700">Enable Article Processing</label>
<p class="text-sm text-gray-500 mt-1">When disabled, the system will not fetch new articles or publish them to platforms.</p>
</div>
<div class="ml-4">
<label class="inline-flex items-center">
<input type="hidden" name="article_processing_enabled" value="0">
<input type="checkbox"
name="article_processing_enabled"
value="1"
{{ $articleProcessingEnabled ? 'checked' : '' }}
class="form-checkbox h-5 w-5 text-blue-600">
<span class="ml-2 text-sm text-gray-700">
{{ $articleProcessingEnabled ? 'Enabled' : 'Disabled' }}
</span>
</label>
</div>
</div>
</div>
<div class="flex justify-end">
<button type="submit" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
Save Settings
</button>
</div>
</form>
</div>
</div>
</div>
</div>
@endsection

View file

@ -29,6 +29,10 @@
<x-heroicon-o-list-bullet class="w-5 h-5 mr-3" />
Logs
</a>
<a href="/settings" class="flex items-center px-4 py-3 text-gray-300 hover:bg-gray-700 hover:text-white transition-colors {{ request()->is('settings*') ? 'bg-gray-700 text-white' : '' }}">
<x-heroicon-o-cog-6-tooth class="w-5 h-5 mr-3" />
Settings
</a>
<a href="/horizon" class="flex items-center px-4 py-3 text-gray-300 hover:bg-gray-700 hover:text-white transition-colors">
<x-heroicon-o-chart-bar class="w-5 h-5 mr-3" />
Queue Monitor

View file

@ -3,6 +3,7 @@
use App\Http\Controllers\ArticlesController;
use App\Http\Controllers\LogsController;
use App\Http\Controllers\OnboardingController;
use App\Http\Controllers\SettingsController;
use Illuminate\Support\Facades\Route;
// Onboarding routes
@ -14,6 +15,8 @@
Route::get('/articles', ArticlesController::class)->name('articles');
Route::get('/logs', LogsController::class)->name('logs');
Route::get('/settings', [SettingsController::class, 'index'])->name('settings.index');
Route::put('/settings', [SettingsController::class, 'update'])->name('settings.update');
Route::resource('platforms', App\Http\Controllers\PlatformAccountsController::class)->names('platforms');
Route::post('/platforms/{platformAccount}/set-active', [App\Http\Controllers\PlatformAccountsController::class, 'setActive'])->name('platforms.set-active');