diff --git a/app/Console/Commands/Grapper/Betsapi/Bet365.php b/app/Console/Commands/Grapper/Betsapi/Bet365.php index 038e2765..bbd1194f 100644 --- a/app/Console/Commands/Grapper/Betsapi/Bet365.php +++ b/app/Console/Commands/Grapper/Betsapi/Bet365.php @@ -13,7 +13,6 @@ 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; @@ -74,11 +73,13 @@ class Bet365 if (isset($data['results'][0]['main'])) { - EventBookmaker::updateOrCreate([ - 'event_id' => $event->id, - 'sport_id' => $event->sport_id, - 'bookmaker_id' => $bookmaker_id, - ], ['starttime' => $event->starttime, 'in_feed' => 1, 'bmoid' => $event->bet365_id]); + DB::transaction(function () use ($event) { + EventBookmaker::updateOrCreate([ + 'event_id' => $event->id, + 'sport_id' => $event->sport_id, + 'bookmaker_id' => $bookmaker_id, + ], ['starttime' => $event->starttime, 'in_feed' => 1, 'bmoid' => $event->bet365_id]); + }, 5); $offer = $data['results'][0]['main']['sp']; @@ -119,9 +120,9 @@ class Bet365 $res->d3w = $odds['a3w']; $res->flags = 1; $res->margin = $odds['margin']; - - DatabaseFunctions::save_update($res); - + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } } } @@ -155,8 +156,9 @@ class Bet365 $res->dcx2 = $odds['dcx2']; $res->flags = 1; $res->margin = $odds['margin']; - - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } } @@ -198,8 +200,9 @@ class Bet365 $res->difference = abs(1 / $odds['over'] - 1 / $odds['under']); $res->flags = 1; $res->margin = $odds['margin']; - - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } } @@ -233,9 +236,9 @@ class Bet365 $res->ng = $odds['ng']; $res->flags = 1; $res->margin = $odds['margin']; - - DatabaseFunctions::save_update($res); - + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } } } @@ -267,8 +270,9 @@ class Bet365 $res->dnb2 = $odds['dnb2']; $res->flags = 1; $res->margin = $odds['margin']; - - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } } @@ -303,8 +307,9 @@ class Bet365 $res->a3w = $odds['a3w']; $res->flags = 1; $res->margin = $odds['margin']; - - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } } diff --git a/app/Console/Commands/Grapper/Betsapi/Odds.php b/app/Console/Commands/Grapper/Betsapi/Odds.php index 367aed45..c75c81e8 100644 --- a/app/Console/Commands/Grapper/Betsapi/Odds.php +++ b/app/Console/Commands/Grapper/Betsapi/Odds.php @@ -7,7 +7,6 @@ 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; @@ -99,8 +98,9 @@ class Odds $res->a3w = $odds['a3w']; $res->flags = 1; $res->margin = $odds['margin']; - - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } break; @@ -126,8 +126,9 @@ class Odds $res->a3w = $odds['a3w']; $res->flags = 1; $res->margin = $odds['margin']; - - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } break; diff --git a/app/Console/Commands/Grapper/Fixtures/FindFixture.php b/app/Console/Commands/Grapper/Fixtures/FindFixture.php index 87907320..dea5a9b7 100644 --- a/app/Console/Commands/Grapper/Fixtures/FindFixture.php +++ b/app/Console/Commands/Grapper/Fixtures/FindFixture.php @@ -101,7 +101,9 @@ class FindFixture } if ($update_array) { - Event::where('id', $match->id)->update($update_array); + DB::transaction(function () use ($match) { + Event::where('id', $match->id)->update($update_array); + }, 5); } if (! in_array(Nuh::$options['provider_id'], [5, 6, 9])) { @@ -149,6 +151,8 @@ class FindFixture if ($match_id) { + $event['id'] = $match_id; + $update_array = []; if ($betradar_id) { diff --git a/app/Console/Commands/Grapper/Logifuture.php b/app/Console/Commands/Grapper/Logifuture.php index edc36ca5..035d0258 100644 --- a/app/Console/Commands/Grapper/Logifuture.php +++ b/app/Console/Commands/Grapper/Logifuture.php @@ -15,7 +15,6 @@ use App\Models\EventBookmaker; use App\Models\Sport; use App\Utilities\Notice; use Illuminate\Support\Facades\DB; -use PDOException; class Logifuture { @@ -26,6 +25,7 @@ class Logifuture public static function switch() { $debug = Nuh::$options['d'] ?? 0; + $echo_data = Nuh::$options['e'] ?? 0; $sportmap = Sport::map('logi', 1, [Nuh::$options['sport_id']]); @@ -42,6 +42,8 @@ class Logifuture $matches = LogifutureData::load($logifuture_sport_id); + // Notice::note($matches, 'b'); + if ($echo_data) { Notice::note($matches, 'g'); } @@ -54,38 +56,27 @@ class Logifuture foreach ($matches as $match) { + // Notice::note($match, 'r'); + if (strpos($match['sportCategory'], 'Simulated Reality') === false) { $event = MapEvent::filter($sport_id, $match); FindFixture::find($event); + Notice::note($event, 'r'); + if (isset($event['id'])) { + Notice::note($event, 'b'); + $event_id_collector[] = $event['id']; - $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); + EventBookmaker::updateOrCreate([ + 'event_id' => $event['id'], + 'sport_id' => $sport_id, + 'bookmaker_id' => Nuh::$options['bookmaker_id'], + ], ['in_feed' => 1, 'bmoid' => $event['id'], 'startime' => $event['starttime']]); switch ($sport_id) { case 1: @@ -106,31 +97,12 @@ class Logifuture break; } } - } } - } } if ($event_id_collector) { - $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); + EventBookmaker::whereNotIn('event_id', $event_id_collector)->where('bookmaker_id', Nuh::$options['bookmaker_id'])->update(['in_feed' => 0]); $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/Icehockey.php b/app/Console/Commands/Grapper/Logifuture/Icehockey.php index bb116ce0..d633e070 100644 --- a/app/Console/Commands/Grapper/Logifuture/Icehockey.php +++ b/app/Console/Commands/Grapper/Logifuture/Icehockey.php @@ -101,7 +101,9 @@ class Icehockey $res->a3w = number_format($_3way['a3w'], 2); $res->flags = 1; $res->margin = $_3way['margin']; - $res->save(); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } } @@ -121,7 +123,9 @@ class Icehockey $res->a2w = number_format($ml['a2w'], 2); $res->flags = 1; $res->margin = $ml['margin']; - $res->save(); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } } @@ -140,7 +144,9 @@ class Icehockey $res->a2w = number_format($ml['a2w'], 2); $res->flags = 1; $res->margin = $mls1['margin']; - $res->save(); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } } diff --git a/app/Console/Commands/Grapper/Logifuture/Soccer.php b/app/Console/Commands/Grapper/Logifuture/Soccer.php index 1b980c07..9f6fbd9b 100644 --- a/app/Console/Commands/Grapper/Logifuture/Soccer.php +++ b/app/Console/Commands/Grapper/Logifuture/Soccer.php @@ -8,7 +8,6 @@ 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 @@ -94,8 +93,9 @@ class Soccer $res->a3w = number_format($_3way['a3w'], 2); $res->flags = 1; $res->margin = $_3way['margin']; - - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } } @@ -120,8 +120,9 @@ class Soccer $res->under = number_format($_total['under'], 2); $res->flags = 1; $res->margin = $_total['margin']; - - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } } @@ -141,8 +142,9 @@ class Soccer $res->ng = number_format($_ggng['ng'], 2); $res->flags = 1; $res->margin = $_ggng['margin']; - - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } } @@ -163,8 +165,9 @@ class Soccer $res->dcx2 = number_format($_dc['dcx2'], 2); $res->flags = 1; $res->margin = $_dc['margin']; - - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } } @@ -184,8 +187,9 @@ class Soccer $res->atq = number_format($_tq['atq'], 2); $res->flags = 1; $res->margin = $_tq['margin']; - - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } } diff --git a/app/Console/Commands/Grapper/Logifuture/Tennis.php b/app/Console/Commands/Grapper/Logifuture/Tennis.php index 80cce7d3..4d0581f1 100644 --- a/app/Console/Commands/Grapper/Logifuture/Tennis.php +++ b/app/Console/Commands/Grapper/Logifuture/Tennis.php @@ -8,8 +8,8 @@ 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; +use App\Utilities\Notice; class Tennis { @@ -76,6 +76,8 @@ class Tennis $ml = array_merge($ml, $base); + // Notice::note($ml, 'g'); + $res = Odds2way::where('event_id', $event['id'])->where('bookmaker_id', $event['bookmaker_id'])->first(); if (! $res) { @@ -85,8 +87,9 @@ class Tennis $res->a2w = number_format($ml['a2w'], 2); $res->flags = 1; $res->margin = $ml['margin']; - - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } } @@ -106,8 +109,9 @@ class Tennis $res->a2w = number_format($ml['a2w'], 2); $res->flags = 1; $res->margin = $mls1['margin']; - - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } } diff --git a/app/Console/Commands/Grapper/Logifuture/Tools/LogifutureStorePoints.php b/app/Console/Commands/Grapper/Logifuture/Tools/LogifutureStorePoints.php index 10a5ace2..36422b1f 100644 --- a/app/Console/Commands/Grapper/Logifuture/Tools/LogifutureStorePoints.php +++ b/app/Console/Commands/Grapper/Logifuture/Tools/LogifutureStorePoints.php @@ -3,7 +3,6 @@ namespace App\Console\Commands\Grapper\Logifuture\Tools; use App\Models\OddsPoint; -use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; class LogifutureStorePoints @@ -40,8 +39,9 @@ class LogifutureStorePoints $res->difference = $odds['difference']; $res->flags = 1; $res->margin = $odds['margin']; - - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } } diff --git a/app/Console/Commands/Grapper/Logifuture/Tools/LogifutureStorePointsQ1.php b/app/Console/Commands/Grapper/Logifuture/Tools/LogifutureStorePointsQ1.php index bd64b600..dc5308b5 100644 --- a/app/Console/Commands/Grapper/Logifuture/Tools/LogifutureStorePointsQ1.php +++ b/app/Console/Commands/Grapper/Logifuture/Tools/LogifutureStorePointsQ1.php @@ -3,7 +3,6 @@ namespace App\Console\Commands\Grapper\Logifuture\Tools; use App\Models\OddsPointQ1; -use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; class LogifutureStorePointsQ1 @@ -40,8 +39,9 @@ class LogifutureStorePointsQ1 $res->difference = $odds['difference']; $res->flags = 1; $res->margin = $odds['margin']; - - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } } diff --git a/app/Console/Commands/Grapper/Logifuture/Tools/LogifutureStoreTotals.php b/app/Console/Commands/Grapper/Logifuture/Tools/LogifutureStoreTotals.php index d694a5d5..d985aba9 100644 --- a/app/Console/Commands/Grapper/Logifuture/Tools/LogifutureStoreTotals.php +++ b/app/Console/Commands/Grapper/Logifuture/Tools/LogifutureStoreTotals.php @@ -3,7 +3,6 @@ namespace App\Console\Commands\Grapper\Logifuture\Tools; use App\Models\OddsTotal; -use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; class LogifutureStoreTotals @@ -40,8 +39,9 @@ class LogifutureStoreTotals $res->difference = $odds['difference']; $res->flags = 1; $res->margin = $odds['margin']; - - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } } diff --git a/app/Console/Commands/Grapper/Logifuture/Tools/LogifutureStoreTotalsQ1.php b/app/Console/Commands/Grapper/Logifuture/Tools/LogifutureStoreTotalsQ1.php index 1b57e341..fb093fb7 100644 --- a/app/Console/Commands/Grapper/Logifuture/Tools/LogifutureStoreTotalsQ1.php +++ b/app/Console/Commands/Grapper/Logifuture/Tools/LogifutureStoreTotalsQ1.php @@ -3,7 +3,6 @@ namespace App\Console\Commands\Grapper\Logifuture\Tools; use App\Models\OddsTotalQ1; -use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; class LogifutureStoreTotalsQ1 @@ -40,8 +39,9 @@ class LogifutureStoreTotalsQ1 $res->difference = $odds['difference']; $res->flags = 1; $res->margin = $odds['margin']; - - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } } diff --git a/app/Console/Commands/Grapper/Magloo/Fixtures.php b/app/Console/Commands/Grapper/Magloo/Fixtures.php index 6c68fc9f..dca77d72 100644 --- a/app/Console/Commands/Grapper/Magloo/Fixtures.php +++ b/app/Console/Commands/Grapper/Magloo/Fixtures.php @@ -9,7 +9,6 @@ use App\Models\EventBookmaker; use App\Models\Sport; use App\Utilities\Notice; use Illuminate\Support\Carbon; -use PDOException; class Fixtures { @@ -101,33 +100,12 @@ class Fixtures FindFixture::find($event); - if (isset($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']]); - $event_id_collector[] = $event['id']; - - $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 e0d95929..2894b42d 100644 --- a/app/Console/Commands/Grapper/Magloo/Odds/MaglooStore1x2.php +++ b/app/Console/Commands/Grapper/Magloo/Odds/MaglooStore1x2.php @@ -3,8 +3,8 @@ namespace App\Console\Commands\Grapper\Magloo\Odds; use App\Models\Odds3way; -use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; +use Illuminate\Support\Facades\DB; class MaglooStore1x2 { @@ -27,8 +27,9 @@ class MaglooStore1x2 $res->a3w = $odds['a3w']; $res->flags = 1; $res->margin = $odds['margin']; - - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } } diff --git a/app/Console/Commands/Grapper/Magloo/Odds/MaglooStoreDc.php b/app/Console/Commands/Grapper/Magloo/Odds/MaglooStoreDc.php index 10f24156..cd0b4053 100644 --- a/app/Console/Commands/Grapper/Magloo/Odds/MaglooStoreDc.php +++ b/app/Console/Commands/Grapper/Magloo/Odds/MaglooStoreDc.php @@ -3,8 +3,8 @@ namespace App\Console\Commands\Grapper\Magloo\Odds; use App\Models\OddsDc; -use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; +use Illuminate\Support\Facades\DB; class MaglooStoreDc { @@ -28,8 +28,9 @@ class MaglooStoreDc $res->dcx2 = $odds['dcx2']; $res->flags = 1; $res->margin = $odds['margin']; - - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } diff --git a/app/Console/Commands/Grapper/Magloo/Odds/MaglooStoreGgng.php b/app/Console/Commands/Grapper/Magloo/Odds/MaglooStoreGgng.php index 81cb1ea3..2953018c 100644 --- a/app/Console/Commands/Grapper/Magloo/Odds/MaglooStoreGgng.php +++ b/app/Console/Commands/Grapper/Magloo/Odds/MaglooStoreGgng.php @@ -3,8 +3,8 @@ namespace App\Console\Commands\Grapper\Magloo\Odds; use App\Models\OddsGgng; -use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; +use Illuminate\Support\Facades\DB; class MaglooStoreGgng { @@ -26,8 +26,9 @@ class MaglooStoreGgng $res->ng = $odds['ng']; $res->flags = 1; $res->margin = $odds['margin']; - - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } } diff --git a/app/Console/Commands/Grapper/Magloo/Odds/MaglooStorePoints.php b/app/Console/Commands/Grapper/Magloo/Odds/MaglooStorePoints.php index eb2d00a6..582fa0e7 100644 --- a/app/Console/Commands/Grapper/Magloo/Odds/MaglooStorePoints.php +++ b/app/Console/Commands/Grapper/Magloo/Odds/MaglooStorePoints.php @@ -3,8 +3,8 @@ namespace App\Console\Commands\Grapper\Magloo\Odds; use App\Models\OddsPoint; -use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; +use Illuminate\Support\Facades\DB; class MaglooStorePoints { @@ -37,8 +37,9 @@ class MaglooStorePoints $res->active_spread = $odds['active_spread']; $res->difference = $odds['difference']; $res->margin = $odds['margin']; - - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } } diff --git a/app/Console/Commands/Grapper/Magloo/Odds/MaglooStorePointsQ1.php b/app/Console/Commands/Grapper/Magloo/Odds/MaglooStorePointsQ1.php index e88aae4a..953ae301 100644 --- a/app/Console/Commands/Grapper/Magloo/Odds/MaglooStorePointsQ1.php +++ b/app/Console/Commands/Grapper/Magloo/Odds/MaglooStorePointsQ1.php @@ -3,8 +3,8 @@ namespace App\Console\Commands\Grapper\Magloo\Odds; use App\Models\OddsPointQ1; -use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; +use Illuminate\Support\Facades\DB; class MaglooStorePointsQ1 { @@ -37,8 +37,9 @@ class MaglooStorePointsQ1 $res->active_spread = $odds['active_spread']; $res->difference = $odds['difference']; $res->margin = $odds['margin']; - - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } } diff --git a/app/Console/Commands/Grapper/Magloo/Odds/MaglooStoreTotals.php b/app/Console/Commands/Grapper/Magloo/Odds/MaglooStoreTotals.php index b908ab8c..848cea39 100644 --- a/app/Console/Commands/Grapper/Magloo/Odds/MaglooStoreTotals.php +++ b/app/Console/Commands/Grapper/Magloo/Odds/MaglooStoreTotals.php @@ -3,8 +3,8 @@ namespace App\Console\Commands\Grapper\Magloo\Odds; use App\Models\OddsTotal; -use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; +use Illuminate\Support\Facades\DB; class MaglooStoreTotals { @@ -37,8 +37,9 @@ class MaglooStoreTotals $res->active_spread = $odds['active_spread']; $res->difference = $odds['difference']; $res->margin = $odds['margin']; - - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } } diff --git a/app/Console/Commands/Grapper/Magloo/Odds/MaglooStoreTotalsQ1.php b/app/Console/Commands/Grapper/Magloo/Odds/MaglooStoreTotalsQ1.php index 2aca21c3..478fa3f7 100644 --- a/app/Console/Commands/Grapper/Magloo/Odds/MaglooStoreTotalsQ1.php +++ b/app/Console/Commands/Grapper/Magloo/Odds/MaglooStoreTotalsQ1.php @@ -3,8 +3,8 @@ namespace App\Console\Commands\Grapper\Magloo\Odds; use App\Models\OddsTotalQ1; -use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; +use Illuminate\Support\Facades\DB; class MaglooStoreTotalsQ1 { @@ -37,8 +37,9 @@ class MaglooStoreTotalsQ1 $res->active_spread = $odds['active_spread']; $res->difference = $odds['difference']; $res->margin = $odds['margin']; - - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } } diff --git a/app/Console/Commands/Grapper/Magloo/Odds/MaglooStoreTq.php b/app/Console/Commands/Grapper/Magloo/Odds/MaglooStoreTq.php index b7754a3b..adedd671 100644 --- a/app/Console/Commands/Grapper/Magloo/Odds/MaglooStoreTq.php +++ b/app/Console/Commands/Grapper/Magloo/Odds/MaglooStoreTq.php @@ -3,8 +3,8 @@ namespace App\Console\Commands\Grapper\Magloo\Odds; use App\Models\OddsTq; -use App\Utilities\DatabaseFunctions; use App\Utilities\Margin; +use Illuminate\Support\Facades\DB; class MaglooStoreTq { @@ -26,8 +26,9 @@ class MaglooStoreTq $res->htq = $odds['htq']; $res->atq = $odds['atq']; $res->margin = $odds['margin']; - - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } } diff --git a/app/Console/Commands/Grapper/TxOdds/Odds.php b/app/Console/Commands/Grapper/TxOdds/Odds.php index 1c21ff6b..c9a80f9c 100644 --- a/app/Console/Commands/Grapper/TxOdds/Odds.php +++ b/app/Console/Commands/Grapper/TxOdds/Odds.php @@ -27,9 +27,9 @@ 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; +use Illuminate\Support\Facades\DB; class Odds { @@ -238,10 +238,10 @@ class Odds 'competition_group_id' => (int) $row->group['cgid'], ]; - $res = Event::updateOrCreate(['id' => (int) $row['id']], $event); - if ($res) { - $event_id = $res->id; - } + $res = DB::transaction(function () use ($row, $event) { + return Event::updateOrCreate(['id' => (int) $row['id']], $event); + }, 5); + $event_id = $res->id; $group = [ 'competition_group_id' => (string) $row->group['cgid'], @@ -326,7 +326,10 @@ class Odds $res = EventBookmaker::where('event_id', $event_id)->where('bookmaker_id', $bookmaker_id)->first(); if ($res && $res->starttime != $attributeValue) { $res->starttime = $attributeValue; - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); + } break; } @@ -342,13 +345,16 @@ class Odds $res = EventBookmaker::where('event_id', $event_id)->where('bookmaker_id', $bookmaker_id)->first(); if ($res && $res->starttime != $attributeValue) { $res->starttime = $attributeValue; - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } break; } } _2Way::grap($odds, $offer); + break; case 3: foreach ($offer->odds->attributes() as $attributeName => $attributeValue) { @@ -358,7 +364,9 @@ class Odds $res = EventBookmaker::where('event_id', $event_id)->where('bookmaker_id', $bookmaker_id)->first(); if ($res && $res->starttime != $attributeValue) { $res->starttime = $attributeValue; - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } break; } diff --git a/app/Console/Commands/Grapper/TxOdds/Odds/Tools/ActiveSpread.php b/app/Console/Commands/Grapper/TxOdds/Odds/Tools/ActiveSpread.php index 8bddade3..577beb0e 100644 --- a/app/Console/Commands/Grapper/TxOdds/Odds/Tools/ActiveSpread.php +++ b/app/Console/Commands/Grapper/TxOdds/Odds/Tools/ActiveSpread.php @@ -3,7 +3,6 @@ namespace App\Console\Commands\Grapper\TxOdds\Odds\Tools; use Illuminate\Support\Facades\DB; -use PDOException; class ActiveSpread { @@ -41,49 +40,17 @@ class ActiveSpread DB::table($table)->where('event_id', $event_id)->where('bookmaker_id', $bookmaker_id)->update(['active_spread' => 0]); if (in_array($table, ['odds_points', 'odds_points_ht', 'odds_points_q1'])) { - $max_tries = 5; - $tries = 0; - do { - $retry = false; - try { - $query = DB::table($table) - ->where('event_id', $event_id) - ->where('bookmaker_id', $bookmaker_id) - ->where('handicap', (float) $value['active_spread']) - ->update(['active_spread' => 1]); - - 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); + DB::table($table) + ->where('event_id', $event_id) + ->where('bookmaker_id', $bookmaker_id) + ->where('handicap', (float) $value['active_spread']) + ->update(['active_spread' => 1]); } else { - $max_tries = 5; - $tries = 0; - do { - $retry = false; - try { - $query = DB::table($table) - ->where('event_id', $event_id) - ->where('bookmaker_id', $bookmaker_id) - ->where('total', (float) $value['active_spread']) - ->update(['active_spread' => 1]); - - 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); + DB::table($table) + ->where('event_id', $event_id) + ->where('bookmaker_id', $bookmaker_id) + ->where('total', (float) $value['active_spread']) + ->update(['active_spread' => 1]); } } } diff --git a/app/Console/Commands/Grapper/TxOdds/Odds/_2Way.php b/app/Console/Commands/Grapper/TxOdds/Odds/_2Way.php index 4878594a..752a4223 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 Illuminate\Support\Facades\DB; class _2Way { @@ -29,8 +29,9 @@ class _2Way $res->flags = 1; $res->margin = $odds['margin']; - DatabaseFunctions::save_update($res); - + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } } } diff --git a/app/Console/Commands/Grapper/TxOdds/Odds/_2WayS1.php b/app/Console/Commands/Grapper/TxOdds/Odds/_2WayS1.php index facc92bb..1ebc8938 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 Illuminate\Support\Facades\DB; class _2WayS1 { @@ -28,8 +28,9 @@ class _2WayS1 $res->a2w = $odds['a2w']; $res->flags = 1; $res->margin = $odds['margin']; - - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } } diff --git a/app/Console/Commands/Grapper/TxOdds/Odds/_3Way.php b/app/Console/Commands/Grapper/TxOdds/Odds/_3Way.php index 75511a10..c8d8fc8b 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 Illuminate\Support\Facades\DB; class _3Way { @@ -31,8 +31,9 @@ class _3Way $res->a3w = $odds['a3w']; $res->flags = 1; $res->margin = $odds['margin']; - - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } } } diff --git a/app/Console/Commands/Grapper/TxOdds/Odds/_3WayHt.php b/app/Console/Commands/Grapper/TxOdds/Odds/_3WayHt.php index 46a1d34d..a66c7d30 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 Illuminate\Support\Facades\DB; class _3WayHt { @@ -30,8 +30,9 @@ class _3WayHt $res->a3w = $odds['a3w']; $res->flags = 1; $res->margin = $odds['margin']; - - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } } diff --git a/app/Console/Commands/Grapper/TxOdds/Odds/_Dc.php b/app/Console/Commands/Grapper/TxOdds/Odds/_Dc.php index 407bacf6..12667160 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 Illuminate\Support\Facades\DB; class _Dc { @@ -30,8 +30,9 @@ class _Dc $res->dcx2 = $odds['dcx2']; $res->flags = 1; $res->margin = $odds['margin']; - - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } } diff --git a/app/Console/Commands/Grapper/TxOdds/Odds/_Dnb.php b/app/Console/Commands/Grapper/TxOdds/Odds/_Dnb.php index d30787b0..cb0d6caf 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 Illuminate\Support\Facades\DB; class _Dnb { @@ -28,8 +28,9 @@ class _Dnb $res->dnb2 = $odds['dnb2']; $res->flags = 1; $res->margin = $odds['margin']; - - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } } diff --git a/app/Console/Commands/Grapper/TxOdds/Odds/_Ggng.php b/app/Console/Commands/Grapper/TxOdds/Odds/_Ggng.php index b73e8e27..a44f9e69 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 Illuminate\Support\Facades\DB; class _Ggng { @@ -28,8 +28,9 @@ class _Ggng $res->ng = $odds['ng']; $res->flags = 1; $res->margin = $odds['margin']; - - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } } diff --git a/app/Console/Commands/Grapper/TxOdds/Odds/_Points.php b/app/Console/Commands/Grapper/TxOdds/Odds/_Points.php index d3c1ab6d..f08905bd 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 Illuminate\Support\Facades\DB; class _Points { @@ -40,8 +40,9 @@ class _Points $res->away = $odds['away']; $res->flags = 1; $res->margin = $odds['margin']; - - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } diff --git a/app/Console/Commands/Grapper/TxOdds/Odds/_PointsHt.php b/app/Console/Commands/Grapper/TxOdds/Odds/_PointsHt.php index 06719ffe..da8a5e10 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 Illuminate\Support\Facades\DB; class _PointsHt { @@ -40,8 +40,9 @@ class _PointsHt $res->away = $odds['away']; $res->flags = 1; $res->margin = $odds['margin']; - - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } diff --git a/app/Console/Commands/Grapper/TxOdds/Odds/_PointsQ1.php b/app/Console/Commands/Grapper/TxOdds/Odds/_PointsQ1.php index 3d0e0dde..e59ddb4b 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 Illuminate\Support\Facades\DB; class _PointsQ1 { @@ -40,8 +40,9 @@ class _PointsQ1 $res->away = $odds['away']; $res->flags = 1; $res->margin = $odds['margin']; - - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } diff --git a/app/Console/Commands/Grapper/TxOdds/Odds/_Totals.php b/app/Console/Commands/Grapper/TxOdds/Odds/_Totals.php index bc0b0f7c..a8e9cd05 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 Illuminate\Support\Facades\DB; class _Totals { @@ -46,8 +46,9 @@ class _Totals $res->under = $odds['under']; $res->flags = 1; $res->margin = $odds['margin']; - - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } diff --git a/app/Console/Commands/Grapper/TxOdds/Odds/_TotalsHt.php b/app/Console/Commands/Grapper/TxOdds/Odds/_TotalsHt.php index bef37073..7743989b 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 Illuminate\Support\Facades\DB; class _TotalsHt { @@ -46,8 +46,9 @@ class _TotalsHt $res->under = $odds['under']; $res->flags = 1; $res->margin = $odds['margin']; - - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } diff --git a/app/Console/Commands/Grapper/TxOdds/Odds/_TotalsQ1.php b/app/Console/Commands/Grapper/TxOdds/Odds/_TotalsQ1.php index 1469a8d7..1f7236a4 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 Illuminate\Support\Facades\DB; class _TotalsQ1 { @@ -46,8 +46,9 @@ class _TotalsQ1 $res->under = $odds['under']; $res->flags = 1; $res->margin = $odds['margin']; - - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } diff --git a/app/Console/Commands/Grapper/TxOdds/Odds/_Tq.php b/app/Console/Commands/Grapper/TxOdds/Odds/_Tq.php index 45e83a2b..2adfad6b 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 Illuminate\Support\Facades\DB; class _Tq { @@ -28,8 +28,9 @@ class _Tq $res->atq = $odds['atq']; $res->flags = 1; $res->margin = $odds['margin']; - - DatabaseFunctions::save_update($res); + DB::transaction(function () use ($res) { + $res->save(); + }, 5); } } diff --git a/app/Console/Commands/Services/Tasks/Alarm/AlarmStore.php b/app/Console/Commands/Services/Tasks/Alarm/AlarmStore.php index faa5bd79..f02f58e6 100644 --- a/app/Console/Commands/Services/Tasks/Alarm/AlarmStore.php +++ b/app/Console/Commands/Services/Tasks/Alarm/AlarmStore.php @@ -3,7 +3,6 @@ namespace App\Console\Commands\Services\Tasks\Alarm; use App\Models\EventBookmaker; -use PDOException; class AlarmStore { @@ -43,23 +42,6 @@ class AlarmStore } } - $max_tries = 5; - $tries = 0; - do { - $retry = false; - try { - - $res = EventBookmaker::where('event_id', $event_id)->where('bookmaker_id', $client_bookmaker_id)->update($update_array); - - 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); + EventBookmaker::where('event_id', $event_id)->where('bookmaker_id', $client_bookmaker_id)->update($update_array); } } diff --git a/app/Utilities/DatabaseFunctions.php b/app/Utilities/DatabaseFunctions.php index bdd84096..71464c9d 100644 --- a/app/Utilities/DatabaseFunctions.php +++ b/app/Utilities/DatabaseFunctions.php @@ -2,8 +2,6 @@ namespace App\Utilities; -use PDOException; - class DatabaseFunctions { public static function save_update($query) @@ -12,12 +10,13 @@ class DatabaseFunctions $tries = 0; do { $retry = false; + $tries++; try { $query->save(); return $query; - } catch (PDOException $exc) { + } catch (\PDOException $exc) { if ($tries < $max_tries && $exc->errorInfo[0] == 40001 && $exc->errorInfo[1] == 1213) { $retry = true; sleep(1);