Commit 6cd9ff73 authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

Fix : Erreur dans les générations des documents si des clefs personnalisées sont non-référencées

Trie des types de structures par labels
Fix : Mauvaise récupération de certains rôles dans la synchronisation des personnes
Fix : Filtre par type de structure
parent 319f4c76
Loading
Loading
Loading
Loading
Loading
+106 −0
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 Moment\Moment;
use Oscar\Connector\ConnectorRepport;
use Oscar\Entity\Authentification;
use Oscar\Entity\LogActivity;
use Oscar\Entity\Person;
use Oscar\Entity\Role;
use Oscar\Service\ConnectorService;
use Oscar\Service\OscarConfigurationService;
use Oscar\Service\OscarUserContext;
use Oscar\Service\PersonService;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

class OscarPersonsSyncCommand extends OscarCommandAbstract
{
    protected static $defaultName = 'persons:sync';

    protected function configure()
    {
        $this
            ->setDescription("Execute la synchronisation des personnes")
            ->addArgument("connectorname", InputArgument::REQUIRED, "Connector (rest)")
            ->addOption('no-rebuild','b', InputOption::VALUE_NONE, 'Ignore la reconstruction de l\'index de recherche après la mise à jour')
            ->addOption('purge','p', InputOption::VALUE_NONE, 'Supprime les personnes d\'Oscar si elles ne sont plus proposées dans la source distante (et qu\'elles ne sont pas utilisées dans Oscar)')
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->addOutputStyle($output);

        /** @var OscarUserContext $oscaruserContext */
        $oscaruserContext = $this->getServicemanager()->get(OscarUserContext::class);

        $io = new SymfonyStyle($input, $output);

        $io->title("Synchronisation des personnes");

        $connectorName = $input->getArgument('connectorname');


        /** @var OscarConfigurationService $oscarConfig */
        $oscarConfig = $this->getServicemanager()->get(OscarConfigurationService::class);

        $io->section("Connector infos : ");
        $io->writeln("Connecteur : <bold>$connectorName</bold>");

        $purge = $input->getOption('purge');

        /** @var ConnectorService $connectorService */
        $connectorService = $this->getServicemanager()->get(ConnectorService::class);

        $connector = $connectorService->getConnector("person.".$connectorName);

        try {
            $connector->setOptionPurge($input->getOption('purge'));

            /** @var ConnectorRepport $repport */
            $repport = $connector->execute();
            foreach ($repport->getRepportStates() as $type => $out) {
                $short = substr($type, 0, 3);
                $io->section( "Opération " . strtoupper($type));
                foreach ($out as $line) {
                    $io->writeln("$short\t " . date('Y-m-d H:i:s', $line['time']) . " " . $line['message'] );
                }
            }
        } catch (\Exception $e) {
            $io->error($e->getMessage());
            exit(0);
        }

        $io->section("Reconstruction de l'index de recherche : ");
        if( !$input->getOption('no-rebuild') ){
            /** @var PersonService $personService */
            $personService = $this->getServicemanager()->get(PersonService::class);

            try {
                $persons = $personService->getPersons();
                $personService->getSearchEngineStrategy()->rebuildIndex($persons);
                $io->success(sprintf('Index de recherche mis à jour avec %s personnes indexées', count($persons)));
            } catch ( \Exception $e ){
                $io->error($e->getMessage());
            }
        } else {
            $io->warning("Pas de reconstruction d'index");
        }


    }
}
 No newline at end of file
+4 −2
Original line number Diff line number Diff line
@@ -685,6 +685,7 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
        $baseDatas = $this->getProjectGrantService()->getBaseDataTemplate();

        if ($doc == "dump") {

            echo "<table border='1'>";
            $activity = $this->getProjectGrantService()->getGrant($id);
            foreach ($activity->documentDatas($baseDatas) as $key => $value) {
@@ -2768,8 +2769,9 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
                                $parameters['typeorga'] = [];
                            }
                            $value1 = $crit['val1'] = explode(',', $params[1]);
                            $qb->andWhere('orga1.type IN (:typeorga) OR orga2.type IN (:typeorga)');
                            $parameters['typeorga'] = $value1;
                            $typeIds = $this->getOrganizationService()->getTypesIdsByLabel($value1);
                            $qb->andWhere('orga1.typeObj IN (:typeorga) OR orga2.typeObj IN (:typeorga)');
                            $parameters['typeorga'] = $typeIds;
                        }
                        break;
                    case 'aj':
+33 −1
Original line number Diff line number Diff line
@@ -31,6 +31,38 @@ class RoleRepository extends EntityRepository
        return $this->getRolesAtLevel(Role::LEVEL_ACTIVITY);
    }

    /**
     * @param string $format
     * @return array
     */
    public function getRolesAtOrganizationArray( string $format = OscarFormatterConst::FORMAT_ARRAY_ID_VALUE) :array
    {
        $return = [];
        $roles = $this->getRolesAtLevel(Role::LEVEL_ORGANIZATION)->getQuery()->getResult();

        if( $format == OscarFormatterConst::FORMAT_ARRAY_OBJECT ){
            return $roles;
        }

        if( $format == OscarFormatterConst::FORMAT_ARRAY_FLAT ){
            return array_map(function($role){ return $role->getRoleId(); }, $roles);
        }

        /** @var Role $role */
        foreach( $roles as $role ){
            switch ($format) {
                case OscarFormatterConst::FORMAT_ARRAY_ID_OBJECT:
                    $return[$role->getRoleId()] = $role;
                    break;
                case OscarFormatterConst::FORMAT_ARRAY_ID_VALUE:
                    $return[$role->getRoleId()] = $role->getRoleId();
                    break;
            }
        }

        return $return;
    }

    /**
     * @param string $format
     * @return array
@@ -129,7 +161,7 @@ class RoleRepository extends EntityRepository
    {
        static $rolesByRoleId;
        if( $rolesByRoleId === null ){
            $rolesByRoleId = $this->getRolesAtActivityArray(OscarFormatterConst::FORMAT_ARRAY_ID_VALUE);
            $rolesByRoleId = $this->getRolesAtOrganizationArray(OscarFormatterConst::FORMAT_ARRAY_ID_OBJECT);
        }
        return $rolesByRoleId;
    }
+16 −0
Original line number Diff line number Diff line
@@ -79,6 +79,22 @@ class OrganizationService implements UseOscarConfigurationService, UseEntityMana
        $this->personService = $personService;
    }

    public function getTypesIdsByLabel(?array $labels) :array {
        $types = [];
        $result = $this->getEntityManager()->getRepository(OrganizationType::class)->findBy(
            ['root' => null],
            ['label' => 'DESC']
        );

        /** @var OrganizationType $type */
        foreach ($result as $type) {
            if( in_array($type->getLabel(), $labels) ){
                $types[] = $type->getId();
            }
        }
        return $types;
    }


    private $cacheCountries = null;
    private $cacheConnectors = null;
+1 −1
Original line number Diff line number Diff line
@@ -511,7 +511,7 @@ class ProjectGrantService implements UseGearmanJobLauncherService, UseOscarConfi
                if ($r['numbers']) {
                    foreach ($r['numbers'] as $key => $value) {
                        if (!$value) {
                            echo "$key\n";
                            //echo "$key\n";
                        }
                        if (!in_array($key, $customNum)) {
                            $customNum[] = $key;