59 lines
1.6 KiB
PHP
59 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Domain\Catalog\ContentElementVersion;
|
|
use App\Domain\Catalog\ContentVersionStatus;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Queue\Queueable;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class StoreContentFile implements ShouldQueue
|
|
{
|
|
use Queueable;
|
|
|
|
public function __construct(
|
|
public readonly int $versionId,
|
|
public readonly string $source,
|
|
) {}
|
|
|
|
public function handle(): void
|
|
{
|
|
if (! str_starts_with($this->source, 'inhalte/') || str_contains($this->source, '..')) {
|
|
return;
|
|
}
|
|
|
|
$version = ContentElementVersion::query()->find($this->versionId);
|
|
|
|
if ($version === null || $version->status !== ContentVersionStatus::Entwurf) {
|
|
return;
|
|
}
|
|
|
|
$name = basename($this->source);
|
|
|
|
if (preg_match('/^[A-Za-z0-9._-]+$/', $name) !== 1) {
|
|
return;
|
|
}
|
|
|
|
$target = 'inhalte/'.$version->id.'/'.$name;
|
|
$incoming = Storage::disk('cms_incoming');
|
|
|
|
if (! $incoming->exists($this->source)) {
|
|
return;
|
|
}
|
|
|
|
Storage::disk('media_derived')->put($target, $incoming->get($this->source));
|
|
|
|
$metadata = $version->metadata ?? [];
|
|
unset($metadata['incoming']);
|
|
$metadata['file'] = $target;
|
|
$version->metadata = $metadata;
|
|
$version->content_hash = hash('sha256', json_encode([
|
|
'body' => $version->body,
|
|
'metadata' => $metadata,
|
|
], JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
|
$version->status = ContentVersionStatus::Bereit;
|
|
$version->save();
|
|
}
|
|
}
|