| <?php |
|
|
| namespace App\Console\Commands; |
|
|
| use Illuminate\Console\Command; |
| use App\Models\Product; |
| use App\Models\CustomGame; |
|
|
| class MigrateExistingCustomGames extends Command |
| { |
| |
| |
| |
| |
| |
| protected $signature = 'migrate:custom-games'; |
|
|
| |
| |
| |
| |
| |
| protected $description = 'Migrate existing custom games from products to custom_games table'; |
|
|
| |
| |
| |
| public function handle() |
| { |
| $this->info('Starting migration of existing custom games...'); |
|
|
| |
| $existingCustomGames = Product::select('game') |
| ->distinct() |
| ->whereNotNull('game') |
| ->whereNotIn('game', ['Genshin', 'Starrail', 'WutheringWave', 'ZenlessZoneZero', 'Arknights', 'AzurLane']) |
| ->pluck('game'); |
|
|
| if ($existingCustomGames->isEmpty()) { |
| $this->info('No existing custom games found to migrate.'); |
| return; |
| } |
|
|
| $this->info("Found {$existingCustomGames->count()} custom games to migrate:"); |
|
|
| $customGameColors = [ |
| 'from-red-500 to-pink-500', |
| 'from-orange-500 to-red-500', |
| 'from-yellow-500 to-orange-500', |
| 'from-green-500 to-teal-500', |
| 'from-teal-500 to-cyan-500', |
| 'from-blue-500 to-indigo-500', |
| 'from-indigo-500 to-purple-500', |
| 'from-purple-500 to-pink-500', |
| 'from-pink-500 to-rose-500', |
| 'from-emerald-500 to-green-500', |
| 'from-cyan-500 to-blue-500', |
| 'from-violet-500 to-purple-500' |
| ]; |
|
|
| $customGameIcons = [ |
| 'fas fa-gamepad', |
| 'fas fa-dice', |
| 'fas fa-chess', |
| 'fas fa-puzzle-piece', |
| 'fas fa-trophy', |
| 'fas fa-crown', |
| 'fas fa-gem', |
| 'fas fa-fire', |
| 'fas fa-bolt', |
| 'fas fa-magic', |
| 'fas fa-dragon', |
| 'fas fa-shield', |
| 'fas fa-sword', |
| 'fas fa-heart', |
| 'fas fa-star', |
| 'fas fa-moon', |
| 'fas fa-sun', |
| 'fas fa-leaf', |
| 'fas fa-snowflake', |
| 'fas fa-mountain' |
| ]; |
|
|
| foreach ($existingCustomGames as $gameName) { |
| |
| $existingCustomGame = CustomGame::where('name', $gameName)->first(); |
| |
| if (!$existingCustomGame) { |
| |
| $hash = crc32($gameName); |
| $colorIndex = abs($hash) % count($customGameColors); |
| $iconIndex = abs($hash >> 8) % count($customGameIcons); |
|
|
| CustomGame::create([ |
| 'name' => $gameName, |
| 'icon' => $customGameIcons[$iconIndex], |
| 'color_gradient' => $customGameColors[$colorIndex] |
| ]); |
|
|
| $this->info("✓ Migrated: {$gameName}"); |
| } else { |
| $this->info("- Already exists: {$gameName}"); |
| } |
| } |
|
|
| $this->info('Migration completed successfully!'); |
| } |
| } |
|
|