56 lines
1.8 KiB
PHP
56 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Services\NovaCards;
|
|
|
|
use App\Jobs\NovaCards\RenderNovaCardPreviewJob;
|
|
use App\Models\NovaCard;
|
|
use App\Services\NovaCards\NovaCardPublishModerationService;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
class NovaCardPublishService
|
|
{
|
|
public function __construct(
|
|
private readonly NovaCardRenderService $renderService,
|
|
private readonly NovaCardVersionService $versions,
|
|
private readonly NovaCardPublishModerationService $moderation,
|
|
) {
|
|
}
|
|
|
|
public function queuePublish(NovaCard $card): NovaCard
|
|
{
|
|
$card->forceFill([
|
|
'status' => NovaCard::STATUS_PROCESSING,
|
|
'moderation_status' => NovaCard::MOD_PENDING,
|
|
'published_at' => $card->published_at ?? Carbon::now(),
|
|
'render_version' => (int) $card->render_version + 1,
|
|
])->save();
|
|
|
|
RenderNovaCardPreviewJob::dispatch($card->id)
|
|
->onQueue((string) config('nova_cards.render.queue', 'default'));
|
|
|
|
return $card->refresh();
|
|
}
|
|
|
|
public function publishNow(NovaCard $card): NovaCard
|
|
{
|
|
$card->forceFill([
|
|
'status' => NovaCard::STATUS_PROCESSING,
|
|
'moderation_status' => NovaCard::MOD_PENDING,
|
|
'published_at' => $card->published_at ?? Carbon::now(),
|
|
'render_version' => (int) $card->render_version + 1,
|
|
])->save();
|
|
|
|
$this->renderService->render($card->refresh());
|
|
|
|
$evaluation = $this->moderation->evaluate($card->fresh()->loadMissing(['originalCard.user', 'rootCard.user']));
|
|
|
|
$card = $this->moderation->applyPublishOutcome($card->fresh(), $evaluation);
|
|
|
|
$this->versions->snapshot($card->refresh()->loadMissing('template'), $card->user, 'Published version', true);
|
|
|
|
return $card->refresh()->load(['category', 'template', 'tags', 'backgroundImage']);
|
|
}
|
|
}
|