97 lines
3 KiB
PHP
97 lines
3 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\Display;
|
|
use App\Models\DisplayFooterContent;
|
|
use App\Models\DisplayPlaylist;
|
|
use App\Models\DisplayPlaylistItem;
|
|
use App\Models\DisplayVersion;
|
|
use App\Models\DisplayVersionItem;
|
|
use App\Models\DisplayVideo;
|
|
use Illuminate\Console\Command;
|
|
|
|
class MigrateLegacyDisplays extends Command
|
|
{
|
|
protected $signature = 'display:migrate-legacy';
|
|
|
|
protected $description = 'Migrate existing DisplayVideo/DisplayFooterContent data into the new DisplayVersion system';
|
|
|
|
public function handle(): int
|
|
{
|
|
if (DisplayVersion::where('name', 'Video-Display (Legacy)')->exists()) {
|
|
$this->warn('Legacy migration already executed. Skipping.');
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
|
|
$videos = DisplayVideo::orderBy('sort_order')->get();
|
|
$footers = DisplayFooterContent::orderBy('sort_order')->get();
|
|
|
|
if ($videos->isEmpty() && $footers->isEmpty()) {
|
|
$this->info('No legacy data found. Nothing to migrate.');
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
|
|
$version = DisplayVersion::create([
|
|
'name' => 'Video-Display (Legacy)',
|
|
'type' => 'video-display',
|
|
'settings' => [],
|
|
'is_active' => true,
|
|
]);
|
|
|
|
$sortOrder = 0;
|
|
foreach ($videos as $video) {
|
|
DisplayVersionItem::create([
|
|
'display_version_id' => $version->id,
|
|
'item_type' => 'video',
|
|
'content' => [
|
|
'filename' => $video->filename,
|
|
'title' => $video->title,
|
|
'position' => $video->position,
|
|
],
|
|
'sort_order' => $sortOrder++,
|
|
'is_active' => $video->is_active,
|
|
]);
|
|
}
|
|
|
|
$sortOrder = 0;
|
|
foreach ($footers as $footer) {
|
|
DisplayVersionItem::create([
|
|
'display_version_id' => $version->id,
|
|
'item_type' => 'footer',
|
|
'content' => [
|
|
'headline' => $footer->headline,
|
|
'subline' => $footer->subline,
|
|
'url' => $footer->url,
|
|
],
|
|
'sort_order' => $sortOrder++,
|
|
'is_active' => $footer->is_active,
|
|
]);
|
|
}
|
|
|
|
$display = Display::create([
|
|
'name' => 'Hauptdisplay',
|
|
'location' => 'Schaufenster',
|
|
'is_active' => true,
|
|
]);
|
|
|
|
$playlist = $display->playlists()->create([
|
|
'status' => DisplayPlaylist::STATUS_PUBLISHED,
|
|
'published_at' => now(),
|
|
]);
|
|
|
|
DisplayPlaylistItem::create([
|
|
'display_playlist_id' => $playlist->id,
|
|
'display_version_id' => $version->id,
|
|
'sort_order' => 0,
|
|
]);
|
|
|
|
$this->info("Migrated {$videos->count()} videos and {$footers->count()} footer items.");
|
|
$this->info("Created version: {$version->name} (ID: {$version->id})");
|
|
$this->info("Created display: {$display->name} (ID: {$display->id})");
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
}
|