Download app/Console/Commands/MigrateExistingCustomGames.php from veela4/gamtest: direct link, hf CLI and curl.
- Browser
- Download file 3.36 kB
-
https://huggingface.co/veela4/gamtest/resolve/main/app/Console/Commands/MigrateExistingCustomGames.php
- Command line
-
hf download hf://veela4/gamtest/app/Console/Commands/MigrateExistingCustomGames.php
-
curl -L -o MigrateExistingCustomGames.php https://huggingface.co/veela4/gamtest/resolve/main/app/Console/Commands/MigrateExistingCustomGames.php
3.36 kB
| namespace App\Console\Commands; | |
| use Illuminate\Console\Command; | |
| use App\Models\Product; | |
| use App\Models\CustomGame; | |
| class MigrateExistingCustomGames extends Command | |
| { | |
| /** | |
| * The name and signature of the console command. | |
| * | |
| * @var string | |
| */ | |
| protected $signature = 'migrate:custom-games'; | |
| /** | |
| * The console command description. | |
| * | |
| * @var string | |
| */ | |
| protected $description = 'Migrate existing custom games from products to custom_games table'; | |
| /** | |
| * Execute the console command. | |
| */ | |
| public function handle() | |
| { | |
| $this->info('Starting migration of existing custom games...'); | |
| // Get all unique custom game categories from existing products | |
| $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) { | |
| // Check if it already exists in custom_games table | |
| $existingCustomGame = CustomGame::where('name', $gameName)->first(); | |
| if (!$existingCustomGame) { | |
| // Generate consistent styling based on game name | |
| $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!'); | |
| } | |
| } | |