fedi-feed-router/app/Services/Article/ValidationService.php

54 lines
1.3 KiB
PHP
Raw Normal View History

2025-06-29 19:46:50 +02:00
<?php
namespace App\Services\Article;
use App\Models\Article;
class ValidationService
{
public static function validate(Article $article): Article
{
logger('Checking keywords for article: ' . $article->id);
2025-06-29 21:33:18 +02:00
$articleData = ArticleFetcher::fetchArticleData($article);
2025-06-30 21:28:15 +02:00
if (!isset($articleData['full_article'])) {
logger()->warning('Article data missing full_article key', [
'article_id' => $article->id,
'url' => $article->url
]);
$article->update([
'is_valid' => false,
'validated_at' => now(),
]);
return $article->refresh();
}
2025-06-29 21:33:18 +02:00
$validationResult = self::validateByKeywords($articleData['full_article']);
2025-06-29 19:46:50 +02:00
$article->update([
2025-06-29 21:33:18 +02:00
'is_valid' => $validationResult,
2025-06-29 19:46:50 +02:00
'validated_at' => now(),
]);
return $article->refresh();
}
2025-06-29 21:33:18 +02:00
private static function validateByKeywords(string $full_article): bool
{
$keywords = [
'N-VA', 'Bart De Wever', 'Frank Vandenbroucke',
];
foreach ($keywords as $keyword) {
if (stripos($full_article, $keyword) !== false) {
return true;
}
}
return false;
}
2025-06-29 19:46:50 +02:00
}