fix crash on large page numbers?

This commit is contained in:
Akinwale Ariwodola 2019-10-15 22:28:45 +01:00
parent 04cbdbcaee
commit c18431394c

View file

@ -136,6 +136,10 @@ class MainController extends AppController {
$count = $stmt->fetch(\PDO::FETCH_OBJ);
$numClaims = $count->Total;
$stmt = $conn->execute('SELECT MAX(id) AS MaxId FROM claim');
$res = $stmt->fetch(\PDO::FETCH_OBJ);
$maxClaimId = $res->MaxId;
$numPages = ceil($numClaims / $pageLimit);
if ($page < 1) {
$page = 1;
@ -144,8 +148,13 @@ class MainController extends AppController {
$page = $numPages;
}
$offset = ($page - 1) * $pageLimit;
$claims = $this->Claims->find()->select($this->Claims)->select(['publisher' => 'C.name'])->leftJoin(['C' => 'claim'], ['C.claim_id = Claims.publisher_id'])->order(['Claims.created_at' => 'DESC'])->offset($offset)->limit($pageLimit)->toArray();
$startLimitId = $maxClaimId - ($page * $pageLimit);
$endLimitId = $startLimitId + $pageLimit;
$claims = $this->Claims->find()->select($this->Claims)->
select(['publisher' => 'C.name'])->leftJoin(['C' => 'claim'], ['C.claim_id = Claims.publisher_id'])->
where(['Claims.id >' => $startLimitId, 'Claims.id <=' => $endLimitId])
order(['Claims.id' => 'DESC'])->toArray();
for ($i = 0; $i < count($claims); $i++) {
if ($canConvert && $claims[$i]->fee > 0 && $claims[$i]->fee_currency == 'USD') {