Gib Website-Bilder aus dem Medienmanager frei, ohne sie zu lizenzieren.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
72130d66c5
commit
13530b8171
18 files changed
+940
-2
No files matched your search
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Media\ThumbnailDeriver;
|
||||
use App\Domain\Media\WebsiteRelease;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Queue\Queueable;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class AcceptWebsiteImage implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public function __construct(
|
||||
public int $elementId,
|
||||
public string $incoming,
|
||||
public ?int $actorId = null,
|
||||
) {}
|
||||
|
||||
public function handle(ThumbnailDeriver $deriver, WebsiteRelease $release): void
|
||||
{
|
||||
$element = ContentElement::query()->find($this->elementId);
|
||||
|
||||
if (! $element instanceof ContentElement) {
|
||||
return;
|
||||
}
|
||||
|
||||
$deriver->forWebsiteImage($element, $this->incoming);
|
||||
$element->refresh();
|
||||
|
||||
if ($release->derivedPath($element) === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->incomingIsDisposable()) {
|
||||
Storage::disk('cms_incoming')->delete($this->incoming);
|
||||
}
|
||||
|
||||
PublishWebsiteMedia::dispatch($element->id, 'release', $this->actorId);
|
||||
}
|
||||
|
||||
private function incomingIsDisposable(): bool
|
||||
{
|
||||
return (str_starts_with($this->incoming, 'cms/') || str_starts_with($this->incoming, 'vorschau/'))
|
||||
&& ! str_contains($this->incoming, '..');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\IdentityChange;
|
||||
use App\Domain\Media\WebsiteRelease;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Queue\Queueable;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class PublishWebsiteMedia implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public function __construct(
|
||||
public int $elementId,
|
||||
public string $action,
|
||||
public ?int $actorId = null,
|
||||
) {}
|
||||
|
||||
public function handle(WebsiteRelease $release): void
|
||||
{
|
||||
$element = ContentElement::query()->find($this->elementId);
|
||||
|
||||
if (! $element instanceof ContentElement || ! in_array($this->action, ['release', 'withdraw'], true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->action === 'withdraw') {
|
||||
$this->deletePublicFile($element);
|
||||
$this->mark($element, $element->website_released_at?->toIso8601String(), null);
|
||||
$element->forceFill([
|
||||
'website_released_at' => null,
|
||||
'website_public_path' => null,
|
||||
])->save();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$derived = $release->derivedPath($element);
|
||||
|
||||
if ($derived === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$target = $release->publicPath($element, $derived);
|
||||
$previous = $element->website_public_path;
|
||||
|
||||
Storage::disk('media_public')->put($target, Storage::disk('media_derived')->get($derived));
|
||||
|
||||
if (is_string($previous) && $previous !== $target && str_starts_with($previous, 'website/'.$element->id.'/')) {
|
||||
Storage::disk('media_public')->delete($previous);
|
||||
}
|
||||
|
||||
$this->mark($element, $element->website_released_at?->toIso8601String(), now()->toIso8601String());
|
||||
$element->forceFill([
|
||||
'website_released_at' => now(),
|
||||
'website_public_path' => $target,
|
||||
])->save();
|
||||
}
|
||||
|
||||
private function deletePublicFile(ContentElement $element): void
|
||||
{
|
||||
$path = $element->website_public_path;
|
||||
|
||||
if (! is_string($path) || ! str_starts_with($path, 'website/'.$element->id.'/') || str_contains($path, '..')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Storage::disk('media_public')->delete($path);
|
||||
}
|
||||
|
||||
private function mark(ContentElement $element, ?string $before, ?string $after): void
|
||||
{
|
||||
if ($before === $after) {
|
||||
return;
|
||||
}
|
||||
|
||||
IdentityChange::query()->create([
|
||||
'subject_type' => $element->getMorphClass(),
|
||||
'subject_id' => $element->id,
|
||||
'field' => 'website_released_at',
|
||||
'before' => $before,
|
||||
'after' => $after,
|
||||
'actor_id' => $this->actorId,
|
||||
'occurred_at' => now(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user