mirror of
https://github.com/flarum/framework.git
synced 2025-04-24 21:54:04 +08:00
Fix/clean up created gambit
$matches indices were incorrect.
This commit is contained in:
parent
4ec108f28a
commit
ba7fba9015
@ -18,8 +18,6 @@ use LogicException;
|
||||
class CreatedGambit extends AbstractRegexGambit
|
||||
{
|
||||
/**
|
||||
* http://stackoverflow.com/a/8270148/3158312
|
||||
*
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $pattern = 'created:(\d{4}\-\d\d\-\d\d)(\.\.(\d{4}\-\d\d\-\d\d))?';
|
||||
@ -33,10 +31,14 @@ class CreatedGambit extends AbstractRegexGambit
|
||||
throw new LogicException('This gambit can only be applied on a DiscussionSearch');
|
||||
}
|
||||
|
||||
if (empty($matches[4])) { // Single date
|
||||
$search->getQuery()->whereDate('start_time', $negate ? '!=' : '=', $matches[2]);
|
||||
} else { // Range: date..date
|
||||
$search->getQuery()->whereBetween('start_time', [$matches[2], $matches[4]], 'and', $negate);
|
||||
// If we've just been provided with a single YYYY-MM-DD date, then find
|
||||
// discussions that were started on that exact date. But if we've been
|
||||
// provided with a YYYY-MM-DD..YYYY-MM-DD range, then find discussions
|
||||
// that were started during that period.
|
||||
if (empty($matches[3])) {
|
||||
$search->getQuery()->whereDate('start_time', $negate ? '!=' : '=', $matches[1]);
|
||||
} else {
|
||||
$search->getQuery()->whereBetween('start_time', [$matches[1], $matches[3]], 'and', $negate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user