1
0
mirror of https://github.com/flarum/core.git synced 2025-07-26 03:01:22 +02:00

Fix/clean up created gambit

$matches indices were incorrect.
This commit is contained in:
Toby Zerner
2016-01-13 10:03:26 +10:30
parent 4bd2ff869e
commit dbfbab5a48

View File

@@ -18,8 +18,6 @@ use LogicException;
class CreatedGambit extends AbstractRegexGambit class CreatedGambit extends AbstractRegexGambit
{ {
/** /**
* http://stackoverflow.com/a/8270148/3158312
*
* {@inheritdoc} * {@inheritdoc}
*/ */
protected $pattern = 'created:(\d{4}\-\d\d\-\d\d)(\.\.(\d{4}\-\d\d\-\d\d))?'; 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'); throw new LogicException('This gambit can only be applied on a DiscussionSearch');
} }
if (empty($matches[4])) { // Single date // If we've just been provided with a single YYYY-MM-DD date, then find
$search->getQuery()->whereDate('start_time', $negate ? '!=' : '=', $matches[2]); // discussions that were started on that exact date. But if we've been
} else { // Range: date..date // provided with a YYYY-MM-DD..YYYY-MM-DD range, then find discussions
$search->getQuery()->whereBetween('start_time', [$matches[2], $matches[4]], 'and', $negate); // 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);
} }
} }
} }