Merge pull request #191 from goteo/feat/find-by-dedupedIds
feat: find by deduped ids
This commit is contained in:
@@ -34,7 +34,8 @@ doctrine:
|
||||
is_bundle: false
|
||||
dql:
|
||||
string_functions:
|
||||
instr: DoctrineExtensions\Query\Mysql\Instr
|
||||
INSTR: DoctrineExtensions\Query\Mysql\Instr
|
||||
JSON_CONTAINS: DoctrineExtensions\Query\Mysql\JsonContains
|
||||
controller_resolver:
|
||||
auto_mapping: false
|
||||
|
||||
|
||||
@@ -27,9 +27,7 @@ use App\Repository\Project\ProjectRepository;
|
||||
use App\Repository\Project\RewardRepository;
|
||||
use App\Repository\Project\SupportRepository;
|
||||
use App\Repository\TipjarRepository;
|
||||
use App\Repository\User\UserRepository;
|
||||
use App\Service\Gateway\CheckoutService;
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use Goteo\Benzina\Pump\ArrayPumpTrait;
|
||||
use Goteo\Benzina\Pump\DoctrinePumpTrait;
|
||||
use Goteo\Benzina\Pump\PumpInterface;
|
||||
@@ -58,9 +56,6 @@ class InvestsPump implements PumpInterface
|
||||
|
||||
private ?int $tipjarCache = null;
|
||||
|
||||
/** @var array<string, int> */
|
||||
private array $userCache = [];
|
||||
|
||||
/** @var array<string, int> */
|
||||
private array $projectCache = [];
|
||||
|
||||
@@ -71,7 +66,7 @@ class InvestsPump implements PumpInterface
|
||||
private array $rewardCache = [];
|
||||
|
||||
public function __construct(
|
||||
private UserRepository $userRepository,
|
||||
private PumpedUserRepository $userRepository,
|
||||
private ProjectRepository $projectRepository,
|
||||
private SupportRepository $supportRepository,
|
||||
private TipjarRepository $tipjarRepository,
|
||||
@@ -209,23 +204,7 @@ class InvestsPump implements PumpInterface
|
||||
|
||||
private function getUser(array $record): ?User
|
||||
{
|
||||
$id = $record['user'];
|
||||
|
||||
if (isset($this->userCache[$id])) {
|
||||
return $this->userRepository->find($this->userCache[$id]);
|
||||
}
|
||||
|
||||
$criteria = new Criteria();
|
||||
$criteria
|
||||
->orWhere($criteria->expr()->eq('migratedId', $id))
|
||||
->orWhere($criteria->expr()->contains('dedupedIds', $id))
|
||||
->setMaxResults(1);
|
||||
|
||||
$user = $this->userRepository->matching($criteria)->first();
|
||||
|
||||
$this->userCache[$id] = $user->getId();
|
||||
|
||||
return $user;
|
||||
return $this->userRepository->findPumped($record['user']);
|
||||
}
|
||||
|
||||
private function getProject(array $record): ?Project
|
||||
@@ -420,18 +399,18 @@ class InvestsPump implements PumpInterface
|
||||
private function getCheckoutGateway(array $record): string
|
||||
{
|
||||
switch ($record['method']) {
|
||||
case 'stripe_subscription':
|
||||
return StripeGateway::getName();
|
||||
case 'pool':
|
||||
return WalletGateway::getName();
|
||||
case 'paypal':
|
||||
return PaypalGateway::getName();
|
||||
case 'tpv':
|
||||
return CecaGateway::getName();
|
||||
case 'paypal':
|
||||
return PaypalGateway::getName();
|
||||
case 'pool':
|
||||
return WalletGateway::getName();
|
||||
case 'cash':
|
||||
return CashGateway::getName();
|
||||
case 'drop':
|
||||
return DropGateway::getName();
|
||||
case 'stripe_subscription':
|
||||
return StripeGateway::getName();
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Benzina;
|
||||
|
||||
use App\Entity\User\User;
|
||||
use App\Repository\User\UserRepository;
|
||||
|
||||
class PumpedUserRepository extends UserRepository
|
||||
{
|
||||
/** @var array<string, int> */
|
||||
private array $userCache = [];
|
||||
|
||||
public function findPumped(string $id): ?User
|
||||
{
|
||||
if (isset($this->userCache[$id])) {
|
||||
return $this->find($this->userCache[$id]);
|
||||
}
|
||||
|
||||
$user = $this->findOneBy(['migratedId' => $id]);
|
||||
if (!$user) {
|
||||
$user = $this->findDeduped([$id]);
|
||||
}
|
||||
|
||||
if (!$user) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->userCache[$id] = $user->getId();
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
@@ -63,8 +63,6 @@ final class GatewayFilter extends AbstractFilter
|
||||
$queryBuilder
|
||||
->andWhere($queryBuilder->expr()->eq($aliasedField, $parameterName))
|
||||
->setParameter($parameterName, $this->getGatewayName($values[0]));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private function getGatewayName(mixed $value): string
|
||||
|
||||
@@ -32,9 +32,7 @@ final class ResourceVersionResourceFilter extends AbstractFilter
|
||||
string $resourceClass,
|
||||
?Operation $operation = null,
|
||||
array $context = [],
|
||||
): void {
|
||||
return;
|
||||
}
|
||||
): void {}
|
||||
|
||||
public function getDescription(string $resourceClass): array
|
||||
{
|
||||
|
||||
@@ -18,9 +18,7 @@ final class ResourceVersionResourceIdFilter extends AbstractFilter
|
||||
string $resourceClass,
|
||||
?Operation $operation = null,
|
||||
array $context = [],
|
||||
): void {
|
||||
return;
|
||||
}
|
||||
): void {}
|
||||
|
||||
public function getDescription(string $resourceClass): array
|
||||
{
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\User\User;
|
||||
|
||||
trait DedupedTrait
|
||||
{
|
||||
public function findDeduped(array $dedupedIds): ?User
|
||||
{
|
||||
/** @var \Doctrine\ORM\QueryBuilder */
|
||||
$queryBuilder = $this->createQueryBuilder('u');
|
||||
|
||||
return $queryBuilder
|
||||
->where('u.deduped = 1')
|
||||
->andWhere('JSON_CONTAINS(u.dedupedIds, :val) = 1')
|
||||
->setParameter('val', \json_encode($dedupedIds))
|
||||
->getQuery()
|
||||
->getOneOrNullResult();
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ namespace App\Repository\User;
|
||||
|
||||
use App\Entity\Accounting\Accounting;
|
||||
use App\Entity\User\User;
|
||||
use App\Repository\DedupedTrait;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
|
||||
@@ -22,6 +23,8 @@ use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;
|
||||
*/
|
||||
class UserRepository extends ServiceEntityRepository implements PasswordUpgraderInterface
|
||||
{
|
||||
use DedupedTrait;
|
||||
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, User::class);
|
||||
|
||||
Reference in New Issue
Block a user