Skip to content

Commit

Permalink
Changed from BINARY to md5 to make it work in Postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathis Koblin committed Jan 30, 2025
1 parent 37ab27e commit fa796e1
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions Classes/Command/UnduplicateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,10 @@ public function findDuplicates(mixed $onlyThisIdentifier, int $onlyThisStorage):
$concreteQueryBuilder = $queryBuilder->getConcreteQueryBuilder();

// GROUP BY BINARY `identifier`,`storage
$concreteQueryBuilder->groupBy('BINARY ' . $queryBuilder->quoteIdentifier('identifier'));
$concreteQueryBuilder->addGroupBy($queryBuilder->quoteIdentifier('storage'));
$concreteQueryBuilder->groupBy('md5(identifier)');
$concreteQueryBuilder->addGroupBy('storage');
// SELECT MAX(`identifier`) AS identifier,`storage`
$concreteQueryBuilder->addSelect('MAX(' . $queryBuilder->quoteIdentifier('identifier')
. ') AS identifier, ' . $queryBuilder->quoteIdentifier('storage'));
$concreteQueryBuilder->addSelect('MAX(identifier) AS identifier, storage');

$this->output->writeln('sql=' . $queryBuilder->getSQL(), OutputInterface::VERBOSITY_VERBOSE);

Expand All @@ -261,9 +260,7 @@ private function findDuplicateFilesForIdentifier(string $identifier, int $storag
)
)->orderBy('uid', 'DESC');

$whereClause = $fileQueryBuilder->expr()->eq('identifier',
$fileQueryBuilder->createNamedParameter($identifier, \PDO::PARAM_STR));
$whereClause = 'BINARY ' . $whereClause;
$whereClause = 'md5(identifier) = md5(' . $fileQueryBuilder->createNamedParameter($identifier, \PDO::PARAM_STR) . ')';
$fileQueryBuilder->add('where', $whereClause);

return $fileQueryBuilder->executeQuery()
Expand Down

0 comments on commit fa796e1

Please sign in to comment.