Skip to content

Commit

Permalink
[Ohme] Refresh adherent tags after import (#11535)
Browse files Browse the repository at this point in the history
Co-authored-by: Rémi <[email protected]>
  • Loading branch information
Remg and Rémi authored Feb 27, 2025
1 parent ebb2c4c commit f21d0de
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/Ohme/PaymentImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@

namespace App\Ohme;

use App\Adherent\Tag\Command\AsyncRefreshAdherentTagCommand;
use App\Entity\Contribution\Payment;
use App\Repository\Contribution\PaymentRepository;
use App\Repository\Ohme\ContactRepository;
use Ramsey\Uuid\Uuid;
use Symfony\Component\Messenger\MessageBusInterface;

class PaymentImporter
{
public function __construct(
private readonly ClientInterface $client,
private readonly ContactRepository $contactRepository,
private readonly PaymentRepository $paymentRepository,
private readonly MessageBusInterface $bus,
) {
}

Expand All @@ -32,6 +36,7 @@ public function importPayments(int $limit = 100, int $offset = 0, array $options

$total = 0;

$adherentsUuidToRefresh = [];
foreach ($payments['data'] as $paymentData) {
++$total;

Expand Down Expand Up @@ -74,6 +79,15 @@ public function importPayments(int $limit = 100, int $offset = 0, array $options

$this->contactRepository->save($contact);
}

$adherentUuid = $contact->adherent->getUuid()->toString();
if (!\in_array($adherentUuid, $adherentsUuidToRefresh)) {
$adherentsUuidToRefresh[] = $adherentUuid;
}
}

foreach ($adherentsUuidToRefresh as $adherentUuid) {
$this->bus->dispatch(new AsyncRefreshAdherentTagCommand(Uuid::fromString($adherentUuid)));
}

return $total;
Expand Down
4 changes: 2 additions & 2 deletions tests/Command/OhmeImportCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ public function testCommandSuccess(): void
{
self::assertCount(0, $this->contactRepository->findAll());

$output = $this->runCommand('app:ohme:import');
$output = $this->runCommand('app:ohme:import', ['--with-payments' => true]);
$output = $output->getDisplay();

self::assertStringContainsString('[OK] 3 contacts handled successfully.', $output);

self::assertStringContainsString('[OK] 3 payments handled successfully.', $output);
self::assertCount(3, $this->contactRepository->findAll());
}

Expand Down

0 comments on commit f21d0de

Please sign in to comment.