diff --git a/config/packages/doctrine.yaml b/config/packages/doctrine.yaml index ffcafbabdb..a23e6838d4 100644 --- a/config/packages/doctrine.yaml +++ b/config/packages/doctrine.yaml @@ -95,5 +95,6 @@ doctrine: dql: datetime_functions: datediff: App\Doctrine\Functions\DateDiff + timestampdiff: App\Doctrine\Functions\TimestampDiff yearweek: App\Doctrine\Functions\YearWeek geodistance: App\Doctrine\Functions\GeoDistance diff --git a/src/Doctrine/Functions/TimestampDiff.php b/src/Doctrine/Functions/TimestampDiff.php new file mode 100644 index 0000000000..728d3f4289 --- /dev/null +++ b/src/Doctrine/Functions/TimestampDiff.php @@ -0,0 +1,61 @@ +match(Lexer::T_IDENTIFIER); + $parser->match(Lexer::T_OPEN_PARENTHESIS); + $parser->match(Lexer::T_IDENTIFIER); + + /** @var Lexer $lexer */ + $lexer = $parser->getLexer(); + $this->unit = $lexer->token['value']; + + $parser->match(Lexer::T_COMMA); + + $this->firstDatetimeExpression = $parser->ArithmeticPrimary(); + + $parser->match(Lexer::T_COMMA); + + $this->secondDatetimeExpression = $parser->ArithmeticPrimary(); + + $parser->match(Lexer::T_CLOSE_PARENTHESIS); + } + + public function getSql(SqlWalker $sqlWalker) + { + return 'TIMESTAMPDIFF(' . + $this->unit . ', ' . + $this->firstDatetimeExpression->dispatch($sqlWalker) . ', ' . + $this->secondDatetimeExpression->dispatch($sqlWalker) . + ')'; + } +} diff --git a/src/Repository/ActivityRepository.php b/src/Repository/ActivityRepository.php index 7b6228f557..75acbb0cc3 100644 --- a/src/Repository/ActivityRepository.php +++ b/src/Repository/ActivityRepository.php @@ -76,7 +76,7 @@ public function queryProblematicActivities() ->join('App:ActivityAttendee', 'aa', Join::WITH, 'aa.activity = a and aa.organizer = 1') ->join('App:Member', 'm', Join::WITH, 'aa.attendee = m') ->where("m.status = 'Banned'") - ->orWhere('DATEDIFF(a.ends, a.starts) > 1') + ->orWhere('TIMESTAMPDIFF(MINUTE, a.starts, a.ends) >= 0') ->orderBy('a.id', 'desc') ->getQuery(); }