mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-27 00:55:01 +00:00
Inject ManagerRegistry directly instead of getting from container
This commit is contained in:
@@ -39,6 +39,8 @@ abstract class AbstractCRUDController extends AbstractController
|
|||||||
*/
|
*/
|
||||||
protected array $crudConfig = [];
|
protected array $crudConfig = [];
|
||||||
|
|
||||||
|
public function __construct(protected ManagerRegistry $doctrine) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the role given from the config.
|
* get the role given from the config.
|
||||||
*/
|
*/
|
||||||
@@ -62,7 +64,6 @@ abstract class AbstractCRUDController extends AbstractController
|
|||||||
return \array_merge(
|
return \array_merge(
|
||||||
parent::getSubscribedServices(),
|
parent::getSubscribedServices(),
|
||||||
[
|
[
|
||||||
'doctrine' => ManagerRegistry::class,
|
|
||||||
'chill_main.paginator_factory' => PaginatorFactory::class,
|
'chill_main.paginator_factory' => PaginatorFactory::class,
|
||||||
'translator' => TranslatorInterface::class,
|
'translator' => TranslatorInterface::class,
|
||||||
AuthorizationHelper::class => AuthorizationHelper::class,
|
AuthorizationHelper::class => AuthorizationHelper::class,
|
||||||
@@ -98,7 +99,7 @@ abstract class AbstractCRUDController extends AbstractController
|
|||||||
*/
|
*/
|
||||||
protected function buildQueryEntities(string $action, Request $request)
|
protected function buildQueryEntities(string $action, Request $request)
|
||||||
{
|
{
|
||||||
$qb = $this->getManagerRegistry()->getManager()
|
$qb = $this->doctrine->getManager()
|
||||||
->createQueryBuilder()
|
->createQueryBuilder()
|
||||||
->select('e')
|
->select('e')
|
||||||
->from($this->getEntityClass(), 'e');
|
->from($this->getEntityClass(), 'e');
|
||||||
@@ -170,8 +171,7 @@ abstract class AbstractCRUDController extends AbstractController
|
|||||||
*/
|
*/
|
||||||
protected function getEntity(mixed $action, string $id, Request $request): object
|
protected function getEntity(mixed $action, string $id, Request $request): object
|
||||||
{
|
{
|
||||||
$e = $this->getManagerRegistry()
|
$e = $this->doctrine->getRepository($this->getEntityClass())
|
||||||
->getRepository($this->getEntityClass())
|
|
||||||
->find($id);
|
->find($id);
|
||||||
|
|
||||||
if (null === $e) {
|
if (null === $e) {
|
||||||
@@ -181,7 +181,7 @@ abstract class AbstractCRUDController extends AbstractController
|
|||||||
$expectedVersion = $request->query->getInt('entity_version');
|
$expectedVersion = $request->query->getInt('entity_version');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$manager = $this->getManagerRegistry()->getManagerForClass($this->getEntityClass());
|
$manager = $this->doctrine->getManagerForClass($this->getEntityClass());
|
||||||
|
|
||||||
if ($manager instanceof EntityManagerInterface) {
|
if ($manager instanceof EntityManagerInterface) {
|
||||||
$manager->lock($e, LockMode::OPTIMISTIC, $expectedVersion);
|
$manager->lock($e, LockMode::OPTIMISTIC, $expectedVersion);
|
||||||
@@ -211,11 +211,6 @@ abstract class AbstractCRUDController extends AbstractController
|
|||||||
return $this->container->get('chill_main.paginator_factory');
|
return $this->container->get('chill_main.paginator_factory');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getManagerRegistry(): ManagerRegistry
|
|
||||||
{
|
|
||||||
return $this->container->get('doctrine');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the result of the query.
|
* Get the result of the query.
|
||||||
*/
|
*/
|
||||||
|
@@ -80,8 +80,8 @@ class ApiController extends AbstractCRUDController
|
|||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->getManagerRegistry()->getManager()->remove($entity);
|
$this->doctrine->getManager()->remove($entity);
|
||||||
$this->getManagerRegistry()->getManager()->flush();
|
$this->doctrine->getManager()->flush();
|
||||||
|
|
||||||
$response = $this->onAfterFlush($action, $request, $_format, $entity, $errors);
|
$response = $this->onAfterFlush($action, $request, $_format, $entity, $errors);
|
||||||
|
|
||||||
|
@@ -62,6 +62,8 @@ class CRUDController extends AbstractController
|
|||||||
*/
|
*/
|
||||||
protected array $crudConfig;
|
protected array $crudConfig;
|
||||||
|
|
||||||
|
public function __construct(private readonly ManagerRegistry $managerRegistry) {}
|
||||||
|
|
||||||
public function CRUD(?string $parameter): Response
|
public function CRUD(?string $parameter): Response
|
||||||
{
|
{
|
||||||
return new Response($parameter);
|
return new Response($parameter);
|
||||||
@@ -175,7 +177,7 @@ class CRUDController extends AbstractController
|
|||||||
*/
|
*/
|
||||||
protected function buildQueryEntities(string $action, Request $request)
|
protected function buildQueryEntities(string $action, Request $request)
|
||||||
{
|
{
|
||||||
$query = $this->getManagerRegistry()
|
$query = $this->managerRegistry
|
||||||
->getManager()
|
->getManager()
|
||||||
->createQueryBuilder()
|
->createQueryBuilder()
|
||||||
->select('e')
|
->select('e')
|
||||||
@@ -289,7 +291,7 @@ class CRUDController extends AbstractController
|
|||||||
|
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
$this->onFormValid($action, $entity, $form, $request);
|
$this->onFormValid($action, $entity, $form, $request);
|
||||||
$em = $this->getManagerRegistry()->getManager();
|
$em = $this->managerRegistry->getManager();
|
||||||
|
|
||||||
$this->onPreRemove($action, $entity, $form, $request);
|
$this->onPreRemove($action, $entity, $form, $request);
|
||||||
$this->removeEntity($action, $entity, $form, $request);
|
$this->removeEntity($action, $entity, $form, $request);
|
||||||
@@ -334,7 +336,7 @@ class CRUDController extends AbstractController
|
|||||||
$id = $request->query->get('duplicate_id', 0);
|
$id = $request->query->get('duplicate_id', 0);
|
||||||
$originalEntity = $this->getEntity($action, $id, $request);
|
$originalEntity = $this->getEntity($action, $id, $request);
|
||||||
|
|
||||||
$this->getManagerRegistry()->getManager()
|
$this->managerRegistry->getManager()
|
||||||
->detach($originalEntity);
|
->detach($originalEntity);
|
||||||
|
|
||||||
return $originalEntity;
|
return $originalEntity;
|
||||||
@@ -406,7 +408,7 @@ class CRUDController extends AbstractController
|
|||||||
|
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
$this->onFormValid($action, $entity, $form, $request);
|
$this->onFormValid($action, $entity, $form, $request);
|
||||||
$em = $this->getManagerRegistry()->getManager();
|
$em = $this->managerRegistry->getManager();
|
||||||
|
|
||||||
$this->onPrePersist($action, $entity, $form, $request);
|
$this->onPrePersist($action, $entity, $form, $request);
|
||||||
$em->persist($entity);
|
$em->persist($entity);
|
||||||
@@ -509,7 +511,7 @@ class CRUDController extends AbstractController
|
|||||||
|
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
$this->onFormValid($action, $entity, $form, $request);
|
$this->onFormValid($action, $entity, $form, $request);
|
||||||
$em = $this->getManagerRegistry()->getManager();
|
$em = $this->managerRegistry->getManager();
|
||||||
|
|
||||||
$this->onPreFlush($action, $entity, $form, $request);
|
$this->onPreFlush($action, $entity, $form, $request);
|
||||||
$em->flush();
|
$em->flush();
|
||||||
@@ -623,7 +625,7 @@ class CRUDController extends AbstractController
|
|||||||
*/
|
*/
|
||||||
protected function getEntity(mixed $action, $id, Request $request): ?object
|
protected function getEntity(mixed $action, $id, Request $request): ?object
|
||||||
{
|
{
|
||||||
return $this->getManagerRegistry()
|
return $this->managerRegistry
|
||||||
->getRepository($this->getEntityClass())
|
->getRepository($this->getEntityClass())
|
||||||
->find($id);
|
->find($id);
|
||||||
}
|
}
|
||||||
@@ -672,11 +674,6 @@ class CRUDController extends AbstractController
|
|||||||
return $this->container->get('chill_main.paginator_factory');
|
return $this->container->get('chill_main.paginator_factory');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getManagerRegistry(): ManagerRegistry
|
|
||||||
{
|
|
||||||
return $this->container->get(ManagerRegistry::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the result of the query.
|
* Get the result of the query.
|
||||||
*/
|
*/
|
||||||
@@ -946,7 +943,7 @@ class CRUDController extends AbstractController
|
|||||||
|
|
||||||
protected function removeEntity(string $action, $entity, FormInterface $form, Request $request)
|
protected function removeEntity(string $action, $entity, FormInterface $form, Request $request)
|
||||||
{
|
{
|
||||||
$this->getManagerRegistry()
|
$this->managerRegistry
|
||||||
->getManager()
|
->getManager()
|
||||||
->remove($entity);
|
->remove($entity);
|
||||||
}
|
}
|
||||||
|
@@ -24,6 +24,7 @@ use Chill\MainBundle\Pagination\PaginatorInterface;
|
|||||||
use Chill\MainBundle\Repository\UserRepository;
|
use Chill\MainBundle\Repository\UserRepository;
|
||||||
use Chill\MainBundle\Security\ChillSecurity;
|
use Chill\MainBundle\Security\ChillSecurity;
|
||||||
use Chill\MainBundle\Templating\Listing\FilterOrderHelper;
|
use Chill\MainBundle\Templating\Listing\FilterOrderHelper;
|
||||||
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||||
@@ -48,7 +49,7 @@ class UserController extends CRUDController
|
|||||||
protected ParameterBagInterface $parameterBag,
|
protected ParameterBagInterface $parameterBag,
|
||||||
private readonly TranslatorInterface $translator,
|
private readonly TranslatorInterface $translator,
|
||||||
private readonly ChillSecurity $security,
|
private readonly ChillSecurity $security,
|
||||||
private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry,
|
private readonly ManagerRegistry $managerRegistry,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
#[Route(path: '/{_locale}/admin/main/user/{uid}/add_link_groupcenter', name: 'admin_user_add_groupcenter')]
|
#[Route(path: '/{_locale}/admin/main/user/{uid}/add_link_groupcenter', name: 'admin_user_add_groupcenter')]
|
||||||
@@ -203,7 +204,7 @@ class UserController extends CRUDController
|
|||||||
* Displays a form to edit the user current location.
|
* Displays a form to edit the user current location.
|
||||||
*/
|
*/
|
||||||
#[Route(path: '/{_locale}/main/user/current-location/edit', name: 'chill_main_user_currentlocation_edit')]
|
#[Route(path: '/{_locale}/main/user/current-location/edit', name: 'chill_main_user_currentlocation_edit')]
|
||||||
public function editCurrentLocationAction(Request $request): \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
public function editCurrentLocationAction(Request $request): RedirectResponse|Response
|
||||||
{
|
{
|
||||||
$user = $this->security->getUser();
|
$user = $this->security->getUser();
|
||||||
$form = $this->createForm(UserCurrentLocationType::class, $user)
|
$form = $this->createForm(UserCurrentLocationType::class, $user)
|
||||||
@@ -234,7 +235,7 @@ class UserController extends CRUDController
|
|||||||
* Displays a form to edit the user password.
|
* Displays a form to edit the user password.
|
||||||
*/
|
*/
|
||||||
#[Route(path: '/{_locale}/admin/user/{id}/edit_password', name: 'admin_user_edit_password')]
|
#[Route(path: '/{_locale}/admin/user/{id}/edit_password', name: 'admin_user_edit_password')]
|
||||||
public function editPasswordAction(User $user, Request $request): \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
public function editPasswordAction(User $user, Request $request): RedirectResponse|Response
|
||||||
{
|
{
|
||||||
$editForm = $this->createEditPasswordForm($user);
|
$editForm = $this->createEditPasswordForm($user);
|
||||||
$editForm->handleRequest($request);
|
$editForm->handleRequest($request);
|
||||||
|
Reference in New Issue
Block a user