mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
fixes after merge of master into upgrade-sf4
This commit is contained in:
@@ -18,10 +18,13 @@ use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||
use Doctrine\DBAL\LockMode;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\OptimisticLockException;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\ConflictHttpException;
|
||||
use Symfony\Component\Serializer\SerializerInterface;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
@@ -36,7 +39,7 @@ abstract class AbstractCRUDController extends AbstractController
|
||||
*/
|
||||
protected array $crudConfig = [];
|
||||
|
||||
public function __construct(private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) {}
|
||||
public function __construct(private readonly ManagerRegistry $managerRegistry) {}
|
||||
|
||||
/**
|
||||
* get the role given from the config.
|
||||
@@ -62,7 +65,7 @@ abstract class AbstractCRUDController extends AbstractController
|
||||
parent::getSubscribedServices(),
|
||||
[
|
||||
'chill_main.paginator_factory' => PaginatorFactory::class,
|
||||
|
||||
ManagerRegistry::class => ManagerRegistry::class,
|
||||
'translator' => TranslatorInterface::class,
|
||||
AuthorizationHelper::class => AuthorizationHelper::class,
|
||||
EventDispatcherInterface::class => EventDispatcherInterface::class,
|
||||
@@ -97,7 +100,7 @@ abstract class AbstractCRUDController extends AbstractController
|
||||
*/
|
||||
protected function buildQueryEntities(string $action, Request $request)
|
||||
{
|
||||
$qb = $this->managerRegistry->getManager()
|
||||
$qb = $this->getManagerRegistry()->getManager()
|
||||
->createQueryBuilder()
|
||||
->select('e')
|
||||
->from($this->getEntityClass(), 'e');
|
||||
@@ -118,7 +121,7 @@ abstract class AbstractCRUDController extends AbstractController
|
||||
*
|
||||
* @param mixed|null $entity
|
||||
*
|
||||
* @throws \Symfony\Component\Security\Core\Exception\AccessDeniedHttpException
|
||||
* @throws AccessDeniedHttpException
|
||||
*/
|
||||
protected function checkACL(string $action, Request $request, string $_format, $entity = null)
|
||||
{
|
||||
@@ -147,9 +150,7 @@ abstract class AbstractCRUDController extends AbstractController
|
||||
return new $class();
|
||||
}
|
||||
|
||||
protected function customizeQuery(string $action, Request $request, $query): void
|
||||
{
|
||||
}
|
||||
protected function customizeQuery(string $action, Request $request, $query): void {}
|
||||
|
||||
protected function getActionConfig(string $action)
|
||||
{
|
||||
@@ -171,7 +172,7 @@ abstract class AbstractCRUDController extends AbstractController
|
||||
*/
|
||||
protected function getEntity(mixed $action, string $id, Request $request): object
|
||||
{
|
||||
$e = $this->managerRegistry
|
||||
$e = $this->getManagerRegistry()
|
||||
->getRepository($this->getEntityClass())
|
||||
->find($id);
|
||||
|
||||
@@ -182,7 +183,7 @@ abstract class AbstractCRUDController extends AbstractController
|
||||
$expectedVersion = $request->query->getInt('entity_version');
|
||||
|
||||
try {
|
||||
$manager = $this->getDoctrine()->getManagerForClass($this->getEntityClass());
|
||||
$manager = $this->managerRegistry->getManagerForClass($this->getEntityClass());
|
||||
|
||||
if ($manager instanceof EntityManagerInterface) {
|
||||
$manager->lock($e, LockMode::OPTIMISTIC, $expectedVersion);
|
||||
@@ -212,6 +213,11 @@ abstract class AbstractCRUDController extends AbstractController
|
||||
return $this->container->get('chill_main.paginator_factory');
|
||||
}
|
||||
|
||||
protected function getManagerRegistry(): ManagerRegistry
|
||||
{
|
||||
return $this->container->get(ManagerRegistry::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the result of the query.
|
||||
*/
|
||||
|
@@ -23,8 +23,6 @@ use Symfony\Component\Validator\ConstraintViolationListInterface;
|
||||
|
||||
class ApiController extends AbstractCRUDController
|
||||
{
|
||||
public function __construct(private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry) {}
|
||||
|
||||
/**
|
||||
* Base method for handling api action.
|
||||
*
|
||||
@@ -82,8 +80,8 @@ class ApiController extends AbstractCRUDController
|
||||
return $response;
|
||||
}
|
||||
|
||||
$this->managerRegistry->getManager()->remove($entity);
|
||||
$this->managerRegistry->getManager()->flush();
|
||||
$this->getManagerRegistry()->getManager()->remove($entity);
|
||||
$this->getManagerRegistry()->getManager()->flush();
|
||||
|
||||
$response = $this->onAfterFlush($action, $request, $_format, $entity, $errors);
|
||||
|
||||
@@ -155,7 +153,7 @@ class ApiController extends AbstractCRUDController
|
||||
return $response;
|
||||
}
|
||||
|
||||
$this->managerRegistry->getManagerForClass($this->getEntityClass())->flush();
|
||||
$this->getManagerRegistry()->getManagerForClass($this->getEntityClass())->flush();
|
||||
|
||||
$response = $this->onAfterFlush($action, $request, $_format, $entity, $errors);
|
||||
|
||||
@@ -271,10 +269,10 @@ class ApiController extends AbstractCRUDController
|
||||
}
|
||||
|
||||
if ($forcePersist && Request::METHOD_POST === $request->getMethod()) {
|
||||
$this->managerRegistry->getManager()->persist($postedData);
|
||||
$this->getManagerRegistry()->getManager()->persist($postedData);
|
||||
}
|
||||
|
||||
$this->managerRegistry->getManager()->flush();
|
||||
$this->getManagerRegistry()->getManager()->flush();
|
||||
|
||||
$response = $this->onAfterFlush($action, $request, $_format, $entity, $errors, [$postedData]);
|
||||
|
||||
@@ -375,7 +373,7 @@ class ApiController extends AbstractCRUDController
|
||||
try {
|
||||
$entity = $this->deserialize($action, $request, $_format, $entity);
|
||||
} catch (NotEncodableValueException $e) {
|
||||
throw new BadRequestHttpException('invalid json', 400, $e);
|
||||
throw new BadRequestHttpException('invalid json', $e, 400);
|
||||
}
|
||||
|
||||
$errors = $this->validate($action, $request, $_format, $entity);
|
||||
@@ -405,8 +403,8 @@ class ApiController extends AbstractCRUDController
|
||||
return $response;
|
||||
}
|
||||
|
||||
$this->managerRegistry->getManager()->persist($entity);
|
||||
$this->managerRegistry->getManager()->flush();
|
||||
$this->getManagerRegistry()->getManager()->persist($entity);
|
||||
$this->getManagerRegistry()->getManager()->flush();
|
||||
|
||||
$response = $this->onAfterFlush($action, $request, $_format, $entity, $errors);
|
||||
|
||||
|
@@ -248,13 +248,9 @@ class CRUDController extends AbstractController
|
||||
/**
|
||||
* Customize the form created by createFormFor.
|
||||
*/
|
||||
protected function customizeForm(string $action, FormInterface $form)
|
||||
{
|
||||
}
|
||||
protected function customizeForm(string $action, FormInterface $form) {}
|
||||
|
||||
protected function customizeQuery(string $action, Request $request, $query): void
|
||||
{
|
||||
}
|
||||
protected function customizeQuery(string $action, Request $request, $query): void {}
|
||||
|
||||
/**
|
||||
* @param null $formClass
|
||||
@@ -873,9 +869,7 @@ class CRUDController extends AbstractController
|
||||
};
|
||||
}
|
||||
|
||||
protected function onFormValid(string $action, object $entity, FormInterface $form, Request $request)
|
||||
{
|
||||
}
|
||||
protected function onFormValid(string $action, object $entity, FormInterface $form, Request $request) {}
|
||||
|
||||
protected function onPostCheckACL($action, Request $request, $entity): ?Response
|
||||
{
|
||||
@@ -887,58 +881,36 @@ class CRUDController extends AbstractController
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function onPostFlush(string $action, $entity, FormInterface $form, Request $request)
|
||||
{
|
||||
}
|
||||
protected function onPostFlush(string $action, $entity, FormInterface $form, Request $request) {}
|
||||
|
||||
/**
|
||||
* method used by indexAction.
|
||||
*/
|
||||
protected function onPostIndexBuildQuery(string $action, Request $request, int $totalItems, PaginatorInterface $paginator, mixed $query)
|
||||
{
|
||||
}
|
||||
protected function onPostIndexBuildQuery(string $action, Request $request, int $totalItems, PaginatorInterface $paginator, mixed $query) {}
|
||||
|
||||
/**
|
||||
* method used by indexAction.
|
||||
*/
|
||||
protected function onPostIndexFetchQuery(string $action, Request $request, int $totalItems, PaginatorInterface $paginator, mixed $entities)
|
||||
{
|
||||
}
|
||||
protected function onPostIndexFetchQuery(string $action, Request $request, int $totalItems, PaginatorInterface $paginator, mixed $entities) {}
|
||||
|
||||
protected function onPostPersist(string $action, $entity, FormInterface $form, Request $request)
|
||||
{
|
||||
}
|
||||
protected function onPostPersist(string $action, $entity, FormInterface $form, Request $request) {}
|
||||
|
||||
protected function onPostRemove(string $action, $entity, FormInterface $form, Request $request)
|
||||
{
|
||||
}
|
||||
protected function onPostRemove(string $action, $entity, FormInterface $form, Request $request) {}
|
||||
|
||||
protected function onPreDelete(string $action, Request $request)
|
||||
{
|
||||
}
|
||||
protected function onPreDelete(string $action, Request $request) {}
|
||||
|
||||
protected function onPreFlush(string $action, $entity, FormInterface $form, Request $request)
|
||||
{
|
||||
}
|
||||
protected function onPreFlush(string $action, $entity, FormInterface $form, Request $request) {}
|
||||
|
||||
protected function onPreIndex(string $action, Request $request)
|
||||
{
|
||||
}
|
||||
protected function onPreIndex(string $action, Request $request) {}
|
||||
|
||||
/**
|
||||
* method used by indexAction.
|
||||
*/
|
||||
protected function onPreIndexBuildQuery(string $action, Request $request, int $totalItems, PaginatorInterface $paginator)
|
||||
{
|
||||
}
|
||||
protected function onPreIndexBuildQuery(string $action, Request $request, int $totalItems, PaginatorInterface $paginator) {}
|
||||
|
||||
protected function onPrePersist(string $action, $entity, FormInterface $form, Request $request)
|
||||
{
|
||||
}
|
||||
protected function onPrePersist(string $action, $entity, FormInterface $form, Request $request) {}
|
||||
|
||||
protected function onPreRemove(string $action, $entity, FormInterface $form, Request $request)
|
||||
{
|
||||
}
|
||||
protected function onPreRemove(string $action, $entity, FormInterface $form, Request $request) {}
|
||||
|
||||
/**
|
||||
* Add ordering fields in the query build by self::queryEntities.
|
||||
|
Reference in New Issue
Block a user