X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FBaseRepository.php;h=1294be88ca053d94d7270c0057a062f5bf7355fe;hb=15caf4b3f7eacda399a56b1ad8eeb9d3257306d9;hp=abec4c119b3f21c834cc73ba34017184ded8f94f;hpb=879c30d4facb040d8579b9e378fbdd3ea14b8d88;p=friendica.git diff --git a/src/BaseRepository.php b/src/BaseRepository.php index abec4c119b..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 = DBA::mergeConditions($boundCondition, ['`id` > ?', $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); + if ($reverseModels) { + $models = array_reverse($models); + } + return new static::$collection_class($models, $totalCount); } @@ -217,6 +236,8 @@ abstract class BaseRepository extends BaseFactory } } + $this->dba->close($result); + return $models; }