Remove dumps and inject thirdparty directly into controller action

This commit is contained in:
Julie Lenaerts 2025-02-25 16:35:30 +01:00
parent 13b1d20ade
commit ed60c6aaa3
4 changed files with 13 additions and 43 deletions

View File

@ -12,28 +12,25 @@ declare(strict_types=1);
namespace Chill\ThirdPartyBundle\Controller; namespace Chill\ThirdPartyBundle\Controller;
use Chill\PersonBundle\Form\PersonConfimDuplicateType; use Chill\PersonBundle\Form\PersonConfimDuplicateType;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Chill\ThirdPartyBundle\Form\ThirdpartyFindDuplicateType; use Chill\ThirdPartyBundle\Form\ThirdpartyFindDuplicateType;
use Chill\ThirdPartyBundle\Repository\ThirdPartyRepository; use Chill\ThirdPartyBundle\Repository\ThirdPartyRepository;
use Chill\ThirdPartyBundle\Service\ThirdpartyMergeService; use Chill\ThirdPartyBundle\Service\ThirdpartyMergeService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
class ThirdpartyDuplicateController extends AbstractController class ThirdpartyDuplicateController extends AbstractController
{ {
public function __construct(private readonly ThirdPartyRepository $thirdPartyRepository, private readonly ThirdpartyMergeService $thirdPartyMergeService) {} public function __construct(private readonly ThirdPartyRepository $thirdPartyRepository, private readonly ThirdpartyMergeService $thirdPartyMergeService) {}
/**
* @ParamConverter("thirdparty", options={"id": "thirdparty_id"})
*/
#[Route(path: '/{_locale}/3party/{thirdparty_id}/find-manually', name: 'chill_thirdparty_find_duplicate')] #[Route(path: '/{_locale}/3party/{thirdparty_id}/find-manually', name: 'chill_thirdparty_find_duplicate')]
public function findManuallyDuplicateAction(mixed $thirdparty_id, Request $request) public function findManuallyDuplicateAction(ThirdParty $thirdparty, Request $request)
{ {
$thirdparty = $this->thirdPartyRepository->find($thirdparty_id);
dump($thirdparty_id);
dump($thirdparty);
if (null === $thirdparty) {
throw $this->createNotFoundException("Thirdparty with id {$thirdparty_id} not".' found on this server');
}
$form = $this->createForm(ThirdpartyFindDuplicateType::class); $form = $this->createForm(ThirdpartyFindDuplicateType::class);
$form->handleRequest($request); $form->handleRequest($request);
@ -64,24 +61,17 @@ class ThirdpartyDuplicateController extends AbstractController
]); ]);
} }
/**
* @ParamConverter("thirdparty1", options={"id": "thirdparty1_id"})
* @ParamConverter("thirdparty2", options={"id": "thirdparty2_id"})
*/
#[Route(path: '/{_locale}/3party/{thirdparty1_id}/duplicate/{thirdparty2_id}/confirm', name: 'chill_thirdparty_duplicate_confirm')] #[Route(path: '/{_locale}/3party/{thirdparty1_id}/duplicate/{thirdparty2_id}/confirm', name: 'chill_thirdparty_duplicate_confirm')]
public function confirmAction(mixed $thirdparty1_id, mixed $thirdparty2_id, Request $request) public function confirmAction(ThirdParty $thirdparty1, ThirdParty $thirdparty2, Request $request)
{ {
if ($thirdparty1_id === $thirdparty2_id) { if ($thirdparty1 === $thirdparty2) {
throw new \InvalidArgumentException('Can not merge same thirdparty'); throw new \InvalidArgumentException('Can not merge same thirdparty');
} }
$thirdparty1 = $this->thirdPartyRepository->find($thirdparty1_id);
$thirdparty2 = $this->thirdPartyRepository->find($thirdparty2_id);
if (null === $thirdparty1) {
throw $this->createNotFoundException("Thirdparty with id {$thirdparty1_id} not".' found on this server');
}
if (null === $thirdparty2) {
throw $this->createNotFoundException("Person with id {$thirdparty2_id} not".' found on this server');
}
$form = $this->createForm(PersonConfimDuplicateType::class); $form = $this->createForm(PersonConfimDuplicateType::class);
$form->handleRequest($request); $form->handleRequest($request);

View File

@ -29,12 +29,4 @@ class ThirdpartyFindDuplicateType extends AbstractType
'data' => 'starting', 'data' => 'starting',
]); ]);
} }
/**
* @return string
*/
public function getBlockPrefix()
{
return 'chill_thirdpartybundle_thirdparty_find_manually_duplicate';
}
} }

View File

@ -25,15 +25,3 @@
{{ thirdparty.contactDataAnonymous }}</li> {{ thirdparty.contactDataAnonymous }}</li>
</ul> </ul>
{% endmacro %} {% endmacro %}
{#{%- macro links(thirdparty, options) -%}#}
{# <ul>#}
{##}
{# <li><b>{{ person.counters.nb_activity }}</b> {{ (person.counters.nb_activity > 1)? 'échanges' : 'échange' }}</li>#}
{# <li><b>{{ person.counters.nb_task }}</b> {{ (person.counters.nb_task > 1)? 'tâches' : 'tâche' }}</li>#}
{# <li><b>{{ person.counters.nb_document }}</b> {{ (person.counters.nb_document > 1)? 'documents' : 'document' }}</li>#}
{# <li><b>{{ person.counters.nb_event }}</b> {{ (person.counters.nb_event > 1)? 'événements' : 'événement' }}</li>#}
{# <li><b>{{ person.counters.nb_addresses }}</b> {{ (person.counters.nb_addresses > 1)? 'adresses' : 'adresse' }}</li>#}
{##}
{# </ul>#}
{#{% endmacro %}#}

View File

@ -2,7 +2,7 @@
{% set activeRouteKey = 'chill_thirdparty_duplicate' %} {% set activeRouteKey = 'chill_thirdparty_duplicate' %}
{% block title %}{{ 'Find duplicate'|trans ~ ' ' ~ thirdparty.name|capitalize }}{% endblock %} {% block title %}{{ 'thirdparty_duplicate.find'|trans ~ ' ' ~ thirdparty.name|capitalize }}{% endblock %}
{% block content %} {% block content %}