Explanation
You can replace the following code
foreach ($order as $o):
$loluser = $o->loluser;
$region = $o->region;
$date_created = $o->date_created;
$date_completed = $o->date_completed;
endforeach;
from
$order = end($orders);
$loluser = ($order === false) ? '' : $order->loluser;
$region = ($order === false) ? '' : $order->region;
$date_created = ($order === false) ? '' : $order->date_created;
$date_completed = ($order === false) ? '' : $order->date_completed;
. -, foreach
. . -, , script.
, , . , .
.
$new_array = array_diff($gameIds, $dbMatches);
foreach ($new_array as $matchId):
$games[] = $matchapi->match($matchId, false);
endforeach;
foreach (array_diff($gameIds, $dbMatches) as $matchId):
$games[] = $matchapi->match($matchId, false);
endforeach;
script :
<?php
if (isset($_POST['refresh-history'])) {
$order_id = $_POST['id'];
$orders = $database->get_results('SELECT * FROM `orders` WHERE `order_id` = '.$order_id);
$matches = $database->get_results('SELECT `match_id` FROM `matches` WHERE `order_id` = '.$order_id);
$order = end($orders);
$loluser = ($order === false) ? '' : $order->loluser;
$region = ($order === false) ? '' : $order->region;
$date_created = ($order === false) ? '' : $order->date_created;
$date_completed = ($order === false) ? '' : $order->date_completed;
$api->setRegion($region);
$matchlistapi = $api->matchlist();
$matchapi = $api->match();
$matchlist = $matchlistapi->matchlist($loluser, "RANKED_SOLO_5x5", "SEASON2015", null, null, null, $date_created, $date_completed);
if ($matchlist->totalGames > 0) {
$matchIds = array();
$matchIdsDB = array();
foreach ($matchlist as $match) {
$matchIds[] = (int) $match->matchId;
}
foreach (object2array($matches) as $match) {
$matchIdsDB[] = (int) $match->match_id;
}
foreach (array_diff($matchIds, $matchIdsDB) as $match) {
$game = $matchapi->match($match, false);
}
$_SESSION['api_success'] = "Success: Games Synced to Order.";
} else {
$_SESSION['error_msg'] = "Error 23: Unable to Find Games.";
}
}
, !