Fixed Api get threads with filter last_days

Affected version
2.1.1

djgxp

New member
By default, last_days is defined in Xenforo and if you are not adding any filter parameter to /api/threads/ you are getting something like last_post_date > 11111111 (where 11111111 here is the timestamp of the current date minus 1 month).

if I set /api/threads/?last_days=0 in order to get all topics from any date, I have a bug because the last_days is not in filters and there is a type conversion that have failed.

So here is the fix on line 37 of src/XF/Api/ControllerPlugin/Threads.php (currently we have $lastDays['last_days']):

PHP:
        $lastDays = $this->filter('last_days', '?uint');
        if (is_int($lastDays))
        {
            if ($lastDays)
            {
                $threadFinder->where('last_post_date', '>=', \XF::$time - ($lastDays * 86400));
            }
            // 0 means no limit here -- bypass the forum default limit if there is one

            $filters['last_days'] = $lastDays;
        }
 

XF Bug Bot

XenForo bug fixer bot
Staff member
Thank you for reporting this issue. It has now been resolved and we are aiming to include it in a future XF release (2.1.2).

Change log:
Fixed variable typo in REST API thread filtering code.
Any changes made as a result of this issue being resolved may not be rolled out here until later.
 
Top