diff --git a/app/Console/Commands/FetchNewArticlesCommand.php b/app/Console/Commands/FetchNewArticlesCommand.php index b22b1d5..c0aef79 100644 --- a/app/Console/Commands/FetchNewArticlesCommand.php +++ b/app/Console/Commands/FetchNewArticlesCommand.php @@ -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.'); diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php new file mode 100644 index 0000000..cc168a8 --- /dev/null +++ b/app/Http/Controllers/SettingsController.php @@ -0,0 +1,28 @@ +validate([ + 'article_processing_enabled' => 'boolean', + ]); + + Setting::setArticleProcessingEnabled($request->boolean('article_processing_enabled')); + + return redirect()->route('settings.index') + ->with('success', 'Settings updated successfully.'); + } +} diff --git a/app/Jobs/ArticleDiscoveryJob.php b/app/Jobs/ArticleDiscoveryJob.php index fee0a47..5ea8476 100644 --- a/app/Jobs/ArticleDiscoveryJob.php +++ b/app/Jobs/ArticleDiscoveryJob.php @@ -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(); diff --git a/app/Models/Setting.php b/app/Models/Setting.php new file mode 100644 index 0000000..9027ff0 --- /dev/null +++ b/app/Models/Setting.php @@ -0,0 +1,44 @@ +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); + } +} diff --git a/database/migrations/2025_07_10_085210_create_settings_table.php b/database/migrations/2025_07_10_085210_create_settings_table.php new file mode 100644 index 0000000..c157b1e --- /dev/null +++ b/database/migrations/2025_07_10_085210_create_settings_table.php @@ -0,0 +1,23 @@ +id(); + $table->string('key')->unique(); + $table->text('value'); + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists('settings'); + } +}; diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index d01a0ef..44312ff 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -19,5 +19,7 @@ public function run(): void 'name' => 'Test User', 'email' => 'test@example.com', ]); + + $this->call(SettingsSeeder::class); } } diff --git a/database/seeders/SettingsSeeder.php b/database/seeders/SettingsSeeder.php new file mode 100644 index 0000000..8f6b388 --- /dev/null +++ b/database/seeders/SettingsSeeder.php @@ -0,0 +1,21 @@ + 'article_processing_enabled'], + ['value' => '1'] + ); + } +} diff --git a/resources/views/pages/settings/index.blade.php b/resources/views/pages/settings/index.blade.php new file mode 100644 index 0000000..6591dd4 --- /dev/null +++ b/resources/views/pages/settings/index.blade.php @@ -0,0 +1,56 @@ +@extends('layouts.app') + +@section('content') +