Avoid using DQL reserved words in queries
This commit is contained in:
parent
d1e752faed
commit
80ee1b01e3
|
@ -107,8 +107,8 @@ final class EntityManager extends EntityManagerDecorator
|
||||||
{
|
{
|
||||||
$timestamp = '0000-00-00T00:00:00Z';
|
$timestamp = '0000-00-00T00:00:00Z';
|
||||||
$dql = $this->createQueryBuilder();
|
$dql = $this->createQueryBuilder();
|
||||||
$dql->select($dql->expr()->min('record.lastChanged'));
|
$dql->select($dql->expr()->min('records.lastChanged'));
|
||||||
$dql->from(Record::class, 'record');
|
$dql->from(Record::class, 'records');
|
||||||
$query = $dql->getQuery()->enableResultCache();
|
$query = $dql->getQuery()->enableResultCache();
|
||||||
/** @var ?string $result */
|
/** @var ?string $result */
|
||||||
$result = $query->getOneOrNullResult(AbstractQuery::HYDRATE_SCALAR_COLUMN);
|
$result = $query->getOneOrNullResult(AbstractQuery::HYDRATE_SCALAR_COLUMN);
|
||||||
|
@ -141,9 +141,10 @@ final class EntityManager extends EntityManagerDecorator
|
||||||
$formats = $this->getRepository(Format::class)->findAll();
|
$formats = $this->getRepository(Format::class)->findAll();
|
||||||
} else {
|
} else {
|
||||||
$dql = $this->createQueryBuilder();
|
$dql = $this->createQueryBuilder();
|
||||||
$dql->select('record.format')
|
$dql->select('formats')
|
||||||
->from(Record::class, 'record')
|
->from(Format::class, 'formats')
|
||||||
->where($dql->expr()->eq('record.identifier', ':recordIdentifier'))
|
->innerJoin('formats.records', 'records')
|
||||||
|
->where($dql->expr()->eq('records.identifier', ':recordIdentifier'))
|
||||||
->setParameter('recordIdentifier', $recordIdentifier);
|
->setParameter('recordIdentifier', $recordIdentifier);
|
||||||
$query = $dql->getQuery()->enableResultCache();
|
$query = $dql->getQuery()->enableResultCache();
|
||||||
/** @var Format[] */
|
/** @var Format[] */
|
||||||
|
@ -196,18 +197,18 @@ final class EntityManager extends EntityManagerDecorator
|
||||||
$cursor = $counter * $maxRecords;
|
$cursor = $counter * $maxRecords;
|
||||||
|
|
||||||
$dql = $this->createQueryBuilder();
|
$dql = $this->createQueryBuilder();
|
||||||
$dql->select('record')
|
$dql->select('records')
|
||||||
->from(Record::class, 'record', 'record.identifier')
|
->from(Record::class, 'records', 'records.identifier')
|
||||||
->where($dql->expr()->eq('record.format', ':metadataPrefix'))
|
->where($dql->expr()->eq('records.format', ':metadataPrefix'))
|
||||||
->setParameter('metadataPrefix', $this->getMetadataFormat($metadataPrefix))
|
->setParameter('metadataPrefix', $this->getMetadataFormat($metadataPrefix))
|
||||||
->setFirstResult($cursor)
|
->setFirstResult($cursor)
|
||||||
->setMaxResults($maxRecords);
|
->setMaxResults($maxRecords);
|
||||||
if (isset($from)) {
|
if (isset($from)) {
|
||||||
$dql->andWhere($dql->expr()->gte('record.lastChanged', ':from'));
|
$dql->andWhere($dql->expr()->gte('records.lastChanged', ':from'));
|
||||||
$dql->setParameter('from', new DateTime($from));
|
$dql->setParameter('from', new DateTime($from));
|
||||||
}
|
}
|
||||||
if (isset($until)) {
|
if (isset($until)) {
|
||||||
$dql->andWhere($dql->expr()->lte('record.lastChanged', ':until'));
|
$dql->andWhere($dql->expr()->lte('records.lastChanged', ':until'));
|
||||||
$dql->setParameter('until', new DateTime($until));
|
$dql->setParameter('until', new DateTime($until));
|
||||||
}
|
}
|
||||||
if (isset($set)) {
|
if (isset($set)) {
|
||||||
|
@ -296,8 +297,8 @@ final class EntityManager extends EntityManagerDecorator
|
||||||
$cursor = $counter * $maxRecords;
|
$cursor = $counter * $maxRecords;
|
||||||
|
|
||||||
$dql = $this->createQueryBuilder();
|
$dql = $this->createQueryBuilder();
|
||||||
$dql->select('set')
|
$dql->select('sets')
|
||||||
->from(Set::class, 'set', 'set.spec')
|
->from(Set::class, 'sets', 'sets.spec')
|
||||||
->setFirstResult($cursor)
|
->setFirstResult($cursor)
|
||||||
->setMaxResults($maxRecords);
|
->setMaxResults($maxRecords);
|
||||||
$query = $dql->getQuery()->enableResultCache();
|
$query = $dql->getQuery()->enableResultCache();
|
||||||
|
@ -348,8 +349,8 @@ final class EntityManager extends EntityManagerDecorator
|
||||||
public function pruneDeletedRecords(): int
|
public function pruneDeletedRecords(): int
|
||||||
{
|
{
|
||||||
$dql = $this->createQueryBuilder();
|
$dql = $this->createQueryBuilder();
|
||||||
$dql->delete(Record::class, 'record')
|
$dql->delete(Record::class, 'records')
|
||||||
->where($dql->expr()->isNull('record.content'));
|
->where($dql->expr()->isNull('records.content'));
|
||||||
/** @var int */
|
/** @var int */
|
||||||
$deleted = $dql->getQuery()->execute();
|
$deleted = $dql->getQuery()->execute();
|
||||||
if ($deleted > 0) {
|
if ($deleted > 0) {
|
||||||
|
@ -366,8 +367,8 @@ final class EntityManager extends EntityManagerDecorator
|
||||||
public function pruneExpiredTokens(): int
|
public function pruneExpiredTokens(): int
|
||||||
{
|
{
|
||||||
$dql = $this->createQueryBuilder();
|
$dql = $this->createQueryBuilder();
|
||||||
$dql->delete(Token::class, 'token')
|
$dql->delete(Token::class, 'tokens')
|
||||||
->where($dql->expr()->lt('token.validUntil', new DateTime()));
|
->where($dql->expr()->lt('tokens.validUntil', new DateTime()));
|
||||||
/** @var int */
|
/** @var int */
|
||||||
return $dql->getQuery()->execute();
|
return $dql->getQuery()->execute();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue