Files
fewo-stommer/app/Actions/ConfigureChannelExport.php
Lars 7c7955b982
Deploy FeWo mit PipelineManager / deploy (push) Successful in 2m39s
Namensweitergabe direkt abschaltbar machen und reale Regelresultate dokumentieren
2026-10-27 19:14:39 +01:00

31 lines
1.2 KiB
PHP

<?php
namespace App\Actions;
use App\Channels\ICal\ICalExportFields;
use App\Models\Channel;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
class ConfigureChannelExport
{
public function handle(Channel $channel, array $mapping, bool $allowNames): Channel
{
Validator::make(['export_mapping' => $mapping], [
'export_mapping' => ['array', 'max:3'],
'export_mapping.*.field' => ['required', 'distinct', Rule::in(array_keys(ICalExportFields::ICAL_FIELDS))],
'export_mapping.*.items' => ['required', 'array', 'min:1'],
'export_mapping.*.items.*' => ['required', Rule::in(array_keys(ICalExportFields::FIELDS))],
'export_mapping.*.separator' => ['nullable', 'string', 'max:30'],
])->validate();
return DB::transaction(function () use ($channel, $mapping, $allowNames): Channel {
$locked = Channel::query()->whereKey($channel->id)->lockForUpdate()->firstOrFail();
$locked->forceFill(['ical_export_mapping' => array_values($mapping), 'ical_export_names' => $allowNames])->save();
return $locked;
});
}
}