From 69a56fb433e288a37d00b7a083db3d1e09e7bb6c Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Wed, 5 May 2021 12:15:18 +0200 Subject: [PATCH 1/8] Update repositories service discovery. --- .../DependencyInjection/ChillPersonExtension.php | 1 - src/Bundle/ChillPersonBundle/config/services.yaml | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php b/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php index effe9750f..81985886a 100644 --- a/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php +++ b/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php @@ -73,7 +73,6 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac $loader->load('services/command.yaml'); $loader->load('services/actions.yaml'); $loader->load('services/form.yaml'); - $loader->load('services/repository.yaml'); $loader->load('services/templating.yaml'); $loader->load('services/alt_names.yaml'); $loader->load('services/serializer.yaml'); diff --git a/src/Bundle/ChillPersonBundle/config/services.yaml b/src/Bundle/ChillPersonBundle/config/services.yaml index 9011e9593..3d7450768 100644 --- a/src/Bundle/ChillPersonBundle/config/services.yaml +++ b/src/Bundle/ChillPersonBundle/config/services.yaml @@ -34,3 +34,7 @@ services: - "%chill_person.validation.birtdate_not_before%" tags: - { name: validator.constraint_validator, alias: birthdate_not_before } + + Chill\PersonBundle\Repository\: + resource: '../Repository/' + tags: ['doctrine.repository_service'] From 86dbe527d8fb1b9f54e9c7543cc9c5351d13623c Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Tue, 11 May 2021 09:43:20 +0200 Subject: [PATCH 2/8] Adding missing arguments for services --- src/Bundle/ChillPersonBundle/config/services.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/config/services.yaml b/src/Bundle/ChillPersonBundle/config/services.yaml index 3d7450768..e4924d0c3 100644 --- a/src/Bundle/ChillPersonBundle/config/services.yaml +++ b/src/Bundle/ChillPersonBundle/config/services.yaml @@ -3,7 +3,6 @@ parameters: services: - chill.person.form.type.select2maritalstatus: class: Chill\PersonBundle\Form\Type\Select2MaritalStatusType arguments: @@ -27,7 +26,7 @@ services: public: true tags: - { name: chill.timeline, context: 'person' } - + chill.person.birthdate_validation: class: Chill\PersonBundle\Validator\Constraints\BirthdateValidator arguments: @@ -37,4 +36,6 @@ services: Chill\PersonBundle\Repository\: resource: '../Repository/' + arguments: + - '@Doctrine\Persistence\ManagerRegistry' tags: ['doctrine.repository_service'] From ed4f1344c234893c18a557454629a086d4c7ab95 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Tue, 11 May 2021 21:02:31 +0200 Subject: [PATCH 3/8] Service autodiscovery, autowire and autoconfigure. --- .../ChillPersonBundle/config/services.yaml | 5 ++-- .../config/services/repository.yaml | 27 ++----------------- 2 files changed, 5 insertions(+), 27 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/config/services.yaml b/src/Bundle/ChillPersonBundle/config/services.yaml index e4924d0c3..23aca6f35 100644 --- a/src/Bundle/ChillPersonBundle/config/services.yaml +++ b/src/Bundle/ChillPersonBundle/config/services.yaml @@ -2,6 +2,9 @@ parameters: # cl_chill_person.example.class: Chill\PersonBundle\Example services: + _defaults: + autowire: true + autoconfigure: true chill.person.form.type.select2maritalstatus: class: Chill\PersonBundle\Form\Type\Select2MaritalStatusType @@ -36,6 +39,4 @@ services: Chill\PersonBundle\Repository\: resource: '../Repository/' - arguments: - - '@Doctrine\Persistence\ManagerRegistry' tags: ['doctrine.repository_service'] diff --git a/src/Bundle/ChillPersonBundle/config/services/repository.yaml b/src/Bundle/ChillPersonBundle/config/services/repository.yaml index b99402bcf..e5ce06149 100644 --- a/src/Bundle/ChillPersonBundle/config/services/repository.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/repository.yaml @@ -2,29 +2,6 @@ services: chill.person.repository.person: class: Chill\PersonBundle\Repository\PersonRepository - factory: ['@doctrine.orm.entity_manager', getRepository] - arguments: - - 'Chill\PersonBundle\Entity\Person' + autowire: true + autoconfigure: true Chill\PersonBundle\Repository\PersonRepository: '@chill.person.repository.person' - - Chill\PersonBundle\Repository\AccompanyingPeriod\ClosingMotiveRepository: - class: Chill\PersonBundle\Repository\AccompanyingPeriod\ClosingMotiveRepository - factory: ['@doctrine.orm.entity_manager', getRepository] - arguments: - - 'Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive' - - Chill\PersonBundle\Repository\AccompanyingPeriodRepository: - class: Chill\PersonBundle\Repository\AccompanyingPeriodRepository - tags: [ doctrine.repository_service ] - arguments: - - '@Doctrine\Persistence\ManagerRegistry' - - Chill\PersonBundle\Repository\AccompanyingPeriodParticipationRepository: - arguments: - - '@Doctrine\Persistence\ManagerRegistry' - tags: [ doctrine.repository_service ] - - Chill\PersonBundle\Repository\AccompanyingPeriod\OriginRepository: - arguments: - - '@Doctrine\Persistence\ManagerRegistry' - tags: [ doctrine.repository_service ] From ce854cb58f9695db60e9a5e27726c3d4f791e196 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Tue, 11 May 2021 20:52:01 +0200 Subject: [PATCH 4/8] refactor: Upgrade repositories. --- .../AccompanyingPeriodWorkGoalRepository.php | 12 +++++---- .../AccompanyingPeriodWorkRepository.php | 12 +++++---- .../ClosingMotiveRepository.php | 27 ++++++++++++------- .../AccompanyingPeriod/CommentRepository.php | 13 ++++----- .../AccompanyingPeriod/OriginRepository.php | 15 ++++++----- .../AccompanyingPeriod/ResourceRepository.php | 15 ++++++----- ...ompanyingPeriodParticipationRepository.php | 13 ++++----- .../AccompanyingPeriodRepository.php | 13 ++++----- .../Household/HouseholdMembersRepository.php | 12 +++++---- .../Household/HouseholdRepository.php | 12 +++++---- .../Repository/PersonAltNameRepository.php | 12 ++++++++- .../PersonNotDuplicateRepository.php | 12 +++++++-- .../Repository/PersonRepository.php | 25 +++++++++++------ .../SocialWork/EvaluationRepository.php | 12 +++++---- .../Repository/SocialWork/GoalRepository.php | 12 +++++---- .../SocialWork/ResultRepository.php | 12 +++++---- .../SocialWork/SocialActionRepository.php | 12 +++++---- .../SocialWork/SocialIssueRepository.php | 11 +++++--- 18 files changed, 156 insertions(+), 96 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkGoalRepository.php b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkGoalRepository.php index fc8233d23..d9fa5b6e3 100644 --- a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkGoalRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkGoalRepository.php @@ -3,8 +3,8 @@ namespace Chill\PersonBundle\Repository\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkGoal; -use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; -use Doctrine\Persistence\ManagerRegistry; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\EntityRepository; /** * @method AccompanyingPeriodWorkGoal|null find($id, $lockMode = null, $lockVersion = null) @@ -12,10 +12,12 @@ use Doctrine\Persistence\ManagerRegistry; * @method AccompanyingPeriodWorkGoal[] findAll() * @method AccompanyingPeriodWorkGoal[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) */ -class AccompanyingPeriodWorkGoalRepository extends ServiceEntityRepository +final class AccompanyingPeriodWorkGoalRepository { - public function __construct(ManagerRegistry $registry) + private EntityRepository $repository; + + public function __construct(EntityManagerInterface $entityManager) { - parent::__construct($registry, AccompanyingPeriodWorkGoal::class); + $this->repository = $entityManager->getRepository(AccompanyingPeriodWorkGoal::class); } } diff --git a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php index f879e97d7..5d455b617 100644 --- a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php @@ -3,8 +3,8 @@ namespace Chill\PersonBundle\Repository\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork; -use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; -use Doctrine\Persistence\ManagerRegistry; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\EntityRepository; /** * @method AccompanyingPeriodWork|null find($id, $lockMode = null, $lockVersion = null) @@ -12,10 +12,12 @@ use Doctrine\Persistence\ManagerRegistry; * @method AccompanyingPeriodWork[] findAll() * @method AccompanyingPeriodWork[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) */ -class AccompanyingPeriodWorkRepository extends ServiceEntityRepository +final class AccompanyingPeriodWorkRepository { - public function __construct(ManagerRegistry $registry) + private EntityRepository $repository; + + public function __construct(EntityManagerInterface $entityManager) { - parent::__construct($registry, AccompanyingPeriodWork::class); + $this->repository = $entityManager->getRepository(AccompanyingPeriodWork::class); } } diff --git a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/ClosingMotiveRepository.php b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/ClosingMotiveRepository.php index ef1130b62..c99ca8efc 100644 --- a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/ClosingMotiveRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/ClosingMotiveRepository.php @@ -22,8 +22,9 @@ namespace Chill\PersonBundle\Repository\AccompanyingPeriod; +use Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; -use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\Query\ResultSetMappingBuilder; /** @@ -32,17 +33,24 @@ use Doctrine\ORM\Query\ResultSetMappingBuilder; * * @package Chill\PersonBundle\Repository */ -class ClosingMotiveRepository extends EntityRepository +final class ClosingMotiveRepository { + private EntityRepository $repository; + + public function __construct(EntityManagerInterface $entityManager) + { + $this->repository = $entityManager->getRepository(ClosingMotive::class); + } + /** * @param bool $onlyLeaf * @return mixed */ public function getActiveClosingMotive(bool $onlyLeaf = true) { - $rsm = new ResultSetMappingBuilder($this->getEntityManager()); - $rsm->addRootEntityFromClassMetadata($this->getClassName(), 'cm'); - + $rsm = new ResultSetMappingBuilder($this->repository->getEntityManager()); + $rsm->addRootEntityFromClassMetadata($this->repository->getClassName(), 'cm'); + $sql = "SELECT ".(string) $rsm." FROM chill_person_accompanying_period_closingmotive AS cm WHERE @@ -55,10 +63,11 @@ class ClosingMotiveRepository extends EntityRepository } $sql .= " ORDER BY cm.ordering ASC"; - - return $this->_em + + return $this + ->repository + ->getEntityManager() ->createNativeQuery($sql, $rsm) - ->getResult() - ; + ->getResult(); } } diff --git a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/CommentRepository.php b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/CommentRepository.php index b41e77591..aca7a9c68 100644 --- a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/CommentRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/CommentRepository.php @@ -23,8 +23,8 @@ namespace Chill\PersonBundle\Repository\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriod\Comment; -use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; -use Doctrine\Persistence\ManagerRegistry; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\EntityRepository; /** * @method Comment|null find($id, $lockMode = null, $lockVersion = null) @@ -32,11 +32,12 @@ use Doctrine\Persistence\ManagerRegistry; * @method Comment[] findAll() * @method Comment[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) */ -class CommentRepository extends ServiceEntityRepository +final class CommentRepository { - public function __construct(ManagerRegistry $registry) + private EntityRepository $repository; + + public function __construct(EntityManagerInterface $entityManager) { - parent::__construct($registry, Comment::class); + $this->repository = $entityManager->getRepository(Comment::class); } - } diff --git a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/OriginRepository.php b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/OriginRepository.php index 6a5b28901..c2851b851 100644 --- a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/OriginRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/OriginRepository.php @@ -23,8 +23,8 @@ namespace Chill\PersonBundle\Repository\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriod\Origin; -use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; -use Doctrine\Persistence\ManagerRegistry; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\EntityRepository; /** * @method Origin|null find($id, $lockMode = null, $lockVersion = null) @@ -32,11 +32,12 @@ use Doctrine\Persistence\ManagerRegistry; * @method Origin[] findAll() * @method Origin[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) */ -class OriginRepository extends ServiceEntityRepository +final class OriginRepository { - public function __construct(ManagerRegistry $registry) - { - parent::__construct($registry, Origin::class); - } + private EntityRepository $repository; + public function __construct(EntityManagerInterface $entityManager) + { + $this->repository = $entityManager->getRepository(Origin::class); + } } diff --git a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/ResourceRepository.php b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/ResourceRepository.php index 46eaaaaa0..4f625b59c 100644 --- a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/ResourceRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/ResourceRepository.php @@ -23,8 +23,8 @@ namespace Chill\PersonBundle\Repository\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriod\Resource; -use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; -use Doctrine\Persistence\ManagerRegistry; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\EntityRepository; /** * @method Resource|null find($id, $lockMode = null, $lockVersion = null) @@ -32,11 +32,12 @@ use Doctrine\Persistence\ManagerRegistry; * @method Resource[] findAll() * @method Resource[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) */ -class ResourceRepository extends ServiceEntityRepository +final class ResourceRepository { - public function __construct(ManagerRegistry $registry) - { - parent::__construct($registry, Resource::class); - } + private EntityRepository $repository; + public function __construct(EntityManagerInterface $entityManager) + { + $this->repository = $entityManager->getRepository(Resource::class); + } } diff --git a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriodParticipationRepository.php b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriodParticipationRepository.php index fbe957ecf..0f157ed42 100644 --- a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriodParticipationRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriodParticipationRepository.php @@ -23,8 +23,8 @@ namespace Chill\PersonBundle\Repository; use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation; -use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; -use Doctrine\Persistence\ManagerRegistry; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\EntityRepository; /** * @method AccompanyingPeriodParticipation|null find($id, $lockMode = null, $lockVersion = null) @@ -32,11 +32,12 @@ use Doctrine\Persistence\ManagerRegistry; * @method AccompanyingPeriodParticipation[] findAll() * @method AccompanyingPeriodParticipation[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) */ -class AccompanyingPeriodParticipationRepository extends ServiceEntityRepository +final class AccompanyingPeriodParticipationRepository { - public function __construct(ManagerRegistry $registry) + private EntityRepository $repository; + + public function __construct(EntityManagerInterface $entityManager) { - parent::__construct($registry, AccompanyingPeriodParticipation::class); + $this->repository = $entityManager->getRepository(AccompanyingPeriodParticipation::class); } - } diff --git a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriodRepository.php b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriodRepository.php index fffb55ede..07aa0a55f 100644 --- a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriodRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriodRepository.php @@ -23,9 +23,8 @@ namespace Chill\PersonBundle\Repository; use Chill\PersonBundle\Entity\AccompanyingPeriod; -use Chill\PersonBundle\Entity\Person; -use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; -use Doctrine\Persistence\ManagerRegistry; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\EntityRepository; /** * @method AccompanyingPeriod|null find($id, $lockMode = null, $lockVersion = null) @@ -33,10 +32,12 @@ use Doctrine\Persistence\ManagerRegistry; * @method AccompanyingPeriod[] findAll() * @method AccompanyingPeriod[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) */ -class AccompanyingPeriodRepository extends ServiceEntityRepository +final class AccompanyingPeriodRepository { - public function __construct(ManagerRegistry $registry) + private EntityRepository $repository; + + public function __construct(EntityManagerInterface $entityManager) { - parent::__construct($registry, AccompanyingPeriod::class); + $this->repository = $entityManager->getRepository(AccompanyingPeriod::class); } } diff --git a/src/Bundle/ChillPersonBundle/Repository/Household/HouseholdMembersRepository.php b/src/Bundle/ChillPersonBundle/Repository/Household/HouseholdMembersRepository.php index feea6d44d..b11d3d93a 100644 --- a/src/Bundle/ChillPersonBundle/Repository/Household/HouseholdMembersRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/Household/HouseholdMembersRepository.php @@ -3,8 +3,8 @@ namespace Chill\PersonBundle\Repository\Household; use Chill\PersonBundle\Entity\Household\HouseholdMembers; -use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; -use Doctrine\Persistence\ManagerRegistry; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\EntityRepository; /** * @method HouseholdMembers|null find($id, $lockMode = null, $lockVersion = null) @@ -12,11 +12,13 @@ use Doctrine\Persistence\ManagerRegistry; * @method HouseholdMembers[] findAll() * @method HouseholdMembers[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) */ -class HouseholdMembersRepository extends ServiceEntityRepository +final class HouseholdMembersRepository { - public function __construct(ManagerRegistry $registry) + private EntityRepository $repository; + + public function __construct(EntityManagerInterface $entityManager) { - parent::__construct($registry, HouseholdMembers::class); + $this->repository = $entityManager->getRepository(HouseholdMembers::class); } // /** diff --git a/src/Bundle/ChillPersonBundle/Repository/Household/HouseholdRepository.php b/src/Bundle/ChillPersonBundle/Repository/Household/HouseholdRepository.php index 38522806c..78a68f56d 100644 --- a/src/Bundle/ChillPersonBundle/Repository/Household/HouseholdRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/Household/HouseholdRepository.php @@ -3,8 +3,8 @@ namespace Chill\PersonBundle\Repository\Household; use Chill\PersonBundle\Entity\Household\Household; -use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; -use Doctrine\Persistence\ManagerRegistry; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\EntityRepository; /** * @method Household|null find($id, $lockMode = null, $lockVersion = null) @@ -12,11 +12,13 @@ use Doctrine\Persistence\ManagerRegistry; * @method Household[] findAll() * @method Household[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) */ -class HouseholdRepository extends ServiceEntityRepository +final class HouseholdRepository { - public function __construct(ManagerRegistry $registry) + private EntityRepository $repository; + + public function __construct(EntityManagerInterface $entityManager) { - parent::__construct($registry, Household::class); + $this->repository = $entityManager->getRepository(Household::class); } // /** diff --git a/src/Bundle/ChillPersonBundle/Repository/PersonAltNameRepository.php b/src/Bundle/ChillPersonBundle/Repository/PersonAltNameRepository.php index 315cee94f..c5dea689a 100644 --- a/src/Bundle/ChillPersonBundle/Repository/PersonAltNameRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/PersonAltNameRepository.php @@ -2,12 +2,22 @@ namespace Chill\PersonBundle\Repository; +use Chill\PersonBundle\Entity\PersonAltName; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\EntityRepository; + /** * PersonAltNameRepository * * This class was generated by the Doctrine ORM. Add your own custom * repository methods below. */ -class PersonAltNameRepository extends \Doctrine\ORM\EntityRepository +final class PersonAltNameRepository { + private EntityRepository $repository; + + public function __construct(EntityManagerInterface $entityManager) + { + $this->repository = $entityManager->getRepository(PersonAltName::class); + } } diff --git a/src/Bundle/ChillPersonBundle/Repository/PersonNotDuplicateRepository.php b/src/Bundle/ChillPersonBundle/Repository/PersonNotDuplicateRepository.php index 8ab711b15..989baaeec 100644 --- a/src/Bundle/ChillPersonBundle/Repository/PersonNotDuplicateRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/PersonNotDuplicateRepository.php @@ -4,6 +4,7 @@ namespace Chill\PersonBundle\Repository; use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\PersonNotDuplicate; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; /** @@ -11,8 +12,15 @@ use Doctrine\ORM\EntityRepository; * * @package Chill\PersonBundle\Repository */ -class PersonNotDuplicateRepository extends EntityRepository +final class PersonNotDuplicateRepository { + private EntityRepository $repository; + + public function __construct(EntityManagerInterface $entityManager) + { + $this->repository = $entityManager->getRepository(PersonNotDuplicate::class); + } + /** * @param \Chill\PersonBundle\Entity\Person $person * @@ -20,7 +28,7 @@ class PersonNotDuplicateRepository extends EntityRepository */ public function findNotDuplicatePerson(Person $person) { - $qb = $this->createQueryBuilder('pnd'); + $qb = $this->repository->createQueryBuilder('pnd'); $qb->select('pnd') ->where('pnd.person1 = :person OR pnd.person2 = :person') ; diff --git a/src/Bundle/ChillPersonBundle/Repository/PersonRepository.php b/src/Bundle/ChillPersonBundle/Repository/PersonRepository.php index ccc56b639..12733a668 100644 --- a/src/Bundle/ChillPersonBundle/Repository/PersonRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/PersonRepository.php @@ -18,16 +18,25 @@ namespace Chill\PersonBundle\Repository; +use Chill\PersonBundle\Entity\Person; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\QueryBuilder; -/** - * Class PersonRepository - * - * @package Chill\PersonBundle\Repository - */ -class PersonRepository extends EntityRepository +final class PersonRepository { + private EntityRepository $repository; + + public function __construct(EntityManagerInterface $entityManager) + { + $this->repository = $entityManager->getRepository(Person::class); + } + + public function find($id, $lockMode = null, $lockVersion = null) + { + return $this->repository->find($id, $lockMode, $lockVersion); + } + /** * @param string $phonenumber * @param $centers @@ -44,7 +53,7 @@ class PersonRepository extends EntityRepository $maxResults, array $only = ['mobile', 'phone'] ) { - $qb = $this->createQueryBuilder('p'); + $qb = $this->repository->createQueryBuilder('p'); $qb->select('p'); $this->addByCenters($qb, $centers); @@ -71,7 +80,7 @@ class PersonRepository extends EntityRepository array $only = ['mobile', 'phone'] ): int { - $qb = $this->createQueryBuilder('p'); + $qb = $this->repository->createQueryBuilder('p'); $qb->select('COUNT(p)'); $this->addByCenters($qb, $centers); diff --git a/src/Bundle/ChillPersonBundle/Repository/SocialWork/EvaluationRepository.php b/src/Bundle/ChillPersonBundle/Repository/SocialWork/EvaluationRepository.php index b030e1617..c9ab3c931 100644 --- a/src/Bundle/ChillPersonBundle/Repository/SocialWork/EvaluationRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/SocialWork/EvaluationRepository.php @@ -3,8 +3,8 @@ namespace Chill\PersonBundle\Repository\SocialWork; use Chill\PersonBundle\Entity\SocialWork\Evaluation; -use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; -use Doctrine\Persistence\ManagerRegistry; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\EntityRepository; /** * @method Evaluation|null find($id, $lockMode = null, $lockVersion = null) @@ -12,10 +12,12 @@ use Doctrine\Persistence\ManagerRegistry; * @method Evaluation[] findAll() * @method Evaluation[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) */ -class EvaluationRepository extends ServiceEntityRepository +final class EvaluationRepository { - public function __construct(ManagerRegistry $registry) + private EntityRepository $repository; + + public function __construct(EntityManagerInterface $entityManager) { - parent::__construct($registry, Evaluation::class); + $this->repository = $entityManager->getRepository(Evaluation::class); } } diff --git a/src/Bundle/ChillPersonBundle/Repository/SocialWork/GoalRepository.php b/src/Bundle/ChillPersonBundle/Repository/SocialWork/GoalRepository.php index 031c31764..30576b4ed 100644 --- a/src/Bundle/ChillPersonBundle/Repository/SocialWork/GoalRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/SocialWork/GoalRepository.php @@ -3,8 +3,8 @@ namespace Chill\PersonBundle\Repository\SocialWork; use Chill\PersonBundle\Entity\SocialWork\Goal; -use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; -use Doctrine\Persistence\ManagerRegistry; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\EntityRepository; /** * @method Goal|null find($id, $lockMode = null, $lockVersion = null) @@ -12,10 +12,12 @@ use Doctrine\Persistence\ManagerRegistry; * @method Goal[] findAll() * @method Goal[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) */ -class GoalRepository extends ServiceEntityRepository +final class GoalRepository { - public function __construct(ManagerRegistry $registry) + private EntityRepository $repository; + + public function __construct(EntityManagerInterface $entityManager) { - parent::__construct($registry, Goal::class); + $this->repository = $entityManager->getRepository(Goal::class); } } diff --git a/src/Bundle/ChillPersonBundle/Repository/SocialWork/ResultRepository.php b/src/Bundle/ChillPersonBundle/Repository/SocialWork/ResultRepository.php index 511823d61..004a2f82c 100644 --- a/src/Bundle/ChillPersonBundle/Repository/SocialWork/ResultRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/SocialWork/ResultRepository.php @@ -3,8 +3,8 @@ namespace Chill\PersonBundle\Repository\SocialWork; use Chill\PersonBundle\Entity\SocialWork\Result; -use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; -use Doctrine\Persistence\ManagerRegistry; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\EntityRepository; /** * @method Result|null find($id, $lockMode = null, $lockVersion = null) @@ -12,10 +12,12 @@ use Doctrine\Persistence\ManagerRegistry; * @method Result[] findAll() * @method Result[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) */ -class ResultRepository extends ServiceEntityRepository +final class ResultRepository { - public function __construct(ManagerRegistry $registry) + private EntityRepository $repository; + + public function __construct(EntityManagerInterface $entityManager) { - parent::__construct($registry, Result::class); + $this->repository = $entityManager->getRepository(Result::class); } } diff --git a/src/Bundle/ChillPersonBundle/Repository/SocialWork/SocialActionRepository.php b/src/Bundle/ChillPersonBundle/Repository/SocialWork/SocialActionRepository.php index f0f2e81b4..cfa9adbd7 100644 --- a/src/Bundle/ChillPersonBundle/Repository/SocialWork/SocialActionRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/SocialWork/SocialActionRepository.php @@ -3,8 +3,8 @@ namespace Chill\PersonBundle\Repository\SocialWork; use Chill\PersonBundle\Entity\SocialWork\SocialAction; -use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; -use Doctrine\Persistence\ManagerRegistry; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\EntityRepository; /** * @method SocialAction|null find($id, $lockMode = null, $lockVersion = null) @@ -12,10 +12,12 @@ use Doctrine\Persistence\ManagerRegistry; * @method SocialAction[] findAll() * @method SocialAction[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) */ -class SocialActionRepository extends ServiceEntityRepository +final class SocialActionRepository { - public function __construct(ManagerRegistry $registry) + private EntityRepository $repository; + + public function __construct(EntityManagerInterface $entityManager) { - parent::__construct($registry, SocialAction::class); + $this->repository = $entityManager->getRepository(SocialAction::class); } } diff --git a/src/Bundle/ChillPersonBundle/Repository/SocialWork/SocialIssueRepository.php b/src/Bundle/ChillPersonBundle/Repository/SocialWork/SocialIssueRepository.php index e64b057f4..2f6eb3ba1 100644 --- a/src/Bundle/ChillPersonBundle/Repository/SocialWork/SocialIssueRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/SocialWork/SocialIssueRepository.php @@ -4,7 +4,8 @@ namespace Chill\PersonBundle\Repository\SocialWork; use Chill\PersonBundle\Entity\SocialWork\SocialIssue; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; -use Doctrine\Persistence\ManagerRegistry; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\EntityRepository; /** * @method SocialIssue|null find($id, $lockMode = null, $lockVersion = null) @@ -12,10 +13,12 @@ use Doctrine\Persistence\ManagerRegistry; * @method SocialIssue[] findAll() * @method SocialIssue[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) */ -class SocialIssueRepository extends ServiceEntityRepository +final class SocialIssueRepository { - public function __construct(ManagerRegistry $registry) + private EntityRepository $repository; + + public function __construct(EntityManagerInterface $entityManager) { - parent::__construct($registry, SocialIssue::class); + $this->repository = $entityManager->getRepository(SocialIssue::class); } } From 3fc6c0c47927af7f24b56ef3eaa394a5a3f4830f Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Tue, 11 May 2021 21:00:20 +0200 Subject: [PATCH 5/8] refactor: Update entities. --- src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php | 2 +- .../Entity/AccompanyingPeriod/AccompanyingPeriodWork.php | 3 +-- .../Entity/AccompanyingPeriod/AccompanyingPeriodWorkGoal.php | 3 +-- .../Entity/AccompanyingPeriod/ClosingMotive.php | 3 +-- .../ChillPersonBundle/Entity/AccompanyingPeriod/Comment.php | 3 +-- .../ChillPersonBundle/Entity/AccompanyingPeriod/Origin.php | 3 +-- .../ChillPersonBundle/Entity/AccompanyingPeriod/Resource.php | 3 +-- .../Entity/AccompanyingPeriodParticipation.php | 3 +-- src/Bundle/ChillPersonBundle/Entity/Household/Household.php | 3 +-- .../ChillPersonBundle/Entity/Household/HouseholdMembers.php | 3 +-- src/Bundle/ChillPersonBundle/Entity/MaritalStatus.php | 2 +- src/Bundle/ChillPersonBundle/Entity/Person.php | 2 +- src/Bundle/ChillPersonBundle/Entity/PersonAltName.php | 2 +- src/Bundle/ChillPersonBundle/Entity/PersonNotDuplicate.php | 2 +- src/Bundle/ChillPersonBundle/Entity/PersonPhone.php | 2 +- src/Bundle/ChillPersonBundle/Entity/SocialWork/Evaluation.php | 3 +-- src/Bundle/ChillPersonBundle/Entity/SocialWork/Goal.php | 3 +-- src/Bundle/ChillPersonBundle/Entity/SocialWork/Result.php | 3 +-- .../ChillPersonBundle/Entity/SocialWork/SocialAction.php | 3 +-- .../ChillPersonBundle/Entity/SocialWork/SocialIssue.php | 4 +--- 20 files changed, 20 insertions(+), 35 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php index 7c451200e..8ec017c07 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php @@ -37,7 +37,7 @@ use Chill\MainBundle\Entity\User; /** * AccompanyingPeriod Class * - * @ORM\Entity(repositoryClass="Chill\PersonBundle\Repository\AccompanyingPeriodRepository") + * @ORM\Entity * @ORM\Table(name="chill_person_accompanying_period") */ class AccompanyingPeriod diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php index 6983f6c0e..25fbcc342 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php @@ -4,7 +4,6 @@ namespace Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\SocialWork\Result; use Chill\PersonBundle\Entity\SocialWork\SocialAction; -use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepository; use Chill\MainBundle\Entity\User; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\ThirdPartyBundle\Entity\ThirdParty; @@ -13,7 +12,7 @@ use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; /** - * @ORM\Entity(repositoryClass=AccompanyingPeriodWorkRepository::class) + * @ORM\Entity * @ORM\Table(name="chill_person_accompanying_period_work") */ class AccompanyingPeriodWork diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWorkGoal.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWorkGoal.php index ec371d6c2..955f9e3a1 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWorkGoal.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWorkGoal.php @@ -4,13 +4,12 @@ namespace Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\SocialWork\Goal; use Chill\PersonBundle\Entity\SocialWork\Result; -use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkGoalRepository; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; /** - * @ORM\Entity(repositoryClass=AccompanyingPeriodWorkGoalRepository::class) + * @ORM\Entity * @ORM\Table(name="chill_person_accompanying_period_work_goal") */ class AccompanyingPeriodWorkGoal diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/ClosingMotive.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/ClosingMotive.php index 4e334b2aa..29b2a44aa 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/ClosingMotive.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/ClosingMotive.php @@ -29,8 +29,7 @@ use Doctrine\Common\Collections\ArrayCollection; /** * ClosingMotive give an explanation why we closed the Accompanying period * - * @ORM\Entity( - * repositoryClass="Chill\PersonBundle\Repository\AccompanyingPeriod\ClosingMotiveRepository") + * @ORM\Entity * @ORM\Table(name="chill_person_accompanying_period_closingmotive") */ class ClosingMotive diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/Comment.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/Comment.php index e8ecf3248..60b3466cd 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/Comment.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/Comment.php @@ -22,13 +22,12 @@ namespace Chill\PersonBundle\Entity\AccompanyingPeriod; -use Chill\PersonBundle\Repository\AccompanyingPeriod\CommentRepository; use Chill\MainBundle\Entity\User; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Doctrine\ORM\Mapping as ORM; /** - * @ORM\Entity(repositoryClass=CommentRepository::class) + * @ORM\Entity * @ORM\Table(name="chill_person_accompanying_period_comment") */ class Comment diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/Origin.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/Origin.php index 55857de4c..a852e166e 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/Origin.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/Origin.php @@ -22,11 +22,10 @@ namespace Chill\PersonBundle\Entity\AccompanyingPeriod; -use Chill\PersonBundle\Repository\AccompanyingPeriod\OriginRepository; use Doctrine\ORM\Mapping as ORM; /** - * @ORM\Entity(repositoryClass=OriginRepository::class) + * @ORM\Entity * @ORM\Table(name="chill_person_accompanying_period_origin") */ class Origin diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/Resource.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/Resource.php index ec13fcad6..0cfefba87 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/Resource.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/Resource.php @@ -22,7 +22,6 @@ namespace Chill\PersonBundle\Entity\AccompanyingPeriod; -use Chill\PersonBundle\Repository\AccompanyingPeriod\ResourceRepository; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriod\Comment; use Chill\PersonBundle\Entity\Person; @@ -30,7 +29,7 @@ use Chill\ThirdPartyBundle\Entity\ThirdParty; use Doctrine\ORM\Mapping as ORM; /** - * @ORM\Entity(repositoryClass=ResourceRepository::class) + * @ORM\Entity * @ORM\Table(name="chill_person_accompanying_period_resource") */ class Resource diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriodParticipation.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriodParticipation.php index c22e84e42..d57d00386 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriodParticipation.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriodParticipation.php @@ -22,7 +22,6 @@ namespace Chill\PersonBundle\Entity; -use Chill\PersonBundle\Repository\AccompanyingPeriodParticipationRepository; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\Person; use Doctrine\ORM\Mapping as ORM; @@ -31,7 +30,7 @@ use Doctrine\ORM\Mapping as ORM; * AccompanyingPeriodParticipation Class * * @package Chill\PersonBundle\Entity - * @ORM\Entity(repositoryClass=AccompanyingPeriodParticipationRepository::class) + * @ORM\Entity * @ORM\Table(name="chill_person_accompanying_period_participation") */ class AccompanyingPeriodParticipation diff --git a/src/Bundle/ChillPersonBundle/Entity/Household/Household.php b/src/Bundle/ChillPersonBundle/Entity/Household/Household.php index a12741dee..4e8787a96 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Household/Household.php +++ b/src/Bundle/ChillPersonBundle/Entity/Household/Household.php @@ -2,13 +2,12 @@ namespace Chill\PersonBundle\Entity\Household; -use Chill\PersonBundle\Repository\Household\HouseholdRepository; use Doctrine\ORM\Mapping as ORM; use Doctrine\Common\Collections\Collection; use Chill\MainBundle\Entity\Address; /** - * @ORM\Entity(repositoryClass=HouseholdRepository::class) + * @ORM\Entity */ class Household { diff --git a/src/Bundle/ChillPersonBundle/Entity/Household/HouseholdMembers.php b/src/Bundle/ChillPersonBundle/Entity/Household/HouseholdMembers.php index 80864ecd0..5d16649a8 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Household/HouseholdMembers.php +++ b/src/Bundle/ChillPersonBundle/Entity/Household/HouseholdMembers.php @@ -3,12 +3,11 @@ namespace Chill\PersonBundle\Entity\Household; use Doctrine\ORM\Mapping as ORM; -use Chill\PersonBundle\Repository\Household\HouseholdMembersRepository; use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Household\Household; /** - * @ORM\Entity(repositoryClass=HouseholdMembersRepository::class) + * @ORM\Entity */ class HouseholdMembers { diff --git a/src/Bundle/ChillPersonBundle/Entity/MaritalStatus.php b/src/Bundle/ChillPersonBundle/Entity/MaritalStatus.php index f1addbb2c..43ae1b09f 100644 --- a/src/Bundle/ChillPersonBundle/Entity/MaritalStatus.php +++ b/src/Bundle/ChillPersonBundle/Entity/MaritalStatus.php @@ -25,7 +25,7 @@ use Doctrine\ORM\Mapping as ORM; /** * MaritalStatus * - * @ORM\Entity() + * @ORM\Entity * @ORM\Table(name="chill_person_marital_status") * @ORM\HasLifecycleCallbacks() */ diff --git a/src/Bundle/ChillPersonBundle/Entity/Person.php b/src/Bundle/ChillPersonBundle/Entity/Person.php index 3624d4c17..e88998205 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person.php @@ -38,7 +38,7 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface; /** * Person Class * - * @ORM\Entity(repositoryClass="Chill\PersonBundle\Repository\PersonRepository") + * @ORM\Entity * @ORM\Table(name="chill_person_person", * indexes={@ORM\Index( * name="person_names", diff --git a/src/Bundle/ChillPersonBundle/Entity/PersonAltName.php b/src/Bundle/ChillPersonBundle/Entity/PersonAltName.php index c5295487e..95603d4ef 100644 --- a/src/Bundle/ChillPersonBundle/Entity/PersonAltName.php +++ b/src/Bundle/ChillPersonBundle/Entity/PersonAltName.php @@ -8,7 +8,7 @@ use Doctrine\ORM\Mapping as ORM; * PersonAltName * * @ORM\Table(name="chill_person_alt_name") - * @ORM\Entity(repositoryClass="Chill\PersonBundle\Repository\PersonAltNameRepository") + * @ORM\Entity */ class PersonAltName { diff --git a/src/Bundle/ChillPersonBundle/Entity/PersonNotDuplicate.php b/src/Bundle/ChillPersonBundle/Entity/PersonNotDuplicate.php index ce2a1c26f..9f116c501 100644 --- a/src/Bundle/ChillPersonBundle/Entity/PersonNotDuplicate.php +++ b/src/Bundle/ChillPersonBundle/Entity/PersonNotDuplicate.php @@ -9,7 +9,7 @@ use Chill\MainBundle\Entity\User; * PersonNotDuplicate * * @ORM\Table(name="chill_person_not_duplicate") - * @ORM\Entity(repositoryClass="Chill\PersonBundle\Repository\PersonNotDuplicateRepository") + * @ORM\Entity */ class PersonNotDuplicate { diff --git a/src/Bundle/ChillPersonBundle/Entity/PersonPhone.php b/src/Bundle/ChillPersonBundle/Entity/PersonPhone.php index 4a2ffaf28..222495e17 100644 --- a/src/Bundle/ChillPersonBundle/Entity/PersonPhone.php +++ b/src/Bundle/ChillPersonBundle/Entity/PersonPhone.php @@ -8,7 +8,7 @@ use Doctrine\ORM\Mapping as ORM; /** * Person Phones * - * @ORM\Entity() + * @ORM\Entity * @ORM\Table(name="chill_person_phone") */ class PersonPhone diff --git a/src/Bundle/ChillPersonBundle/Entity/SocialWork/Evaluation.php b/src/Bundle/ChillPersonBundle/Entity/SocialWork/Evaluation.php index 9e6dcbaa6..5a877e264 100644 --- a/src/Bundle/ChillPersonBundle/Entity/SocialWork/Evaluation.php +++ b/src/Bundle/ChillPersonBundle/Entity/SocialWork/Evaluation.php @@ -2,11 +2,10 @@ namespace Chill\PersonBundle\Entity\SocialWork; -use Chill\PersonBundle\Repository\SocialWork\EvaluationRepository; use Doctrine\ORM\Mapping as ORM; /** - * @ORM\Entity(repositoryClass=EvaluationRepository::class) + * @ORM\Entity * @ORM\Table(name="chill_person_social_work_evaluation") */ class Evaluation diff --git a/src/Bundle/ChillPersonBundle/Entity/SocialWork/Goal.php b/src/Bundle/ChillPersonBundle/Entity/SocialWork/Goal.php index c92e9a736..996fcf3eb 100644 --- a/src/Bundle/ChillPersonBundle/Entity/SocialWork/Goal.php +++ b/src/Bundle/ChillPersonBundle/Entity/SocialWork/Goal.php @@ -2,13 +2,12 @@ namespace Chill\PersonBundle\Entity\SocialWork; -use Chill\PersonBundle\Repository\SocialWork\GoalRepository; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; /** - * @ORM\Entity(repositoryClass=GoalRepository::class) + * @ORM\Entity * @ORM\Table(name="chill_person_social_work_goal") */ class Goal diff --git a/src/Bundle/ChillPersonBundle/Entity/SocialWork/Result.php b/src/Bundle/ChillPersonBundle/Entity/SocialWork/Result.php index be38b1757..37e5c2b18 100644 --- a/src/Bundle/ChillPersonBundle/Entity/SocialWork/Result.php +++ b/src/Bundle/ChillPersonBundle/Entity/SocialWork/Result.php @@ -4,13 +4,12 @@ namespace Chill\PersonBundle\Entity\SocialWork; use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork; use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkGoal; -use Chill\PersonBundle\Repository\SocialWork\ResultRepository; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; /** - * @ORM\Entity(repositoryClass=ResultRepository::class) + * @ORM\Entity * @ORM\Table(name="chill_person_social_work_result") */ class Result diff --git a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php index 64413d987..ff7291b45 100644 --- a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php +++ b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialAction.php @@ -2,13 +2,12 @@ namespace Chill\PersonBundle\Entity\SocialWork; -use Chill\PersonBundle\Repository\SocialWork\SocialActionRepository; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; /** - * @ORM\Entity(repositoryClass=SocialActionRepository::class) + * @ORM\Entity * @ORM\Table(name="chill_person_social_action") */ class SocialAction diff --git a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialIssue.php b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialIssue.php index cfec01751..2b6df9be2 100644 --- a/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialIssue.php +++ b/src/Bundle/ChillPersonBundle/Entity/SocialWork/SocialIssue.php @@ -1,14 +1,12 @@ Date: Wed, 12 May 2021 15:33:18 +0200 Subject: [PATCH 6/8] Use repositories as services. --- .../ChillPersonBundle/Controller/PersonController.php | 6 +++--- .../Controller/PersonDuplicateController.php | 6 +++--- .../ChillPersonBundle/Search/SimilarPersonMatcher.php | 5 ++--- src/Bundle/ChillPersonBundle/Widget/PersonListWidget.php | 4 ++-- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Controller/PersonController.php b/src/Bundle/ChillPersonBundle/Controller/PersonController.php index bfb32654e..abba491b1 100644 --- a/src/Bundle/ChillPersonBundle/Controller/PersonController.php +++ b/src/Bundle/ChillPersonBundle/Controller/PersonController.php @@ -38,6 +38,7 @@ use Symfony\Component\Translation\TranslatorInterface; use Chill\MainBundle\Search\SearchProvider; use Chill\PersonBundle\Repository\PersonRepository; use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper; +use Chill\PersonBundle\Repository\PersonNotDuplicateRepository; use Symfony\Component\Validator\Validator\ValidatorInterface; use Doctrine\ORM\EntityManagerInterface; @@ -290,7 +291,7 @@ final class PersonController extends AbstractController return $errors; } - public function reviewAction(Request $request) + public function reviewAction(Request $request, PersonNotDuplicateRepository $personNotDuplicateRepository) { if ($request->getMethod() !== 'POST') { $r = new Response("You must send something to review the creation of a new Person"); @@ -342,8 +343,7 @@ final class PersonController extends AbstractController $this->em->persist($person); - $alternatePersons = $this->similarPersonMatcher - ->matchPerson($person); + $alternatePersons = $this->similarPersonMatcher->matchPerson($person, $personNotDuplicateRepository); if (count($alternatePersons) === 0) { return $this->forward('ChillPersonBundle:Person:create'); diff --git a/src/Bundle/ChillPersonBundle/Controller/PersonDuplicateController.php b/src/Bundle/ChillPersonBundle/Controller/PersonDuplicateController.php index aa2e2768a..48654134d 100644 --- a/src/Bundle/ChillPersonBundle/Controller/PersonDuplicateController.php +++ b/src/Bundle/ChillPersonBundle/Controller/PersonDuplicateController.php @@ -19,6 +19,7 @@ use Symfony\Component\Translation\TranslatorInterface; use Chill\ActivityBundle\Entity\Activity; use Chill\DocStoreBundle\Entity\PersonDocument; use Chill\EventBundle\Entity\Participation; +use Chill\PersonBundle\Repository\PersonNotDuplicateRepository; use Chill\TaskBundle\Entity\SingleTask; class PersonDuplicateController extends Controller @@ -62,7 +63,7 @@ class PersonDuplicateController extends Controller $this->eventDispatcher = $eventDispatcher; } - public function viewAction($person_id) + public function viewAction($person_id, PersonNotDuplicateRepository $personNotDuplicateRepository) { $person = $this->_getPerson($person_id); if ($person === null) { @@ -76,8 +77,7 @@ class PersonDuplicateController extends Controller $duplicatePersons = $this->similarPersonMatcher-> matchPerson($person, 0.5, SimilarPersonMatcher::SIMILAR_SEARCH_ORDER_BY_ALPHABETICAL); - $notDuplicatePersons = $this->getDoctrine()->getRepository(PersonNotDuplicate::class) - ->findNotDuplicatePerson($person); + $notDuplicatePersons = $personNotDuplicateRepository->findNotDuplicatePerson($person); return $this->render('ChillPersonBundle:PersonDuplicate:view.html.twig', [ 'person' => $person, diff --git a/src/Bundle/ChillPersonBundle/Search/SimilarPersonMatcher.php b/src/Bundle/ChillPersonBundle/Search/SimilarPersonMatcher.php index 956f9a4d2..c220e62e8 100644 --- a/src/Bundle/ChillPersonBundle/Search/SimilarPersonMatcher.php +++ b/src/Bundle/ChillPersonBundle/Search/SimilarPersonMatcher.php @@ -62,7 +62,7 @@ class SimilarPersonMatcher $this->tokenStorage = $tokenStorage; } - public function matchPerson(Person $person, $precision = 0.15, $orderBy = self::SIMILAR_SEARCH_ORDER_BY_SIMILARITY) + public function matchPerson(Person $person, PersonNotDuplicateRepository $personNotDuplicateRepository, $precision = 0.15, $orderBy = self::SIMILAR_SEARCH_ORDER_BY_SIMILARITY) { $centers = $this->authorizationHelper->getReachableCenters( $this->tokenStorage->getToken()->getUser(), @@ -77,8 +77,7 @@ class SimilarPersonMatcher . ' AND p.id != :personId ' ; - $notDuplicatePersons = $this->em->getRepository(PersonNotDuplicate::class) - ->findNotDuplicatePerson($person); + $notDuplicatePersons = $personNotDuplicateRepository->findNotDuplicatePerson($person); if (count($notDuplicatePersons)) { $dql .= ' AND p.id not in (:notDuplicatePersons)'; diff --git a/src/Bundle/ChillPersonBundle/Widget/PersonListWidget.php b/src/Bundle/ChillPersonBundle/Widget/PersonListWidget.php index e885e0a26..2dcbb8230 100644 --- a/src/Bundle/ChillPersonBundle/Widget/PersonListWidget.php +++ b/src/Bundle/ChillPersonBundle/Widget/PersonListWidget.php @@ -45,7 +45,7 @@ class PersonListWidget implements WidgetInterface /** * Repository for persons * - * @var EntityRepository + * @var PersonRepository */ protected $personRepository; @@ -76,7 +76,7 @@ class PersonListWidget implements WidgetInterface protected $user; public function __construct( - EntityRepository $personRepostory, + PersonRepository $personRepostory, EntityManager $em, AuthorizationHelper $authorizationHelper, TokenStorage $tokenStorage From f867f4985da23ee047e2822d970007343c491a1c Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Wed, 12 May 2021 15:14:17 +0200 Subject: [PATCH 7/8] Add a note about the custom service definition for the repository. --- .../DependencyInjection/ChillPersonExtension.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php b/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php index 81985886a..98e2d30e9 100644 --- a/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php +++ b/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php @@ -75,6 +75,9 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac $loader->load('services/form.yaml'); $loader->load('services/templating.yaml'); $loader->load('services/alt_names.yaml'); + // We can get rid of this file when the service 'chill.person.repository.person' is no more used. + // We should use the PersonRepository service instead of a custom service name. + $loader->load('services/repository.yaml'); $loader->load('services/serializer.yaml'); $loader->load('services/security.yaml'); From 893c38fba40211f6c702994d63511ea3c7343bb3 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Fri, 14 May 2021 08:20:23 +0200 Subject: [PATCH 8/8] Fix collateral things. --- .../Controller/PersonDuplicateController.php | 10 +++++----- .../Search/SimilarPersonMatcher.php | 15 ++++++++------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Controller/PersonDuplicateController.php b/src/Bundle/ChillPersonBundle/Controller/PersonDuplicateController.php index 48654134d..d30ddebae 100644 --- a/src/Bundle/ChillPersonBundle/Controller/PersonDuplicateController.php +++ b/src/Bundle/ChillPersonBundle/Controller/PersonDuplicateController.php @@ -75,7 +75,7 @@ class PersonDuplicateController extends Controller "You are not allowed to see this person."); $duplicatePersons = $this->similarPersonMatcher-> - matchPerson($person, 0.5, SimilarPersonMatcher::SIMILAR_SEARCH_ORDER_BY_ALPHABETICAL); + matchPerson($person, $personNotDuplicateRepository, 0.5, SimilarPersonMatcher::SIMILAR_SEARCH_ORDER_BY_ALPHABETICAL); $notDuplicatePersons = $personNotDuplicateRepository->findNotDuplicatePerson($person); @@ -97,7 +97,7 @@ class PersonDuplicateController extends Controller $person1->counters = $this->_getCounters($person1_id); $person2->counters = $this->_getCounters($person2_id); - + if ($person1 === null) { throw $this->createNotFoundException("Person with id $person1_id not" . " found on this server"); @@ -264,17 +264,17 @@ class PersonDuplicateController extends Controller return [$person1, $person2]; } - + private function _getCounters($id): ?array { $em = $this->getDoctrine()->getManager(); - + $nb_activity = $em->getRepository(Activity::class)->findBy(['person'=>$id]); $nb_document = $em->getRepository(PersonDocument::class)->findBy(['person'=>$id]); $nb_event = $em->getRepository(Participation::class)->findBy(['person'=>$id]); $nb_task = $em->getRepository(SingleTask::class)->countByParameters(['person'=>$id]); $person = $em->getRepository(Person::class)->findOneBy(['id'=>$id]); - + return [ 'nb_activity' => count($nb_activity), 'nb_document' => count($nb_document), diff --git a/src/Bundle/ChillPersonBundle/Search/SimilarPersonMatcher.php b/src/Bundle/ChillPersonBundle/Search/SimilarPersonMatcher.php index c220e62e8..1c564aa11 100644 --- a/src/Bundle/ChillPersonBundle/Search/SimilarPersonMatcher.php +++ b/src/Bundle/ChillPersonBundle/Search/SimilarPersonMatcher.php @@ -22,12 +22,13 @@ use Chill\PersonBundle\Entity\PersonNotDuplicate; use Doctrine\ORM\EntityManagerInterface; use Chill\PersonBundle\Entity\Person; use Chill\MainBundle\Security\Authorization\AuthorizationHelper; +use Chill\PersonBundle\Repository\PersonNotDuplicateRepository; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\Role\Role; use Chill\PersonBundle\Security\Authorization\PersonVoter; /** - * + * * * @author Julien Fastré */ @@ -41,20 +42,20 @@ class SimilarPersonMatcher * @var EntityManagerInterface */ protected $em; - + /** * @var AuthorizationHelper */ protected $authorizationHelper; - + /** - * @var TokenStorageInterface + * @var TokenStorageInterface */ protected $tokenStorage; - + public function __construct( - EntityManagerInterface $em, - AuthorizationHelper $authorizationHelper, + EntityManagerInterface $em, + AuthorizationHelper $authorizationHelper, TokenStorageInterface $tokenStorage ) { $this->em = $em;