2026-03-08 01:18:12 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Actions;
|
|
|
|
|
|
|
|
|
|
use App\Models\Feed;
|
|
|
|
|
use App\Models\Language;
|
2026-03-08 01:42:21 +01:00
|
|
|
use InvalidArgumentException;
|
2026-03-08 01:18:12 +01:00
|
|
|
|
|
|
|
|
class CreateFeedAction
|
|
|
|
|
{
|
|
|
|
|
public function execute(string $name, string $provider, int $languageId, ?string $description = null): Feed
|
|
|
|
|
{
|
|
|
|
|
$language = Language::findOrFail($languageId);
|
|
|
|
|
$langCode = $language->short_code;
|
|
|
|
|
|
|
|
|
|
$url = config("feed.providers.{$provider}.languages.{$langCode}.url");
|
|
|
|
|
|
|
|
|
|
if (!$url) {
|
2026-03-08 01:42:21 +01:00
|
|
|
throw new InvalidArgumentException("Invalid provider and language combination: {$provider}/{$langCode}");
|
2026-03-08 01:18:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$providerConfig = config("feed.providers.{$provider}");
|
|
|
|
|
|
|
|
|
|
return Feed::firstOrCreate(
|
|
|
|
|
['url' => $url],
|
|
|
|
|
[
|
|
|
|
|
'name' => $name,
|
|
|
|
|
'type' => $providerConfig['type'] ?? 'website',
|
|
|
|
|
'provider' => $provider,
|
|
|
|
|
'language_id' => $languageId,
|
|
|
|
|
'description' => $description,
|
|
|
|
|
'is_active' => true,
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|