103 lines
3.8 KiB
PHP
103 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Support\Str;
|
|
use App\Models\{Event, Task, Emotion, Photo, PhotoLike, Tenant};
|
|
use Illuminate\Support\Facades\File;
|
|
use Carbon\Carbon;
|
|
|
|
class DemoPhotosSeeder extends Seeder
|
|
{
|
|
public function run(): void
|
|
{
|
|
// Get demo event and tenant
|
|
$demoEvent = Event::where('slug', 'demo-wedding-2025')->first();
|
|
$demoTenant = Tenant::where('slug', 'demo')->first();
|
|
|
|
if (!$demoEvent || !$demoTenant) {
|
|
$this->command->info('Demo event or tenant not found, skipping DemoPhotosSeeder');
|
|
return;
|
|
}
|
|
|
|
// Get all available tasks and emotions
|
|
$tasks = Task::where('tenant_id', $demoTenant->id)->get();
|
|
$emotions = Emotion::all();
|
|
|
|
if ($tasks->isEmpty() || $emotions->isEmpty()) {
|
|
$this->command->info('No tasks or emotions found, skipping DemoPhotosSeeder');
|
|
return;
|
|
}
|
|
|
|
// List of 20 guest names (ASCII only to avoid encoding issues)
|
|
$guestNames = [
|
|
'Anna Mueller', 'Max Schmidt', 'Lisa Weber', 'Tom Fischer', 'Sophie Bauer',
|
|
'Lukas Hoffmann', 'Emma Wagner', 'Jonas Klein', 'Mia Schwarz', 'Felix Becker',
|
|
'Lena Richter', 'Paul Lehmann', 'Julia Neumann', 'David Vogel', 'Sara Krueger',
|
|
'Tim Berger', 'Nina Wolf', 'Ben Schaefer', 'Laura Stein', 'Moritz Fuchs'
|
|
];
|
|
|
|
// Get all photo files from storage
|
|
$photoDir = storage_path('app/public/photos');
|
|
$photoFiles = File::files($photoDir);
|
|
|
|
$seededCount = 0;
|
|
foreach ($photoFiles as $file) {
|
|
$filename = $file->getFilename();
|
|
if (!str_ends_with($filename, '.jpg')) {
|
|
continue;
|
|
}
|
|
|
|
// Check if already seeded (avoid duplicates)
|
|
if (Photo::where('file_path', 'photos/' . $filename)->exists()) {
|
|
continue;
|
|
}
|
|
|
|
// Generate thumbnail path
|
|
$thumbnailFilename = str_replace('.jpg', '_thumb.jpg', $filename);
|
|
$thumbnailPath = 'thumbnails/' . $thumbnailFilename;
|
|
|
|
// Random assignments
|
|
$randomTask = $tasks->random();
|
|
$randomEmotion = $emotions->random();
|
|
$randomGuest = $guestNames[array_rand($guestNames)];
|
|
$randomLikes = rand(0, 20);
|
|
$eventDate = $demoEvent->date;
|
|
$randomUploadedAt = Carbon::parse($eventDate)->addHours(rand(0, 24))->addMinutes(rand(0, 59));
|
|
|
|
// Create photo
|
|
$photo = Photo::create([
|
|
'tenant_id' => $demoTenant->id,
|
|
'event_id' => $demoEvent->id,
|
|
'task_id' => $randomTask->id,
|
|
'emotion_id' => $randomEmotion->id,
|
|
'guest_name' => $randomGuest,
|
|
'file_path' => 'photos/' . $filename,
|
|
'thumbnail_path' => $thumbnailPath,
|
|
'likes_count' => $randomLikes,
|
|
'is_featured' => false,
|
|
'metadata' => [],
|
|
'created_at' => $randomUploadedAt,
|
|
'updated_at' => $randomUploadedAt,
|
|
]);
|
|
|
|
// Add random likes
|
|
if ($randomLikes > 0) {
|
|
for ($i = 0; $i < $randomLikes; $i++) {
|
|
PhotoLike::create([
|
|
'photo_id' => $photo->id,
|
|
'guest_name' => 'GuestLike_' . Str::random(6),
|
|
'ip_address' => '10.0.' . rand(0, 254) . '.' . rand(1, 254),
|
|
'created_at' => $randomUploadedAt->clone()->addMinutes(rand(0, 60)),
|
|
]);
|
|
}
|
|
}
|
|
|
|
$seededCount++;
|
|
}
|
|
|
|
$this->command->info(sprintf('Seeded %d demo photos with random tasks, emotions, uploaders, and likes', $seededCount));
|
|
}
|
|
}
|