9A — Gelb geht direkt live (Entscheidung 12.06.2026): - routeByClassification(): Gelb durchlaeuft denselben Auto-Publish-Pfad wie Gruen (autoPublishApproved); nur Rot wird abgelehnt - Scheduler publiziert faellige gelbe + gruene PMs; unklassifizierte bleiben als Fallback in der manuellen Queue 9B — Slot-Verbrauch bei Veroeffentlichung (Decision-Update 3.2): - Increment aus submitForReview() entfernt; publish() und changeStatusFromAdmin() zaehlen idempotent beim ersten published-Uebergang (Pruefung ueber Status-Logs); Rot kostet nichts - Submit-Guard: Einreichen erfordert freien Slot (QuotaExceededException, API 422) 9C — Submit-Gate vorbereitet (Decision-Update 5.1): - User::hasActiveBooking()-Stub hinter config/billing.php (enforce_booking, Default aus); Tarif-Modul ersetzt nur den Rumpf - Einreichungs-Modal zeigt ohne Buchung einen Buchungs-Hinweis; Server-Guard (BookingRequiredException), API antwortet 402 - Fix: Customer-Create legte PMs bei "Zur Pruefung senden" direkt mit Status review an (vorbei an Blacklist/Quota/KI/Status-Log) — laeuft jetzt immer ueber submitForReview() Suite: 451 passed, 4 skipped (9 neue Tests). Pint clean. Plan: docs/PHASE-9-FLOW-UND-TARIFE-PLAN.md (Block 2 nach Review-Stopp). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
118 lines
3.8 KiB
PHP
118 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Enums\PressReleaseClassification;
|
|
use App\Enums\PressReleaseStatus;
|
|
use App\Models\PressRelease;
|
|
use App\Services\PressRelease\BlacklistViolationException;
|
|
use App\Services\PressRelease\PressReleaseService;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Str;
|
|
use Throwable;
|
|
|
|
/**
|
|
* Veröffentlicht Pressemitteilungen mit Status `review`, der KI-Klassifikation
|
|
* `green` und einem `scheduled_at`-Zeitpunkt, der erreicht/überschritten wurde.
|
|
*
|
|
* Läuft regelmäßig per Scheduler (siehe routes/console.php). Idempotent:
|
|
* berührt nur grüne PRs in Review-Status — bereits publishte werden ignoriert.
|
|
* Gelb eingestufte PMs bleiben bewusst in der manuellen Admin-Queue, auch wenn
|
|
* ihr Termin fällig ist.
|
|
*
|
|
* Blacklist-Treffer landen wie beim manuellen Publish im Reject-Status mit
|
|
* Mail-Benachrichtigung des Autors.
|
|
*/
|
|
class PublishScheduledPressReleases extends Command
|
|
{
|
|
/**
|
|
* @var string
|
|
*/
|
|
protected $signature = 'press-releases:publish-scheduled
|
|
{--dry-run : Nur anzeigen, was publiziert würde, ohne DB zu ändern}
|
|
{--limit=200 : Maximale Anzahl pro Lauf}';
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
protected $description = 'Veröffentlicht fällige geplante Pressemitteilungen (Status review + scheduled_at <= now).';
|
|
|
|
public function handle(PressReleaseService $service): int
|
|
{
|
|
$dryRun = (bool) $this->option('dry-run');
|
|
$limit = max(1, (int) $this->option('limit'));
|
|
|
|
$now = now();
|
|
|
|
// Gelb und Grün gehen zum Termin automatisch live (Decision-Update
|
|
// §5.0); nur Rot wird abgelehnt. Unklassifizierte PMs bleiben als
|
|
// Fallback in der manuellen Queue.
|
|
$candidates = PressRelease::withoutGlobalScopes()
|
|
->where('status', PressReleaseStatus::Review->value)
|
|
->whereIn('classification', [
|
|
PressReleaseClassification::Green->value,
|
|
PressReleaseClassification::Yellow->value,
|
|
])
|
|
->whereNotNull('scheduled_at')
|
|
->where('scheduled_at', '<=', $now)
|
|
->orderBy('scheduled_at')
|
|
->limit($limit)
|
|
->get();
|
|
|
|
if ($candidates->isEmpty()) {
|
|
$this->info('Keine fälligen geplanten Pressemitteilungen gefunden.');
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
|
|
$this->info(sprintf(
|
|
'%d fällige Pressemitteilung(en) gefunden.%s',
|
|
$candidates->count(),
|
|
$dryRun ? ' (Dry-Run)' : '',
|
|
));
|
|
|
|
$published = 0;
|
|
$rejected = 0;
|
|
$failed = 0;
|
|
|
|
foreach ($candidates as $pressRelease) {
|
|
$line = sprintf(
|
|
' #%d scheduled_at=%s title="%s"',
|
|
$pressRelease->id,
|
|
$pressRelease->scheduled_at?->format('Y-m-d H:i') ?? '-',
|
|
Str::limit($pressRelease->title, 60),
|
|
);
|
|
|
|
if ($dryRun) {
|
|
$this->line($line.' [DRY]');
|
|
|
|
continue;
|
|
}
|
|
|
|
try {
|
|
$service->publish($pressRelease, source: 'scheduler');
|
|
$published++;
|
|
$this->line($line.' [OK]');
|
|
} catch (BlacklistViolationException $e) {
|
|
$rejected++;
|
|
$this->warn($line.' [REJECT: '.$e->word.']');
|
|
} catch (Throwable $e) {
|
|
$failed++;
|
|
$this->error($line.' [FAIL: '.$e->getMessage().']');
|
|
report($e);
|
|
}
|
|
}
|
|
|
|
if (! $dryRun) {
|
|
$this->newLine();
|
|
$this->info(sprintf(
|
|
'Fertig: %d veröffentlicht, %d wegen Blacklist abgelehnt, %d fehlgeschlagen.',
|
|
$published,
|
|
$rejected,
|
|
$failed,
|
|
));
|
|
}
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
}
|