Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#248 Fetching spam activities with at least 0 minutes runtime (instead of only the ones longer than 1 day) #339

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
61 changes: 61 additions & 0 deletions src/Doctrine/Functions/TimestampDiff.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace App\Doctrine\Functions;

use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\AST\Node;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\SqlWalker;

/**
* TimestampDiffFunction ::=
* "TIMESTAMPDIFF" "(" ArithmeticPrimary Identifier "," ArithmeticPrimary "," ArithmeticPrimary ")".
*/
class TimestampDiff extends FunctionNode
{
/**
* @var string|null
*/
public $unit = null;

/**
* @var Node|null
*/
public $firstDatetimeExpression = null;

/**
* @var Node|null
*/
public $secondDatetimeExpression = null;

public function parse(Parser $parser)
{
$parser->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) .
')';
}
}
2 changes: 1 addition & 1 deletion src/Repository/ActivityRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down