27 lines
838 B
PHP
27 lines
838 B
PHP
<?php
|
|
|
|
namespace App\Channels\ICal;
|
|
|
|
use App\Models\Channel;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class ICalExport
|
|
{
|
|
public function __construct(private ICalFeed $feed, private ICalParser $parser) {}
|
|
|
|
public function build(Channel $channel): ?string
|
|
{
|
|
return DB::transaction(function () use ($channel): ?string {
|
|
$locked = Channel::query()->whereKey($channel->id)->lockForUpdate()->firstOrFail();
|
|
if ($locked->exportsOccupations()) {
|
|
$body = $this->feed->build($locked);
|
|
$this->parser->parse($body);
|
|
$locked->forceFill(['export_snapshot' => $body, 'export_snapshot_at' => now()]);
|
|
}
|
|
$locked->forceFill(['last_export_requested_at' => now()])->saveQuietly();
|
|
|
|
return $locked->export_snapshot;
|
|
});
|
|
}
|
|
}
|