diff --git a/app/Filament/Imports/Helper/ImportDetails.php b/app/Filament/Imports/Helper/ImportDetails.php index a2f36b59..89ca8568 100644 --- a/app/Filament/Imports/Helper/ImportDetails.php +++ b/app/Filament/Imports/Helper/ImportDetails.php @@ -16,6 +16,8 @@ class ImportDetails { $now = now()->format('Y-m-d H:i:s'); + $player_collection = []; + SimpleExcelReader::create(storage_path('app/public/'.$filePath)) ->getRows() ->chunk(1000) @@ -38,11 +40,12 @@ class ImportDetails // last_update if ($row[1] != '') { - StatistikoDetail::updateOrCreate( + + $player_collection[] = (int) $row[0]; + + StatistikoDetail::upsert( [ 'ss_player_id' => (int) $row[0], - ], - [ 'ss_team_id' => (int) $row[1], 'player_name' => $row[2], 'ss_national_team_id' => (int) $row[3], @@ -55,15 +58,49 @@ class ImportDetails 'is_active' => 1, 'created_at' => $now, 'updated_at' => $now, + ], + uniqueBy: [ + 'ss_player_id', + ], + update: [ + 'ss_team_id', + 'player_name', + 'ss_national_team_id', + 'birthdate', + 'height', + 'nationality', + 'position', + 'preferred_foot', + 'last_update', + 'is_active', ] ); + // StatistikoDetail::updateOrCreate( + // [ + // 'ss_player_id' => (int) $row[0], + // ], + // [ + // 'ss_team_id' => (int) $row[1], + // 'player_name' => $row[2], + // 'ss_national_team_id' => (int) $row[3], + // 'birthdate' => Carbon::parse($row[4])->format('Y-m-d'), + // 'height' => (int) $row[5], + // 'nationality' => $row[6], + // 'position' => $row[7], + // 'preferred_foot' => $row[8], + // 'last_update' => Carbon::parse($row[9])->format('Y-m-d H:i:s'), + // 'is_active' => 1, + // 'created_at' => $now, + // 'updated_at' => $now, + // ] + // ); } } }); - StatistikoDetail::where('updated_at', '!=', $now)->update(['is_active' => 0, 'ss_team_id' => 0]); + StatistikoDetail::whereNotIn('ss_player_id', $player_collection)->update(['is_active' => 0, 'ss_team_id' => 0]); /**update statistic player tabel */ - UpdateHelper::updatePlayers(1000000); + // UpdateHelper::updatePlayers(1000000); } } diff --git a/app/Filament/Imports/Helper/ImportPlayer.php b/app/Filament/Imports/Helper/ImportPlayer.php index 16a64d79..88be4539 100644 --- a/app/Filament/Imports/Helper/ImportPlayer.php +++ b/app/Filament/Imports/Helper/ImportPlayer.php @@ -117,6 +117,6 @@ class ImportPlayer }); /**update statistic player tabel */ - UpdateHelper::updatePlayers(1000000); + // UpdateHelper::updatePlayers(1000000); } }