Commit fbebbb21 authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

Fix : Passage à Elasticsearch 8 (+maj lib PHP)

parent 1584fa37
Loading
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@
    "cocur/slugify": "^3.2",
    "erusev/parsedown": "^1.7",
    "jacksay/php-file-extension": "^0.0.1",
    "elasticsearch/elasticsearch": "^7.2",
    "elasticsearch/elasticsearch": "^8.0",
    "monolog/monolog": "^2.0",
    "dompdf/dompdf": "^0.8.3",
    "swiftmailer/swiftmailer": "^6.2",
@@ -50,7 +50,8 @@
    "github-protocols": ["https", "ssh"],
    "secure-http": false,
    "allow-plugins": {
      "laminas/laminas-dependency-plugin": true
      "laminas/laminas-dependency-plugin": true,
      "php-http/discovery": true
    }
  },
  "autoload": {
+478 −215

File changed.

Preview size limit exceeded, changes collapsed.

+13 −1
Original line number Diff line number Diff line
@@ -88,7 +88,19 @@ class OscarActivitySearchCommand extends OscarAdvancedCommandAbstract
                'filters' => $filters
            ];

            $result = $this->getProjectGrantService()->searchActivities($search, $options);
            $params = [
                'q' => $search,
                'page' => 1,
                'rbp' => 50,
                'sort' => 'hit',
                'direction' => 'desc',
                'filters' => [],
                'project' => 0,
                'restricted_ids' => false,
                'exportable' => false,
            ];

            $result = $this->getProjectGrantService()->search2($params);
            $showPersons = $input->getOption(self::OPT_PER);
            $showOrganizations = $input->getOption(self::OPT_ORG);

+101 −154
Original line number Diff line number Diff line
@@ -247,84 +247,84 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
        $this->activityRequestService = $activityRequestService;
    }

    /**
     * @url /activites-de-recherche/api
     * @return JsonModel
     */
    public function apiAction()
    {
        // On test les droits de la personne / restrictions
        $person = $this->getCurrentPerson();
        $fullaccess = false; // $this->getOscarUserContextService()->hasPrivileges(Privileges::ACTIVITY_INDEX);
        if ($fullaccess) {
            $restricted_ids = false;
        }
        else {
            $restricted_ids = array_unique($this->getActivityService()->getActivitiesIdsPerson($person));
        }

        ////////////////////////////////////////////////////////////////////////
        // Paramètres envoyés à l'API
        $q = $this->params()->fromQuery('q', '');
        $page = (int)$this->params()->fromQuery('p', 1);
        $rbp = (int)$this->params()->fromQuery('rbp', 20);
        $sort = $this->params()->fromQuery('t', null);
        $direction = $this->params()->fromQuery('d', 'desc');
        $status = $this->params()->fromQuery('st', '');
        $filters = $this->params()->fromQuery('f', []);

        if (!array_key_exists($sort, $this->getProjectGrantService()->getActivitiesSearchSort())) {
            $sort = 'hit';
        }

        if (!array_key_exists($direction, $this->getProjectGrantService()->getActivitiesSearchDirection())) {
            $direction = 'desc';
        }

        // Contrôle des filtres

        if ($status) {
            $filters[] = 's;' . $status . ';-1';
        }

        // Options des recheches
        $options = [
            'sort'           => $sort,
            'direction'      => $direction,
            'page'           => $page,
            'result_by_page' => $rbp,
            'filters'        => $filters,
            'restricted_ids' => $restricted_ids
        ];

        // Recherche
        $resultSearch = $this->getProjectGrantService()->searchActivities($q, $options);
        $jsonFormatter = new JSONFormatter($this->getOscarUserContextService());

        $datas = [];
        $activityIds = [];

        foreach ($resultSearch['activities'] as $activity) {
            $activityIds[] = $activity->getId();
            $datas[] = $jsonFormatter->format($activity, false);
        }

        $output = [
            'oscar'         => OscarVersion::getBuild(),
            'date'          => date('Y-m-d H:i:s'),
            'code'          => 200,
            'filters_infos' => $resultSearch['filters_infos'],
            'page'          => $resultSearch['page'],
            'resultsByPage' => $resultSearch['result_by_page'],
            'result_total'  => $resultSearch['total'],
            'datas'         => [
                'ids'     => $activityIds,
                'content' => $datas
            ]
        ];

        return $this->ajaxResponse($output);
    }
