X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FBaseRepository.php;h=1294be88ca053d94d7270c0057a062f5bf7355fe;hb=12367648fae2aebd981b9cde83599a34682221be;hp=64a0d1c510626e995cb4c213f9565271fa6af062;hpb=e80d68ba53776bed047d897f52db7e25b35a479d;p=friendica.git diff --git a/src/BaseRepository.php b/src/BaseRepository.php index 64a0d1c510..1294be88ca 100644 --- a/src/BaseRepository.php +++ b/src/BaseRepository.php @@ -1,6 +1,6 @@ ?', $min_id]); + if (!isset($max_id) && isset($params['order']['id']) && ($params['order']['id'] === true || $params['order']['id'] === 'DESC')) { + $reverseModels = true; + $params['order']['id'] = 'ASC'; + } } - if (isset($since_id)) { - $boundCondition[0] .= " AND `id` > ?"; - $boundCondition[] = $since_id; + if (isset($max_id)) { + $boundCondition = DBA::mergeConditions($boundCondition, ['`id` < ?', $max_id]); + if (!isset($min_id) && (!isset($params['order']['id']) || $params['order']['id'] === false || $params['order']['id'] === 'ASC')) { + $reverseModels = true; + $params['order']['id'] = 'DESC'; + } } $params['limit'] = $limit; $models = $this->selectModels($boundCondition, $params); - $totalCount = DBA::count(static::$table_name, $condition); + if ($reverseModels) { + $models = array_reverse($models); + } return new static::$collection_class($models, $totalCount); } @@ -221,6 +236,8 @@ abstract class BaseRepository extends BaseFactory } } + $this->dba->close($result); + return $models; }