simplify media deletion

This commit is contained in:
Yisroel Baum 2026-06-02 17:12:44 +03:00
parent 247433bc60
commit 01434a9b2d
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
4 changed files with 34 additions and 15 deletions

View file

@ -6,6 +6,7 @@ use App\Element\CreateElementDto;
use App\Element\ElementRepository;
use App\Set\SetRepository;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Storage;
use RuntimeException;
class ElementSeeder extends Seeder
@ -15,11 +16,25 @@ class ElementSeeder extends Seeder
$setRepository = app(SetRepository::class);
$elementRepository = app(ElementRepository::class);
$baderechSet = $setRepository->find(1);
$rootIconImageUrl = $this->seedStorageFile(
base_path(
'../frontend/rabbi_gerzi/public/assets/'
. 'baderech-haavodah-icon.png',
),
'element-icons/baderech-haavodah-icon.png',
);
$introductionPdfPath = $this->seedStorageFile(
base_path(
'../frontend/rabbi_gerzi/public/assets/pdfs/baderech.pdf',
),
'element-pdfs/baderech.pdf',
);
$rootElement = $elementRepository->create(new CreateElementDto(
set: $baderechSet,
title: $baderechSet->getName(),
description: $baderechSet->getDescription(),
iconImageUrl: '/assets/baderech-haavodah-icon.png',
iconImageUrl: $rootIconImageUrl,
richText: '',
pdfPath: null,
youtubeUrl: null,
@ -36,7 +51,7 @@ class ElementSeeder extends Seeder
. 'unlock the ability to live with strength, confidence, '
. 'and hope.',
'richText' => $this->introductionRichText(),
'pdfPath' => '/assets/pdfs/baderech.pdf',
'pdfPath' => $introductionPdfPath,
],
[
'title' => '2. Foundations',
@ -116,6 +131,20 @@ class ElementSeeder extends Seeder
));
}
private function seedStorageFile(
string $sourcePath,
string $storagePath,
): string {
$contents = file_get_contents($sourcePath);
if ($contents === false) {
throw new RuntimeException("Seed file missing: $sourcePath");
}
Storage::disk('public')->put($storagePath, $contents);
return $storagePath;
}
private function introductionRichText(): string
{
return '<h2 style="text-align: center;">'