//    /**
//     * @url /activites-de-recherche/api
//     * @return JsonModel
//     */
//    public function apiAction()
//    {
//        // On test les droits de la personne / restrictions
//        $person = $this->getCurrentPerson();
//        $fullaccess = false; // $this->getOscarUserContextService()->hasPrivileges(Privileges::ACTIVITY_INDEX);
//        if ($fullaccess) {
//            $restricted_ids = false;
//        }
//        else {
//            $restricted_ids = array_unique($this->getActivityService()->getActivitiesIdsPerson($person));
//        }
//
//        ////////////////////////////////////////////////////////////////////////
//        // Paramètres envoyés à l'API
//        $q = $this->params()->fromQuery('q', '');
//        $page = (int)$this->params()->fromQuery('p', 1);
//        $rbp = (int)$this->params()->fromQuery('rbp', 20);
//        $sort = $this->params()->fromQuery('t', null);
//        $direction = $this->params()->fromQuery('d', 'desc');
//        $status = $this->params()->fromQuery('st', '');
//        $filters = $this->params()->fromQuery('f', []);
//
//        if (!array_key_exists($sort, $this->getProjectGrantService()->getActivitiesSearchSort())) {
//            $sort = 'hit';
//        }
//
//        if (!array_key_exists($direction, $this->getProjectGrantService()->getActivitiesSearchDirection())) {
//            $direction = 'desc';
//        }
//
//        // Contrôle des filtres
//
//        if ($status) {
//            $filters[] = 's;' . $status . ';-1';
//        }
//
//        // Options des recheches
//        $options = [
//            'sort'           => $sort,
//            'direction'      => $direction,
//            'page'           => $page,
//            'result_by_page' => $rbp,
//            'filters'        => $filters,
//            'restricted_ids' => $restricted_ids
//        ];
//
//        // Recherche
//        $resultSearch = $this->getProjectGrantService()->searchActivities($q, $options);
//        $jsonFormatter = new JSONFormatter($this->getOscarUserContextService());
//
//        $datas = [];
//        $activityIds = [];
//
//        foreach ($resultSearch['activities'] as $activity) {
//            $activityIds[] = $activity->getId();
//            $datas[] = $jsonFormatter->format($activity, false);
//        }
//
//        $output = [
//            'oscar'         => OscarVersion::getBuild(),
//            'date'          => date('Y-m-d H:i:s'),
//            'code'          => 200,
//            'filters_infos' => $resultSearch['filters_infos'],
//            'page'          => $resultSearch['page'],
//            'resultsByPage' => $resultSearch['result_by_page'],
//            'result_total'  => $resultSearch['total'],
//            'datas'         => [
//                'ids'     => $activityIds,
//                'content' => $datas
//            ]
//        ];
//
//        return $this->ajaxResponse($output);
//    }

    public function adminDemandeAction()
    {
@@ -2678,29 +2678,29 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
        return $this->advancedSearchAction();
    }

    /**
     * @return array
     */
    public function searchActivityAction(): array|ViewModel|Response
    {
        $search = $this->params()->fromQuery('q', "");
        $options = [];

        try {
            $activities = $this->getProjectGrantService()->searchActivities($search, $options);
        } catch (Exception $e) {
            return $this->getResponseBadRequest($e->getMessage());
        }

        $view = new ViewModel(
            [
                'search'     => $search,
                'activities' => $activities,
            ]
        );
        $view->setTemplate('oscar/activity/search.phtml');
        return $view;
    }
//    /**
//     * @return array
//     */
//    public function searchActivityAction(): array|ViewModel|Response
//    {
//        $search = $this->params()->fromQuery('q', "");
//        $options = [];
//
//        try {
//            $activities = $this->getProjectGrantService()->searchActivities($search, $options);
//        } catch (Exception $e) {
//            return $this->getResponseBadRequest($e->getMessage());
//        }
//
//        $view = new ViewModel(
//            [
//                'search'     => $search,
//                'activities' => $activities,
//            ]
//        );
//        $view->setTemplate('oscar/activity/search.phtml');
//        return $view;
//    }

    /**
     * Recherche avancée des activités.
@@ -2967,59 +2967,6 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
        return $view;
    }

    /**
     * Liste des activités de recherche.
     */
    public function indexAction()
    {
        die("DEPRECATED");
        return $this->getResponseDeprecated();
    }

    public function almostStartAction()
    {
        $qb = $this->getActivityService()->getActivityBeginsSoon();
        $persons = $this->filterPersons($qb);
        $activities = $qb->orderBy(
            'c.dateStart',
            'DESC'
        )->getQuery()->getResult();

        $view = new ViewModel(
            [
                'entities'     => $activities,
                'filterLabel'  => "débutant prochainement",
                'datePrefix'   => "Débute",
                'getDateGroup' => 'getDateStart',
                'persons'      => $persons,

            ]
        );

        $view->setTemplate('oscar/activity/list-view.phtml');
        return $view;
    }

    public function almostDoneAction()
    {
        $qb = $this->getActivityService()->getActivityAlmostDone();
        $persons = $this->filterPersons($qb);
        $activities = $qb->orderBy('c.dateEnd')->getQuery()->getResult();

        $view = new ViewModel(
            [
                'entities'     => $activities,
                'filterLabel'  => "se terminant bientôt",
                'datePrefix'   => "Se termine",
                'getDateGroup' => 'getDateEnd',
                'persons'      => $persons,
            ]
        );
        $view->setTemplate('oscar/activity/list-view.phtml');

        return $view;
    }

    public function timesheetAction()
    {
        /** @var Activity $activity */
+2 −3
Original line number Diff line number Diff line
@@ -921,12 +921,12 @@ class ProjectGrantService implements UseGearmanJobLauncherService, UseOscarConfi
            $restricted_ids = $options['restricted_ids'];
        }

        // Critère de trie
        // Critère de tri
        if (array_key_exists('sort', $options)) {
            $sort = $options['sort'];
        }

        // Ordre de trie
        // Ordre de tri
        if (array_key_exists('direction', $options)) {
            $direction = $options['direction'];
        }
@@ -2963,7 +2963,6 @@ class ProjectGrantService implements UseGearmanJobLauncherService, UseOscarConfi


            if( $params['restricted_ids'] !== false ){
                $this->getLoggerService()->info('ICI');
                $body['query']['bool']['filter'][] = [
                    'terms' => [ 'id' => array_values($params['restricted_ids'])]
                ];
Loading