File size: 3,363 Bytes
70ba896
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php

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!');
    }
}