Files
fewo-stommer/app/Actions/RotateChannelToken.php
Lars 783068501c
Deploy FeWo mit PipelineManager / deploy (push) Successful in 2m33s
Generische iCal-Kanäle mit Bestandsklärung und sicheren Exporten bereitstellen
2026-10-27 17:14:45 +01:00

29 lines
1.0 KiB
PHP

<?php
namespace App\Actions;
use App\Models\Channel;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Illuminate\Validation\ValidationException;
class RotateChannelToken
{
public function handle(Channel $channel, int $graceHours = 168): Channel
{
return DB::transaction(function () use ($channel, $graceHours): Channel {
$locked = Channel::query()->whereKey($channel->id)->lockForUpdate()->firstOrFail();
if ($graceHours < 24 || $graceHours > 720 || $locked->previous_export_token_expires_at?->isFuture()) {
throw ValidationException::withMessages(['grace_hours' => '24 bis 720 Stunden wählen; eine laufende Token-Übergangsphase muss zuerst ablaufen.']);
}
$locked->forceFill([
'previous_export_token' => $locked->export_token,
'previous_export_token_expires_at' => now()->addHours($graceHours),
'export_token' => Str::random(48),
])->save();
return $locked->refresh();
});
}
}