- Publish/Reject/Archive und changeStatus erzwingen konsistent press-releases:publish; changeStatus schloss die Lücke, über die das Status-Modal die Prüfung umging (Fix#1/H2). - publish()/changeStatusFromAdmin sperren PM- und User-Zeile transaktional; QuotaExceededException wird in Admin-Publish und im Auto-Publish-Job abgefangen (Warnung statt 500 / bleibt in Review, Fix#3/M2). - Slug-Erzeugung nur noch über HasUniqueSlug (generateUniqueSlug + saveWithUniqueSlugRetry), redundanter Controller-Helper entfernt (M3). - API-/Legacy-Text wird vor der Persistenz sanitisiert (M6); Scheduler/Legacy-Tracking ignorieren soft-gelöschte PMs. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
119 lines
3.9 KiB
PHP
119 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Enums\PressReleaseClassification;
|
|
use App\Enums\PressReleaseStatus;
|
|
use App\Models\PressRelease;
|
|
use App\Scopes\PortalScope;
|
|
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::withoutGlobalScope(PortalScope::class)
|
|
->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;
|
|
}
|
|
}
|