From 046407df18da3b163a489569f2ed4e6c073ae488 Mon Sep 17 00:00:00 2001 From: salam Date: Sat, 7 Feb 2026 07:08:58 +0100 Subject: [PATCH] save updates --- app/Console/Commands/Grapper/Betica.php | 3 +- .../Commands/Grapper/Betsapi/Bet365.php | 25 +++++++--- app/Console/Commands/Grapper/Betsapi/Odds.php | 9 +++- app/Console/Commands/Grapper/Logifuture.php | 47 ++++++++++++++++--- .../Commands/Grapper/Logifuture/Soccer.php | 19 ++++++-- .../Commands/Grapper/Logifuture/Tennis.php | 9 +++- .../Tools/LogifutureStorePoints.php | 5 +- .../Tools/LogifutureStorePointsQ1.php | 5 +- .../Tools/LogifutureStoreTotals.php | 5 +- .../Tools/LogifutureStoreTotalsQ1.php | 5 +- .../Commands/Grapper/Magloo/Fixtures.php | 28 +++++++++-- .../Grapper/Magloo/Odds/MaglooStore1x2.php | 5 +- .../Grapper/Magloo/Odds/MaglooStoreDc.php | 5 +- .../Grapper/Magloo/Odds/MaglooStoreGgng.php | 5 +- .../Grapper/Magloo/Odds/MaglooStorePoints.php | 5 +- .../Magloo/Odds/MaglooStorePointsQ1.php | 5 +- .../Grapper/Magloo/Odds/MaglooStoreTotals.php | 5 +- .../Magloo/Odds/MaglooStoreTotalsQ1.php | 5 +- .../Grapper/Magloo/Odds/MaglooStoreTq.php | 5 +- app/Console/Commands/Grapper/TxOdds/Odds.php | 34 ++++++++------ .../Commands/Grapper/TxOdds/Odds/_2Way.php | 20 +------- .../Commands/Grapper/TxOdds/Odds/_2WayS1.php | 19 +------- .../Commands/Grapper/TxOdds/Odds/_3Way.php | 20 +------- .../Commands/Grapper/TxOdds/Odds/_3WayHt.php | 20 +------- .../Commands/Grapper/TxOdds/Odds/_Dc.php | 20 +------- .../Commands/Grapper/TxOdds/Odds/_Dnb.php | 20 +------- .../Commands/Grapper/TxOdds/Odds/_Ggng.php | 20 +------- .../Commands/Grapper/TxOdds/Odds/_Points.php | 20 +------- .../Grapper/TxOdds/Odds/_PointsHt.php | 20 +------- .../Grapper/TxOdds/Odds/_PointsQ1.php | 20 +------- .../Commands/Grapper/TxOdds/Odds/_Totals.php | 20 +------- .../Grapper/TxOdds/Odds/_TotalsHt.php | 20 +------- .../Grapper/TxOdds/Odds/_TotalsQ1.php | 20 +------- .../Commands/Grapper/TxOdds/Odds/_Tq.php | 20 +------- .../Services/Tasks/DBConsistencyChecker.php | 23 +++++++++ app/Utilities/DatabaseFunctions.php | 30 ++++++++++++ 36 files changed, 261 insertions(+), 305 deletions(-) create mode 100644 app/Console/Commands/Services/Tasks/DBConsistencyChecker.php create mode 100644 app/Utilities/DatabaseFunctions.php diff --git a/app/Console/Commands/Grapper/Betica.php b/app/Console/Commands/Grapper/Betica.php index ee55deef..e0e0a996 100644 --- a/app/Console/Commands/Grapper/Betica.php +++ b/app/Console/Commands/Grapper/Betica.php @@ -213,7 +213,8 @@ class Betica } } } - sleep(10); + + usleep(rand(10000, 20000)); } } } diff --git a/app/Console/Commands/Grapper/Betsapi/Bet365.php b/app/Console/Commands/Grapper/Betsapi/Bet365.php index 79be644f..8c210791 100644 --- a/app/Console/Commands/Grapper/Betsapi/Bet365.php +++ b/app/Console/Commands/Grapper/Betsapi/Bet365.php @@ -13,6 +13,7 @@ use App\Models\OddsDnb; use App\Models\OddsGgng; use App\Models\OddsTotal; use App\Models\Sport; +use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; use App\Utilities\Notice; use Illuminate\Support\Carbon; @@ -118,7 +119,9 @@ class Bet365 $res->d3w = $odds['a3w']; $res->flags = 1; $res->margin = $odds['margin']; - $res->save(); + + DatabaseFunctions::save_update($res); + } } } @@ -152,7 +155,9 @@ class Bet365 $res->dcx2 = $odds['dcx2']; $res->flags = 1; $res->margin = $odds['margin']; - $res->save(); + + DatabaseFunctions::save_update($res); + } } } @@ -193,7 +198,9 @@ class Bet365 $res->difference = abs(1 / $odds['over'] - 1 / $odds['under']); $res->flags = 1; $res->margin = $odds['margin']; - $res->save(); + + DatabaseFunctions::save_update($res); + } } } @@ -226,7 +233,9 @@ class Bet365 $res->ng = $odds['ng']; $res->flags = 1; $res->margin = $odds['margin']; - $res->save(); + + DatabaseFunctions::save_update($res); + } } } @@ -258,7 +267,9 @@ class Bet365 $res->dnb2 = $odds['dnb2']; $res->flags = 1; $res->margin = $odds['margin']; - $res->save(); + + DatabaseFunctions::save_update($res); + } } } @@ -292,7 +303,9 @@ class Bet365 $res->d3w = $odds['a3w']; $res->flags = 1; $res->margin = $odds['margin']; - $res->save(); + + DatabaseFunctions::save_update($res); + } } } diff --git a/app/Console/Commands/Grapper/Betsapi/Odds.php b/app/Console/Commands/Grapper/Betsapi/Odds.php index f6167e7c..ebb45533 100644 --- a/app/Console/Commands/Grapper/Betsapi/Odds.php +++ b/app/Console/Commands/Grapper/Betsapi/Odds.php @@ -7,6 +7,7 @@ use App\Console\Commands\Nuh; use App\Models\Event; use App\Models\Odds3way; use App\Models\Supervisor; +use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; use App\Utilities\Notice; use Illuminate\Support\Carbon; @@ -98,7 +99,9 @@ class Odds $res->d3w = $odds['a3w']; $res->flags = 1; $res->margin = $odds['margin']; - $res->save(); + + DatabaseFunctions::save_update($res); + } break; case '1_3': @@ -123,7 +126,9 @@ class Odds $res->d3w = $odds['a3w']; $res->flags = 1; $res->margin = $odds['margin']; - $res->save(); + + DatabaseFunctions::save_update($res); + } break; } diff --git a/app/Console/Commands/Grapper/Logifuture.php b/app/Console/Commands/Grapper/Logifuture.php index dc3df1ee..6acb1b3b 100644 --- a/app/Console/Commands/Grapper/Logifuture.php +++ b/app/Console/Commands/Grapper/Logifuture.php @@ -15,6 +15,7 @@ use App\Models\EventBookmaker; use App\Models\Sport; use App\Utilities\Notice; use Illuminate\Support\Facades\DB; +use PDOException; class Logifuture { @@ -58,11 +59,28 @@ class Logifuture $event_id_collector[] = $event['id']; - EventBookmaker::updateOrCreate([ - 'event_id' => $event['id'], - 'sport_id' => $sport_id, - 'bookmaker_id' => Nuh::$options['bookmaker_id'], - ], ['in_feed' => 1, 'bmoid' => $event['event_id'], 'startime' => $event['starttime']]); + $max_tries = 5; + $tries = 0; + do { + $retry = false; + try { + + $handle = EventBookmaker::updateOrCreate([ + 'event_id' => $event['id'], + 'sport_id' => $sport_id, + 'bookmaker_id' => Nuh::$options['bookmaker_id'], + ], ['in_feed' => 1, 'bmoid' => $event['event_id'], 'startime' => $event['starttime']]); + + return $handle; + } catch (PDOException $exc) { + if ($tries < $max_tries && $exc->errorInfo[0] == 40001 && $exc->errorInfo[1] == 1213) { + $retry = true; + sleep(1); + } else { + throw $exc; + } + } + } while ($retry); switch ($sport_id) { case 1: @@ -90,7 +108,24 @@ class Logifuture } } if ($event_id_collector) { - EventBookmaker::whereNotIn('event_id', $event_id_collector)->where('bookmaker_id', Nuh::$options['bookmaker_id'])->update(['in_feed' => 0]); + $max_tries = 5; + $tries = 0; + do { + $retry = false; + try { + + $handle = EventBookmaker::whereNotIn('event_id', $event_id_collector)->where('bookmaker_id', Nuh::$options['bookmaker_id'])->update(['in_feed' => 0]); + + return $handle; + } catch (PDOException $exc) { + if ($tries < $max_tries && $exc->errorInfo[0] == 40001 && $exc->errorInfo[1] == 1213) { + $retry = true; + sleep(1); + } else { + throw $exc; + } + } + } while ($retry); $tables = ['odds_2ways', 'odds_2ways_s1', 'odds_3ways', 'odds_totals', 'odds_points', 'odds_ggng', 'odds_dc', 'odds_tq', 'odds_points_q1', 'odds_totals_q1']; foreach ($tables as $table) { diff --git a/app/Console/Commands/Grapper/Logifuture/Soccer.php b/app/Console/Commands/Grapper/Logifuture/Soccer.php index 65866162..1b980c07 100644 --- a/app/Console/Commands/Grapper/Logifuture/Soccer.php +++ b/app/Console/Commands/Grapper/Logifuture/Soccer.php @@ -8,6 +8,7 @@ use App\Models\OddsDc; use App\Models\OddsGgng; use App\Models\OddsTotal; use App\Models\OddsTq; +use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; class Soccer @@ -93,7 +94,9 @@ class Soccer $res->a3w = number_format($_3way['a3w'], 2); $res->flags = 1; $res->margin = $_3way['margin']; - $res->save(); + + DatabaseFunctions::save_update($res); + } } // OU @@ -117,7 +120,9 @@ class Soccer $res->under = number_format($_total['under'], 2); $res->flags = 1; $res->margin = $_total['margin']; - $res->save(); + + DatabaseFunctions::save_update($res); + } } // GG NG @@ -136,7 +141,8 @@ class Soccer $res->ng = number_format($_ggng['ng'], 2); $res->flags = 1; $res->margin = $_ggng['margin']; - $res->save(); + + DatabaseFunctions::save_update($res); } } @@ -157,7 +163,8 @@ class Soccer $res->dcx2 = number_format($_dc['dcx2'], 2); $res->flags = 1; $res->margin = $_dc['margin']; - $res->save(); + + DatabaseFunctions::save_update($res); } } @@ -177,7 +184,9 @@ class Soccer $res->atq = number_format($_tq['atq'], 2); $res->flags = 1; $res->margin = $_tq['margin']; - $res->save(); + + DatabaseFunctions::save_update($res); + } } } diff --git a/app/Console/Commands/Grapper/Logifuture/Tennis.php b/app/Console/Commands/Grapper/Logifuture/Tennis.php index 8e7a203a..80cce7d3 100644 --- a/app/Console/Commands/Grapper/Logifuture/Tennis.php +++ b/app/Console/Commands/Grapper/Logifuture/Tennis.php @@ -8,6 +8,7 @@ use App\Console\Commands\Grapper\Logifuture\Tools\LogifutureStoreTotals; use App\Console\Commands\Nuh; use App\Models\Odds2way; use App\Models\Odds2wayS1; +use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; class Tennis @@ -84,7 +85,9 @@ class Tennis $res->a2w = number_format($ml['a2w'], 2); $res->flags = 1; $res->margin = $ml['margin']; - $res->save(); + + DatabaseFunctions::save_update($res); + } } @@ -103,7 +106,9 @@ class Tennis $res->a2w = number_format($ml['a2w'], 2); $res->flags = 1; $res->margin = $mls1['margin']; - $res->save(); + + DatabaseFunctions::save_update($res); + } } diff --git a/app/Console/Commands/Grapper/Logifuture/Tools/LogifutureStorePoints.php b/app/Console/Commands/Grapper/Logifuture/Tools/LogifutureStorePoints.php index e44dfc84..10a5ace2 100644 --- a/app/Console/Commands/Grapper/Logifuture/Tools/LogifutureStorePoints.php +++ b/app/Console/Commands/Grapper/Logifuture/Tools/LogifutureStorePoints.php @@ -3,6 +3,7 @@ namespace App\Console\Commands\Grapper\Logifuture\Tools; use App\Models\OddsPoint; +use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; class LogifutureStorePoints @@ -39,7 +40,9 @@ class LogifutureStorePoints $res->difference = $odds['difference']; $res->flags = 1; $res->margin = $odds['margin']; - $res->save(); + + DatabaseFunctions::save_update($res); + } } } diff --git a/app/Console/Commands/Grapper/Logifuture/Tools/LogifutureStorePointsQ1.php b/app/Console/Commands/Grapper/Logifuture/Tools/LogifutureStorePointsQ1.php index 79b73510..bd64b600 100644 --- a/app/Console/Commands/Grapper/Logifuture/Tools/LogifutureStorePointsQ1.php +++ b/app/Console/Commands/Grapper/Logifuture/Tools/LogifutureStorePointsQ1.php @@ -3,6 +3,7 @@ namespace App\Console\Commands\Grapper\Logifuture\Tools; use App\Models\OddsPointQ1; +use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; class LogifutureStorePointsQ1 @@ -39,7 +40,9 @@ class LogifutureStorePointsQ1 $res->difference = $odds['difference']; $res->flags = 1; $res->margin = $odds['margin']; - $res->save(); + + DatabaseFunctions::save_update($res); + } } } diff --git a/app/Console/Commands/Grapper/Logifuture/Tools/LogifutureStoreTotals.php b/app/Console/Commands/Grapper/Logifuture/Tools/LogifutureStoreTotals.php index f71f061e..d694a5d5 100644 --- a/app/Console/Commands/Grapper/Logifuture/Tools/LogifutureStoreTotals.php +++ b/app/Console/Commands/Grapper/Logifuture/Tools/LogifutureStoreTotals.php @@ -3,6 +3,7 @@ namespace App\Console\Commands\Grapper\Logifuture\Tools; use App\Models\OddsTotal; +use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; class LogifutureStoreTotals @@ -39,7 +40,9 @@ class LogifutureStoreTotals $res->difference = $odds['difference']; $res->flags = 1; $res->margin = $odds['margin']; - $res->save(); + + DatabaseFunctions::save_update($res); + } } } diff --git a/app/Console/Commands/Grapper/Logifuture/Tools/LogifutureStoreTotalsQ1.php b/app/Console/Commands/Grapper/Logifuture/Tools/LogifutureStoreTotalsQ1.php index 7452561a..1b57e341 100644 --- a/app/Console/Commands/Grapper/Logifuture/Tools/LogifutureStoreTotalsQ1.php +++ b/app/Console/Commands/Grapper/Logifuture/Tools/LogifutureStoreTotalsQ1.php @@ -3,6 +3,7 @@ namespace App\Console\Commands\Grapper\Logifuture\Tools; use App\Models\OddsTotalQ1; +use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; class LogifutureStoreTotalsQ1 @@ -39,7 +40,9 @@ class LogifutureStoreTotalsQ1 $res->difference = $odds['difference']; $res->flags = 1; $res->margin = $odds['margin']; - $res->save(); + + DatabaseFunctions::save_update($res); + } } } diff --git a/app/Console/Commands/Grapper/Magloo/Fixtures.php b/app/Console/Commands/Grapper/Magloo/Fixtures.php index 4e281a75..6c68fc9f 100644 --- a/app/Console/Commands/Grapper/Magloo/Fixtures.php +++ b/app/Console/Commands/Grapper/Magloo/Fixtures.php @@ -9,6 +9,7 @@ use App\Models\EventBookmaker; use App\Models\Sport; use App\Utilities\Notice; use Illuminate\Support\Carbon; +use PDOException; class Fixtures { @@ -104,11 +105,28 @@ class Fixtures $event_id_collector[] = $event['id']; - EventBookmaker::updateOrCreate([ - 'event_id' => $event['id'], - 'sport_id' => $sport_id, - 'bookmaker_id' => Nuh::$options['bookmaker_id'], - ], ['in_feed' => 1, 'bmoid' => $event['event_id'], 'starttime' => $event['starttime']]); + $max_tries = 5; + $tries = 0; + do { + $retry = false; + try { + $handle = EventBookmaker::updateOrCreate([ + 'event_id' => $event['id'], + 'sport_id' => $sport_id, + 'bookmaker_id' => Nuh::$options['bookmaker_id'], + ], ['in_feed' => 1, 'bmoid' => $event['event_id'], 'starttime' => $event['starttime']]); + + return $handle; + } catch (PDOException $exc) { + if ($tries < $max_tries && $exc->errorInfo[0] == 40001 && $exc->errorInfo[1] == 1213) { + $retry = true; + sleep(1); + } else { + throw $exc; + } + } + } while ($retry); + } } } diff --git a/app/Console/Commands/Grapper/Magloo/Odds/MaglooStore1x2.php b/app/Console/Commands/Grapper/Magloo/Odds/MaglooStore1x2.php index 5ce6420e..48c8eb78 100644 --- a/app/Console/Commands/Grapper/Magloo/Odds/MaglooStore1x2.php +++ b/app/Console/Commands/Grapper/Magloo/Odds/MaglooStore1x2.php @@ -3,6 +3,7 @@ namespace App\Console\Commands\Grapper\Magloo\Odds; use App\Models\Odds3way; +use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; class MaglooStore1x2 @@ -26,7 +27,9 @@ class MaglooStore1x2 $res->d3w = $odds['a3w']; $res->flags = 1; $res->margin = $odds['margin']; - $res->save(); + + DatabaseFunctions::save_update($res); + } } } diff --git a/app/Console/Commands/Grapper/Magloo/Odds/MaglooStoreDc.php b/app/Console/Commands/Grapper/Magloo/Odds/MaglooStoreDc.php index 98536afb..10f24156 100644 --- a/app/Console/Commands/Grapper/Magloo/Odds/MaglooStoreDc.php +++ b/app/Console/Commands/Grapper/Magloo/Odds/MaglooStoreDc.php @@ -3,6 +3,7 @@ namespace App\Console\Commands\Grapper\Magloo\Odds; use App\Models\OddsDc; +use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; class MaglooStoreDc @@ -27,7 +28,9 @@ class MaglooStoreDc $res->dcx2 = $odds['dcx2']; $res->flags = 1; $res->margin = $odds['margin']; - $res->save(); + + DatabaseFunctions::save_update($res); + } } diff --git a/app/Console/Commands/Grapper/Magloo/Odds/MaglooStoreGgng.php b/app/Console/Commands/Grapper/Magloo/Odds/MaglooStoreGgng.php index 671bd435..81cb1ea3 100644 --- a/app/Console/Commands/Grapper/Magloo/Odds/MaglooStoreGgng.php +++ b/app/Console/Commands/Grapper/Magloo/Odds/MaglooStoreGgng.php @@ -3,6 +3,7 @@ namespace App\Console\Commands\Grapper\Magloo\Odds; use App\Models\OddsGgng; +use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; class MaglooStoreGgng @@ -25,7 +26,9 @@ class MaglooStoreGgng $res->ng = $odds['ng']; $res->flags = 1; $res->margin = $odds['margin']; - $res->save(); + + DatabaseFunctions::save_update($res); + } } } diff --git a/app/Console/Commands/Grapper/Magloo/Odds/MaglooStorePoints.php b/app/Console/Commands/Grapper/Magloo/Odds/MaglooStorePoints.php index a89ebec2..eb2d00a6 100644 --- a/app/Console/Commands/Grapper/Magloo/Odds/MaglooStorePoints.php +++ b/app/Console/Commands/Grapper/Magloo/Odds/MaglooStorePoints.php @@ -3,6 +3,7 @@ namespace App\Console\Commands\Grapper\Magloo\Odds; use App\Models\OddsPoint; +use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; class MaglooStorePoints @@ -36,7 +37,9 @@ class MaglooStorePoints $res->active_spread = $odds['active_spread']; $res->difference = $odds['difference']; $res->margin = $odds['margin']; - $res->save(); + + DatabaseFunctions::save_update($res); + } } } diff --git a/app/Console/Commands/Grapper/Magloo/Odds/MaglooStorePointsQ1.php b/app/Console/Commands/Grapper/Magloo/Odds/MaglooStorePointsQ1.php index dd26e841..e88aae4a 100644 --- a/app/Console/Commands/Grapper/Magloo/Odds/MaglooStorePointsQ1.php +++ b/app/Console/Commands/Grapper/Magloo/Odds/MaglooStorePointsQ1.php @@ -3,6 +3,7 @@ namespace App\Console\Commands\Grapper\Magloo\Odds; use App\Models\OddsPointQ1; +use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; class MaglooStorePointsQ1 @@ -36,7 +37,9 @@ class MaglooStorePointsQ1 $res->active_spread = $odds['active_spread']; $res->difference = $odds['difference']; $res->margin = $odds['margin']; - $res->save(); + + DatabaseFunctions::save_update($res); + } } } diff --git a/app/Console/Commands/Grapper/Magloo/Odds/MaglooStoreTotals.php b/app/Console/Commands/Grapper/Magloo/Odds/MaglooStoreTotals.php index fd03a386..b908ab8c 100644 --- a/app/Console/Commands/Grapper/Magloo/Odds/MaglooStoreTotals.php +++ b/app/Console/Commands/Grapper/Magloo/Odds/MaglooStoreTotals.php @@ -3,6 +3,7 @@ namespace App\Console\Commands\Grapper\Magloo\Odds; use App\Models\OddsTotal; +use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; class MaglooStoreTotals @@ -36,7 +37,9 @@ class MaglooStoreTotals $res->active_spread = $odds['active_spread']; $res->difference = $odds['difference']; $res->margin = $odds['margin']; - $res->save(); + + DatabaseFunctions::save_update($res); + } } } diff --git a/app/Console/Commands/Grapper/Magloo/Odds/MaglooStoreTotalsQ1.php b/app/Console/Commands/Grapper/Magloo/Odds/MaglooStoreTotalsQ1.php index 848f3ed3..2aca21c3 100644 --- a/app/Console/Commands/Grapper/Magloo/Odds/MaglooStoreTotalsQ1.php +++ b/app/Console/Commands/Grapper/Magloo/Odds/MaglooStoreTotalsQ1.php @@ -3,6 +3,7 @@ namespace App\Console\Commands\Grapper\Magloo\Odds; use App\Models\OddsTotalQ1; +use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; class MaglooStoreTotalsQ1 @@ -36,7 +37,9 @@ class MaglooStoreTotalsQ1 $res->active_spread = $odds['active_spread']; $res->difference = $odds['difference']; $res->margin = $odds['margin']; - $res->save(); + + DatabaseFunctions::save_update($res); + } } } diff --git a/app/Console/Commands/Grapper/Magloo/Odds/MaglooStoreTq.php b/app/Console/Commands/Grapper/Magloo/Odds/MaglooStoreTq.php index 35368438..b7754a3b 100644 --- a/app/Console/Commands/Grapper/Magloo/Odds/MaglooStoreTq.php +++ b/app/Console/Commands/Grapper/Magloo/Odds/MaglooStoreTq.php @@ -3,6 +3,7 @@ namespace App\Console\Commands\Grapper\Magloo\Odds; use App\Models\OddsTq; +use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; class MaglooStoreTq @@ -25,7 +26,9 @@ class MaglooStoreTq $res->htq = $odds['htq']; $res->atq = $odds['atq']; $res->margin = $odds['margin']; - $res->save(); + + DatabaseFunctions::save_update($res); + } } } diff --git a/app/Console/Commands/Grapper/TxOdds/Odds.php b/app/Console/Commands/Grapper/TxOdds/Odds.php index 637d3d40..ce5e146f 100644 --- a/app/Console/Commands/Grapper/TxOdds/Odds.php +++ b/app/Console/Commands/Grapper/TxOdds/Odds.php @@ -27,6 +27,7 @@ use App\Models\EventBookmaker; use App\Models\Group; use App\Models\Supervisor; use App\Models\TxoddsMarket; +use App\Utilities\DatabaseFunctions; use App\Utilities\Notice; use Illuminate\Support\Carbon; @@ -316,12 +317,13 @@ class Odds case 0: foreach ($offer->odds->attributes() as $attributeName => $attributeValue) { switch ($attributeName) { + case 'starting_time': - EventBookmaker::updateOrInsert([ - 'event_id' => $event_id, - 'sport_id' => $sport_id, - 'bookmaker_id' => $bookmaker_id, - ], ['starttime' => $attributeValue]); + $res = EventBookmaker::where('event_id', $event_id)->where('bookmaker_id', $bookmaker_id)->first(); + if ($res->starttime != $attributeValue) { + $res->starttime = $attributeValue; + DatabaseFunctions::save_update($res); + } break; } } @@ -332,11 +334,12 @@ class Odds foreach ($offer->odds->attributes() as $attributeName => $attributeValue) { switch ($attributeName) { case 'starting_time': - EventBookmaker::updateOrInsert([ - 'event_id' => $event_id, - 'sport_id' => $sport_id, - 'bookmaker_id' => $bookmaker_id, - ], ['starttime' => $attributeValue]); + + $res = EventBookmaker::where('event_id', $event_id)->where('bookmaker_id', $bookmaker_id)->first(); + if ($res->starttime != $attributeValue) { + $res->starttime = $attributeValue; + DatabaseFunctions::save_update($res); + } break; } } @@ -347,11 +350,12 @@ class Odds foreach ($offer->odds->attributes() as $attributeName => $attributeValue) { switch ($attributeName) { case 'starting_time': - EventBookmaker::updateOrInsert([ - 'event_id' => $event_id, - 'sport_id' => $sport_id, - 'bookmaker_id' => $bookmaker_id, - ], ['starttime' => $attributeValue]); + + $res = EventBookmaker::where('event_id', $event_id)->where('bookmaker_id', $bookmaker_id)->first(); + if ($res->starttime != $attributeValue) { + $res->starttime = $attributeValue; + DatabaseFunctions::save_update($res); + } break; } } diff --git a/app/Console/Commands/Grapper/TxOdds/Odds/_2Way.php b/app/Console/Commands/Grapper/TxOdds/Odds/_2Way.php index 618840e4..4878594a 100644 --- a/app/Console/Commands/Grapper/TxOdds/Odds/_2Way.php +++ b/app/Console/Commands/Grapper/TxOdds/Odds/_2Way.php @@ -4,8 +4,8 @@ namespace App\Console\Commands\Grapper\TxOdds\Odds; use App\Console\Commands\Nuh; use App\Models\Odds2way; +use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; -use PDOException; class _2Way { @@ -29,24 +29,8 @@ class _2Way $res->flags = 1; $res->margin = $odds['margin']; - $max_tries = 5; - $tries = 0; - do { - $retry = false; - try { + DatabaseFunctions::save_update($res); - $res->save(); - - return $res; - } catch (PDOException $exc) { - if ($tries < $max_tries && $exc->errorInfo[0] == 40001 && $exc->errorInfo[1] == 1213) { - $retry = true; - sleep(1); - } else { - throw $exc; - } - } - } while ($retry); } } } diff --git a/app/Console/Commands/Grapper/TxOdds/Odds/_2WayS1.php b/app/Console/Commands/Grapper/TxOdds/Odds/_2WayS1.php index 6a9ff6fb..facc92bb 100644 --- a/app/Console/Commands/Grapper/TxOdds/Odds/_2WayS1.php +++ b/app/Console/Commands/Grapper/TxOdds/Odds/_2WayS1.php @@ -4,8 +4,8 @@ namespace App\Console\Commands\Grapper\TxOdds\Odds; use App\Console\Commands\Nuh; use App\Models\Odds2wayS1; +use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; -use PDOException; class _2WayS1 { @@ -29,23 +29,8 @@ class _2WayS1 $res->flags = 1; $res->margin = $odds['margin']; - $max_tries = 5; - $tries = 0; - do { - $retry = false; - try { - $res->save(); + DatabaseFunctions::save_update($res); - return $res; - } catch (PDOException $exc) { - if ($tries < $max_tries && $exc->errorInfo[0] == 40001 && $exc->errorInfo[1] == 1213) { - $retry = true; - sleep(1); - } else { - throw $exc; - } - } - } while ($retry); } } } diff --git a/app/Console/Commands/Grapper/TxOdds/Odds/_3Way.php b/app/Console/Commands/Grapper/TxOdds/Odds/_3Way.php index 0edf2bba..53377d81 100644 --- a/app/Console/Commands/Grapper/TxOdds/Odds/_3Way.php +++ b/app/Console/Commands/Grapper/TxOdds/Odds/_3Way.php @@ -4,8 +4,8 @@ namespace App\Console\Commands\Grapper\TxOdds\Odds; use App\Console\Commands\Nuh; use App\Models\Odds3way; +use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; -use PDOException; class _3Way { @@ -32,23 +32,7 @@ class _3Way $res->flags = 1; $res->margin = $odds['margin']; - $max_tries = 5; - $tries = 0; - do { - $retry = false; - try { - $res->save(); - - return $res; - } catch (PDOException $exc) { - if ($tries < $max_tries && $exc->errorInfo[0] == 40001 && $exc->errorInfo[1] == 1213) { - $retry = true; - sleep(1); - } else { - throw $exc; - } - } - } while ($retry); + DatabaseFunctions::save_update($res); } } } diff --git a/app/Console/Commands/Grapper/TxOdds/Odds/_3WayHt.php b/app/Console/Commands/Grapper/TxOdds/Odds/_3WayHt.php index 5b7adcdf..bbca2517 100644 --- a/app/Console/Commands/Grapper/TxOdds/Odds/_3WayHt.php +++ b/app/Console/Commands/Grapper/TxOdds/Odds/_3WayHt.php @@ -4,8 +4,8 @@ namespace App\Console\Commands\Grapper\TxOdds\Odds; use App\Console\Commands\Nuh; use App\Models\Odds3wayHt; +use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; -use PDOException; class _3WayHt { @@ -31,24 +31,8 @@ class _3WayHt $res->flags = 1; $res->margin = $odds['margin']; - $max_tries = 5; - $tries = 0; - do { - $retry = false; - try { + DatabaseFunctions::save_update($res); - $res->save(); - - return $res; - } catch (PDOException $exc) { - if ($tries < $max_tries && $exc->errorInfo[0] == 40001 && $exc->errorInfo[1] == 1213) { - $retry = true; - sleep(1); - } else { - throw $exc; - } - } - } while ($retry); } } } diff --git a/app/Console/Commands/Grapper/TxOdds/Odds/_Dc.php b/app/Console/Commands/Grapper/TxOdds/Odds/_Dc.php index 06df01d7..407bacf6 100644 --- a/app/Console/Commands/Grapper/TxOdds/Odds/_Dc.php +++ b/app/Console/Commands/Grapper/TxOdds/Odds/_Dc.php @@ -4,8 +4,8 @@ namespace App\Console\Commands\Grapper\TxOdds\Odds; use App\Console\Commands\Nuh; use App\Models\OddsDc; +use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; -use PDOException; class _Dc { @@ -31,24 +31,8 @@ class _Dc $res->flags = 1; $res->margin = $odds['margin']; - $max_tries = 5; - $tries = 0; - do { - $retry = false; - try { + DatabaseFunctions::save_update($res); - $res->save(); - - return $res; - } catch (PDOException $exc) { - if ($tries < $max_tries && $exc->errorInfo[0] == 40001 && $exc->errorInfo[1] == 1213) { - $retry = true; - sleep(1); - } else { - throw $exc; - } - } - } while ($retry); } } } diff --git a/app/Console/Commands/Grapper/TxOdds/Odds/_Dnb.php b/app/Console/Commands/Grapper/TxOdds/Odds/_Dnb.php index cffd803b..d30787b0 100644 --- a/app/Console/Commands/Grapper/TxOdds/Odds/_Dnb.php +++ b/app/Console/Commands/Grapper/TxOdds/Odds/_Dnb.php @@ -4,8 +4,8 @@ namespace App\Console\Commands\Grapper\TxOdds\Odds; use App\Console\Commands\Nuh; use App\Models\OddsDnb; +use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; -use PDOException; class _Dnb { @@ -29,24 +29,8 @@ class _Dnb $res->flags = 1; $res->margin = $odds['margin']; - $max_tries = 5; - $tries = 0; - do { - $retry = false; - try { + DatabaseFunctions::save_update($res); - $res->save(); - - return $res; - } catch (PDOException $exc) { - if ($tries < $max_tries && $exc->errorInfo[0] == 40001 && $exc->errorInfo[1] == 1213) { - $retry = true; - sleep(1); - } else { - throw $exc; - } - } - } while ($retry); } } } diff --git a/app/Console/Commands/Grapper/TxOdds/Odds/_Ggng.php b/app/Console/Commands/Grapper/TxOdds/Odds/_Ggng.php index c49000da..b73e8e27 100644 --- a/app/Console/Commands/Grapper/TxOdds/Odds/_Ggng.php +++ b/app/Console/Commands/Grapper/TxOdds/Odds/_Ggng.php @@ -4,8 +4,8 @@ namespace App\Console\Commands\Grapper\TxOdds\Odds; use App\Console\Commands\Nuh; use App\Models\OddsGgng; +use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; -use PDOException; class _Ggng { @@ -29,24 +29,8 @@ class _Ggng $res->flags = 1; $res->margin = $odds['margin']; - $max_tries = 5; - $tries = 0; - do { - $retry = false; - try { + DatabaseFunctions::save_update($res); - $res->save(); - - return $res; - } catch (PDOException $exc) { - if ($tries < $max_tries && $exc->errorInfo[0] == 40001 && $exc->errorInfo[1] == 1213) { - $retry = true; - sleep(1); - } else { - throw $exc; - } - } - } while ($retry); } } } diff --git a/app/Console/Commands/Grapper/TxOdds/Odds/_Points.php b/app/Console/Commands/Grapper/TxOdds/Odds/_Points.php index 1fc85386..d3c1ab6d 100644 --- a/app/Console/Commands/Grapper/TxOdds/Odds/_Points.php +++ b/app/Console/Commands/Grapper/TxOdds/Odds/_Points.php @@ -5,8 +5,8 @@ namespace App\Console\Commands\Grapper\TxOdds\Odds; use App\Console\Commands\Grapper\TxOdds\Odds\Tools\ActiveSpread; use App\Console\Commands\Nuh; use App\Models\OddsPoint; +use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; -use PDOException; class _Points { @@ -40,25 +40,9 @@ class _Points $res->away = $odds['away']; $res->flags = 1; $res->margin = $odds['margin']; - $max_tries = 5; - $tries = 0; - do { - $retry = false; - try { + DatabaseFunctions::save_update($res); - $res->save(); - - return $res; - } catch (PDOException $exc) { - if ($tries < $max_tries && $exc->errorInfo[0] == 40001 && $exc->errorInfo[1] == 1213) { - $retry = true; - sleep(1); - } else { - throw $exc; - } - } - } while ($retry); } ActiveSpread::collect($odds, 'odds_points'); diff --git a/app/Console/Commands/Grapper/TxOdds/Odds/_PointsHt.php b/app/Console/Commands/Grapper/TxOdds/Odds/_PointsHt.php index c66649ec..06719ffe 100644 --- a/app/Console/Commands/Grapper/TxOdds/Odds/_PointsHt.php +++ b/app/Console/Commands/Grapper/TxOdds/Odds/_PointsHt.php @@ -5,8 +5,8 @@ namespace App\Console\Commands\Grapper\TxOdds\Odds; use App\Console\Commands\Grapper\TxOdds\Odds\Tools\ActiveSpread; use App\Console\Commands\Nuh; use App\Models\OddsPointHt; +use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; -use PDOException; class _PointsHt { @@ -41,24 +41,8 @@ class _PointsHt $res->flags = 1; $res->margin = $odds['margin']; - $max_tries = 5; - $tries = 0; - do { - $retry = false; - try { + DatabaseFunctions::save_update($res); - $res->save(); - - return $res; - } catch (PDOException $exc) { - if ($tries < $max_tries && $exc->errorInfo[0] == 40001 && $exc->errorInfo[1] == 1213) { - $retry = true; - sleep(1); - } else { - throw $exc; - } - } - } while ($retry); } ActiveSpread::collect($odds, 'odds_points_ht'); diff --git a/app/Console/Commands/Grapper/TxOdds/Odds/_PointsQ1.php b/app/Console/Commands/Grapper/TxOdds/Odds/_PointsQ1.php index 7b2570f2..3d0e0dde 100644 --- a/app/Console/Commands/Grapper/TxOdds/Odds/_PointsQ1.php +++ b/app/Console/Commands/Grapper/TxOdds/Odds/_PointsQ1.php @@ -5,8 +5,8 @@ namespace App\Console\Commands\Grapper\TxOdds\Odds; use App\Console\Commands\Grapper\TxOdds\Odds\Tools\ActiveSpread; use App\Console\Commands\Nuh; use App\Models\OddsPointQ1; +use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; -use PDOException; class _PointsQ1 { @@ -41,24 +41,8 @@ class _PointsQ1 $res->flags = 1; $res->margin = $odds['margin']; - $max_tries = 5; - $tries = 0; - do { - $retry = false; - try { + DatabaseFunctions::save_update($res); - $res->save(); - - return $res; - } catch (PDOException $exc) { - if ($tries < $max_tries && $exc->errorInfo[0] == 40001 && $exc->errorInfo[1] == 1213) { - $retry = true; - sleep(1); - } else { - throw $exc; - } - } - } while ($retry); } ActiveSpread::collect($odds, 'odds_points_q1'); diff --git a/app/Console/Commands/Grapper/TxOdds/Odds/_Totals.php b/app/Console/Commands/Grapper/TxOdds/Odds/_Totals.php index f66ebb5c..bc0b0f7c 100644 --- a/app/Console/Commands/Grapper/TxOdds/Odds/_Totals.php +++ b/app/Console/Commands/Grapper/TxOdds/Odds/_Totals.php @@ -5,8 +5,8 @@ namespace App\Console\Commands\Grapper\TxOdds\Odds; use App\Console\Commands\Grapper\TxOdds\Odds\Tools\ActiveSpread; use App\Console\Commands\Nuh; use App\Models\OddsTotal; +use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; -use PDOException; class _Totals { @@ -47,24 +47,8 @@ class _Totals $res->flags = 1; $res->margin = $odds['margin']; - $max_tries = 5; - $tries = 0; - do { - $retry = false; - try { + DatabaseFunctions::save_update($res); - $res->save(); - - return $res; - } catch (PDOException $exc) { - if ($tries < $max_tries && $exc->errorInfo[0] == 40001 && $exc->errorInfo[1] == 1213) { - $retry = true; - sleep(1); - } else { - throw $exc; - } - } - } while ($retry); } ActiveSpread::collect($odds, 'odds_totals'); diff --git a/app/Console/Commands/Grapper/TxOdds/Odds/_TotalsHt.php b/app/Console/Commands/Grapper/TxOdds/Odds/_TotalsHt.php index 2d46da6f..bef37073 100644 --- a/app/Console/Commands/Grapper/TxOdds/Odds/_TotalsHt.php +++ b/app/Console/Commands/Grapper/TxOdds/Odds/_TotalsHt.php @@ -5,8 +5,8 @@ namespace App\Console\Commands\Grapper\TxOdds\Odds; use App\Console\Commands\Grapper\TxOdds\Odds\Tools\ActiveSpread; use App\Console\Commands\Nuh; use App\Models\OddsTotalHt; +use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; -use PDOException; class _TotalsHt { @@ -47,24 +47,8 @@ class _TotalsHt $res->flags = 1; $res->margin = $odds['margin']; - $max_tries = 5; - $tries = 0; - do { - $retry = false; - try { + DatabaseFunctions::save_update($res); - $res->save(); - - return $res; - } catch (PDOException $exc) { - if ($tries < $max_tries && $exc->errorInfo[0] == 40001 && $exc->errorInfo[1] == 1213) { - $retry = true; - sleep(1); - } else { - throw $exc; - } - } - } while ($retry); } ActiveSpread::collect($odds, 'odds_totals_ht'); diff --git a/app/Console/Commands/Grapper/TxOdds/Odds/_TotalsQ1.php b/app/Console/Commands/Grapper/TxOdds/Odds/_TotalsQ1.php index 8c185b2c..1469a8d7 100644 --- a/app/Console/Commands/Grapper/TxOdds/Odds/_TotalsQ1.php +++ b/app/Console/Commands/Grapper/TxOdds/Odds/_TotalsQ1.php @@ -5,8 +5,8 @@ namespace App\Console\Commands\Grapper\TxOdds\Odds; use App\Console\Commands\Grapper\TxOdds\Odds\Tools\ActiveSpread; use App\Console\Commands\Nuh; use App\Models\OddsTotalQ1; +use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; -use PDOException; class _TotalsQ1 { @@ -47,24 +47,8 @@ class _TotalsQ1 $res->flags = 1; $res->margin = $odds['margin']; - $max_tries = 5; - $tries = 0; - do { - $retry = false; - try { + DatabaseFunctions::save_update($res); - $res->save(); - - return $res; - } catch (PDOException $exc) { - if ($tries < $max_tries && $exc->errorInfo[0] == 40001 && $exc->errorInfo[1] == 1213) { - $retry = true; - sleep(1); - } else { - throw $exc; - } - } - } while ($retry); } ActiveSpread::collect($odds, 'odds_totals_q1'); diff --git a/app/Console/Commands/Grapper/TxOdds/Odds/_Tq.php b/app/Console/Commands/Grapper/TxOdds/Odds/_Tq.php index 0d4b0c20..45e83a2b 100644 --- a/app/Console/Commands/Grapper/TxOdds/Odds/_Tq.php +++ b/app/Console/Commands/Grapper/TxOdds/Odds/_Tq.php @@ -4,8 +4,8 @@ namespace App\Console\Commands\Grapper\TxOdds\Odds; use App\Console\Commands\Nuh; use App\Models\OddsTq; +use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; -use PDOException; class _Tq { @@ -29,24 +29,8 @@ class _Tq $res->flags = 1; $res->margin = $odds['margin']; - $max_tries = 5; - $tries = 0; - do { - $retry = false; - try { + DatabaseFunctions::save_update($res); - $res->save(); - - return $res; - } catch (PDOException $exc) { - if ($tries < $max_tries && $exc->errorInfo[0] == 40001 && $exc->errorInfo[1] == 1213) { - $retry = true; - sleep(1); - } else { - throw $exc; - } - } - } while ($retry); } } } diff --git a/app/Console/Commands/Services/Tasks/DBConsistencyChecker.php b/app/Console/Commands/Services/Tasks/DBConsistencyChecker.php new file mode 100644 index 00000000..08738da8 --- /dev/null +++ b/app/Console/Commands/Services/Tasks/DBConsistencyChecker.php @@ -0,0 +1,23 @@ +save(); + + return $query; + } catch (PDOException $exc) { + if ($tries < $max_tries && $exc->errorInfo[0] == 40001 && $exc->errorInfo[1] == 1213) { + $retry = true; + sleep(1); + } else { + throw $exc; + } + } + } while ($retry); + } +}