From 2b05bef5b6ce53d3a992a06f0e0135700ea71df9 Mon Sep 17 00:00:00 2001 From: myrmidex Date: Sun, 29 Jun 2025 09:53:45 +0200 Subject: [PATCH] Add article publishing events --- app/Events/ArticleReadyToPublish.php | 18 ++++++++++++++++++ app/Listeners/CheckArticleKeywords.php | 15 ++++++++++++--- app/Listeners/PublishArticle.php | 19 +++++++++++++++++++ app/Models/Article.php | 1 + app/Providers/AppServiceProvider.php | 7 +++++++ ...025_06_29_072202_create_articles_table.php | 1 + 6 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 app/Events/ArticleReadyToPublish.php create mode 100644 app/Listeners/PublishArticle.php diff --git a/app/Events/ArticleReadyToPublish.php b/app/Events/ArticleReadyToPublish.php new file mode 100644 index 0000000..a23ca5c --- /dev/null +++ b/app/Events/ArticleReadyToPublish.php @@ -0,0 +1,18 @@ +article->id); + logger('Checking keywords for article: ' . $event->article->id); + + // TODO: Add actual keyword checking logic here + // For now, mark all articles as relevant + $isRelevant = true; + + $event->article->update(['is_relevant' => $isRelevant]); + + if ($isRelevant) { + event(new ArticleReadyToPublish($event->article)); + } } } diff --git a/app/Listeners/PublishArticle.php b/app/Listeners/PublishArticle.php new file mode 100644 index 0000000..10cfb95 --- /dev/null +++ b/app/Listeners/PublishArticle.php @@ -0,0 +1,19 @@ +article->id); + // TODO: Add actual publishing logic here + } +} \ No newline at end of file diff --git a/app/Models/Article.php b/app/Models/Article.php index dd4b54e..66a0fa7 100644 --- a/app/Models/Article.php +++ b/app/Models/Article.php @@ -17,6 +17,7 @@ class Article extends Model protected $fillable = [ 'url', + 'is_relevant', ]; public function casts(): array diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index a557d0e..6bf1434 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -3,7 +3,9 @@ namespace App\Providers; use App\Events\ArticleFetched; +use App\Events\ArticleReadyToPublish; use App\Listeners\CheckArticleKeywords; +use App\Listeners\PublishArticle; use Illuminate\Support\Facades\Event; use Illuminate\Support\ServiceProvider; @@ -20,5 +22,10 @@ public function boot(): void ArticleFetched::class, CheckArticleKeywords::class, ); + + Event::listen( + ArticleReadyToPublish::class, + PublishArticle::class, + ); } } diff --git a/database/migrations/2025_06_29_072202_create_articles_table.php b/database/migrations/2025_06_29_072202_create_articles_table.php index db3d3a8..e2dae8c 100644 --- a/database/migrations/2025_06_29_072202_create_articles_table.php +++ b/database/migrations/2025_06_29_072202_create_articles_table.php @@ -11,6 +11,7 @@ public function up(): void Schema::create('articles', function (Blueprint $table) { $table->id(); $table->string('url'); + $table->boolean('is_relevant')->nullable(); $table->timestamp('created_at')->default(now()); }); }