Loading module/Oscar/src/Oscar/Command/OscarCheckIndexCommand.php 0 → 100644 +72 −0 Changes for module/Oscar/src/Oscar/Command/OscarCheckIndexCommand.php: 72 added lines, 0 removed lines. Original line number Diff line number Diff line <?php /** * Created by PhpStorm. * User: bouvry * Date: 04/10/19 * Time: 11:49 */ namespace Oscar\Command; use Monolog\Logger; use Oscar\Service\OscarConfigurationService; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; class OscarCheckIndexCommand extends OscarAdvancedCommandAbstract { protected static $defaultName = 'check:index'; protected function configure() { $this ->setDescription("Reconstruction des index (activité, organisation, personne"); } /** * @return OscarConfigurationService */ protected function getOscarConfiguration() { return $this->getServicemanager()->get(OscarConfigurationService::class); } /** * @return Logger */ protected function getLogger() { return $this->getServicemanager()->get('Logger'); } public function execute(InputInterface $input, OutputInterface $output): int { parent::execute($input, $output); try { $this->getIO()->title("Reconstruction de l'index de recherche des activités"); $this->getProjectGrantService()->searchIndex_rebuild(); $this->finalSuccess("Index de recherche des activités mis à jour"); } catch (Exception $e) { return $this->finalFatalError($e); } try { $this->getIO()->title("Reconstruction de l'index de recherche des organisations"); $this->getOrganizationService()->searchIndexRebuild(); $this->finalSuccess("Index de recherche des organisations mis à jour"); } catch (Exception $e) { return $this->finalFatalError($e); } try { $this->getIO()->title("Reconstruction de l'index de recherche des personnes"); $this->getPersonService()->searchIndexRebuild(); $this->finalSuccess("Index de recherche des personnes mis à jour"); } catch (Exception $e) { return $this->finalFatalError($e); } return 0; } } No newline at end of file module/Oscar/src/Oscar/Command/OscarOrganizationSearchReindexCommand.php +2 −0 Changes for module/Oscar/src/Oscar/Command/OscarOrganizationSearchReindexCommand.php: 2 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -46,5 +46,7 @@ class OscarOrganizationSearchReindexCommand extends OscarAdvancedCommandAbstract } catch (Exception $e) { return $this->finalFatalError($e); } return 0; } } No newline at end of file module/Oscar/src/Oscar/Service/OrganizationService.php +1 −2 Changes for module/Oscar/src/Oscar/Service/OrganizationService.php: 1 added line, 2 removed lines. Original line number Diff line number Diff line Loading @@ -621,9 +621,8 @@ class OrganizationService implements UseOscarConfigurationService, UseEntityMana $this->getPersonService()->getGearmanJobLauncherService()->triggerUpdateSearchIndexOrganization($organization); } catch (\Exception $e){ $this->getLoggerService()->error("! closeOrganizationPerson : $person > $organization > $role"); } } //////////////////////////////////////////////////////////////////////////// Loading module/Oscar/src/Oscar/Service/PersonService.php +49 −1 Changes for module/Oscar/src/Oscar/Service/PersonService.php: 49 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -236,6 +236,7 @@ class PersonService implements UseOscarConfigurationService, UseEntityManager, U /** * Retourne les personnes subordonnées du référent. * * @param $personId ID du référents * @return Referent[] */ Loading @@ -247,6 +248,31 @@ class PersonService implements UseOscarConfigurationService, UseEntityManager, U return $query->getQuery()->getResult(); } /** * Cloture le role d'une personne sur une organisation. * * @param Person $person * @param Organization $organization * @param Role $roleObj * @param bool $hardRemove Type de suppression */ public function removePersonOrganizationWithRole( Person $person, Organization $organization, Role $roleObj, bool $hardRemove = false) :void { /** @var OrganizationPerson $personOrganization */ foreach ($person->getOrganizations() as $personOrganization) { if( $personOrganization->getOrganization()->getId() == $organization->getId() && $personOrganization->getRoleObj()->getId() == $roleObj->getId() ){ if( $hardRemove == true ){ $this->personOrganizationRemove($personOrganization); } else { $this->getOrganizationService()->closeOrganizationPerson($personOrganization, new \DateTime()); } } } } /** * Transfert les affectations actives d'une personne vers une autre. Concerne : Loading Loading @@ -304,13 +330,16 @@ class PersonService implements UseOscarConfigurationService, UseEntityManager, U ); foreach ($organizationDatas['roles'] as $roleDatas) { if ($roleDatas['active']) { $roleObj = $this->getRoleRepository()->getRoleByRoleId($roleDatas['roleId']); $this->personOrganizationAdd( $organization, $replacer, $roleObj ); // TODO Suppression du remplacé (date de fin) $this->removePersonOrganizationWithRole($fromPerson, $organization, $roleObj); $this->getLoggerService()->info( "Replacer $fromPerson par $replacer dans la structure $organization" ); Loading Loading @@ -371,6 +400,8 @@ class PersonService implements UseOscarConfigurationService, UseEntityManager, U try { $referent = $this->getPersonById($referentId, true); $this->addReferent($referent->getId(), $replacer->getId()); $this->removeReferentOnPerson($referent, $fromPerson); } catch (\Exception $e) { $this->getLoggerService()->warning("Impossible d'ajouter le référent $referentId à $replacer"); } Loading @@ -380,6 +411,7 @@ class PersonService implements UseOscarConfigurationService, UseEntityManager, U try { $subordinate = $this->getPersonById($subordinateId, true); $this->addReferent($replacer->getId(), $subordinate->getId()); $this->removeReferentOnPerson($fromPerson, $subordinate); } catch (\Exception $e) { $this->getLoggerService()->warning("Impossible d'ajouter le subordonné $subordinateId à $replacer"); } Loading Loading @@ -744,6 +776,7 @@ class PersonService implements UseOscarConfigurationService, UseEntityManager, U /** * Supprime le référent. * * @param $referent_id * @return bool * @throws OscarException Loading @@ -764,6 +797,21 @@ class PersonService implements UseOscarConfigurationService, UseEntityManager, U } } public function removeReferentOnPerson( Person $referent, Person $on ){ try { $referentRepo = $this->getEntityManager()->getRepository(Referent::class); $referents = $referentRepo->findBy([ 'referent' => $referent, 'person' => $on ]); foreach ($referents as $r) { $this->removeReferentById($r->getId()); } } catch (\Exception $exception) { throw $exception; } } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Loading Loading
module/Oscar/src/Oscar/Command/OscarCheckIndexCommand.php 0 → 100644 +72 −0 Changes for module/Oscar/src/Oscar/Command/OscarCheckIndexCommand.php: 72 added lines, 0 removed lines. Original line number Diff line number Diff line <?php /** * Created by PhpStorm. * User: bouvry * Date: 04/10/19 * Time: 11:49 */ namespace Oscar\Command; use Monolog\Logger; use Oscar\Service\OscarConfigurationService; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; class OscarCheckIndexCommand extends OscarAdvancedCommandAbstract { protected static $defaultName = 'check:index'; protected function configure() { $this ->setDescription("Reconstruction des index (activité, organisation, personne"); } /** * @return OscarConfigurationService */ protected function getOscarConfiguration() { return $this->getServicemanager()->get(OscarConfigurationService::class); } /** * @return Logger */ protected function getLogger() { return $this->getServicemanager()->get('Logger'); } public function execute(InputInterface $input, OutputInterface $output): int { parent::execute($input, $output); try { $this->getIO()->title("Reconstruction de l'index de recherche des activités"); $this->getProjectGrantService()->searchIndex_rebuild(); $this->finalSuccess("Index de recherche des activités mis à jour"); } catch (Exception $e) { return $this->finalFatalError($e); } try { $this->getIO()->title("Reconstruction de l'index de recherche des organisations"); $this->getOrganizationService()->searchIndexRebuild(); $this->finalSuccess("Index de recherche des organisations mis à jour"); } catch (Exception $e) { return $this->finalFatalError($e); } try { $this->getIO()->title("Reconstruction de l'index de recherche des personnes"); $this->getPersonService()->searchIndexRebuild(); $this->finalSuccess("Index de recherche des personnes mis à jour"); } catch (Exception $e) { return $this->finalFatalError($e); } return 0; } } No newline at end of file
module/Oscar/src/Oscar/Command/OscarOrganizationSearchReindexCommand.php +2 −0 Changes for module/Oscar/src/Oscar/Command/OscarOrganizationSearchReindexCommand.php: 2 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -46,5 +46,7 @@ class OscarOrganizationSearchReindexCommand extends OscarAdvancedCommandAbstract } catch (Exception $e) { return $this->finalFatalError($e); } return 0; } } No newline at end of file
module/Oscar/src/Oscar/Service/OrganizationService.php +1 −2 Changes for module/Oscar/src/Oscar/Service/OrganizationService.php: 1 added line, 2 removed lines. Original line number Diff line number Diff line Loading @@ -621,9 +621,8 @@ class OrganizationService implements UseOscarConfigurationService, UseEntityMana $this->getPersonService()->getGearmanJobLauncherService()->triggerUpdateSearchIndexOrganization($organization); } catch (\Exception $e){ $this->getLoggerService()->error("! closeOrganizationPerson : $person > $organization > $role"); } } //////////////////////////////////////////////////////////////////////////// Loading
module/Oscar/src/Oscar/Service/PersonService.php +49 −1 Changes for module/Oscar/src/Oscar/Service/PersonService.php: 49 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -236,6 +236,7 @@ class PersonService implements UseOscarConfigurationService, UseEntityManager, U /** * Retourne les personnes subordonnées du référent. * * @param $personId ID du référents * @return Referent[] */ Loading @@ -247,6 +248,31 @@ class PersonService implements UseOscarConfigurationService, UseEntityManager, U return $query->getQuery()->getResult(); } /** * Cloture le role d'une personne sur une organisation. * * @param Person $person * @param Organization $organization * @param Role $roleObj * @param bool $hardRemove Type de suppression */ public function removePersonOrganizationWithRole( Person $person, Organization $organization, Role $roleObj, bool $hardRemove = false) :void { /** @var OrganizationPerson $personOrganization */ foreach ($person->getOrganizations() as $personOrganization) { if( $personOrganization->getOrganization()->getId() == $organization->getId() && $personOrganization->getRoleObj()->getId() == $roleObj->getId() ){ if( $hardRemove == true ){ $this->personOrganizationRemove($personOrganization); } else { $this->getOrganizationService()->closeOrganizationPerson($personOrganization, new \DateTime()); } } } } /** * Transfert les affectations actives d'une personne vers une autre. Concerne : Loading Loading @@ -304,13 +330,16 @@ class PersonService implements UseOscarConfigurationService, UseEntityManager, U ); foreach ($organizationDatas['roles'] as $roleDatas) { if ($roleDatas['active']) { $roleObj = $this->getRoleRepository()->getRoleByRoleId($roleDatas['roleId']); $this->personOrganizationAdd( $organization, $replacer, $roleObj ); // TODO Suppression du remplacé (date de fin) $this->removePersonOrganizationWithRole($fromPerson, $organization, $roleObj); $this->getLoggerService()->info( "Replacer $fromPerson par $replacer dans la structure $organization" ); Loading Loading @@ -371,6 +400,8 @@ class PersonService implements UseOscarConfigurationService, UseEntityManager, U try { $referent = $this->getPersonById($referentId, true); $this->addReferent($referent->getId(), $replacer->getId()); $this->removeReferentOnPerson($referent, $fromPerson); } catch (\Exception $e) { $this->getLoggerService()->warning("Impossible d'ajouter le référent $referentId à $replacer"); } Loading @@ -380,6 +411,7 @@ class PersonService implements UseOscarConfigurationService, UseEntityManager, U try { $subordinate = $this->getPersonById($subordinateId, true); $this->addReferent($replacer->getId(), $subordinate->getId()); $this->removeReferentOnPerson($fromPerson, $subordinate); } catch (\Exception $e) { $this->getLoggerService()->warning("Impossible d'ajouter le subordonné $subordinateId à $replacer"); } Loading Loading @@ -744,6 +776,7 @@ class PersonService implements UseOscarConfigurationService, UseEntityManager, U /** * Supprime le référent. * * @param $referent_id * @return bool * @throws OscarException Loading @@ -764,6 +797,21 @@ class PersonService implements UseOscarConfigurationService, UseEntityManager, U } } public function removeReferentOnPerson( Person $referent, Person $on ){ try { $referentRepo = $this->getEntityManager()->getRepository(Referent::class); $referents = $referentRepo->findBy([ 'referent' => $referent, 'person' => $on ]); foreach ($referents as $r) { $this->removeReferentById($r->getId()); } } catch (\Exception $exception) { throw $exception; } } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Loading