Commit 8bd6e1d5 authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

Job de réindexation des projets

parent d8de91b6
Loading
Loading
Loading
Loading
+18 −1
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ $worker->addServer($oscarConfigurationService->getGearmanHost());

$worker->addFunction('updateIndexActivity', 'oscarJob_updateIndexActivity');
$worker->addFunction('updateIndexPerson', 'oscarJob_updateIndexPerson');
$worker->addFunction('updateIndexProject', 'oscarJob_updateIndexProject');
$worker->addFunction('updateIndexOrganization', 'oscarJob_updateIndexOrganization');
$worker->addFunction('updateNotificationsActivity', 'oscarJob_updateNotificationsActivity');

@@ -63,7 +64,6 @@ function oscarJob_updateIndexActivity(GearmanJob $job)
        if (!property_exists($params, 'activityid')) {
            throw new Exception("Paramètres manquant 'activityid'");
        }
        $activityid = $params->activityid;
        $cmd = $oscarCmd . ' indexactivity \'{"activityid":' . $params->activityid . '}\'';
        echo "[worker] exec $cmd\n";
        exec($cmd);
@@ -72,6 +72,23 @@ function oscarJob_updateIndexActivity(GearmanJob $job)
    }
}

// oscarJob_updateIndexProject
function oscarJob_updateIndexProject(GearmanJob $job)
{
    global $oscarCmd;
    $params = json_decode($job->workload());
    try {
        if (!property_exists($params, 'projectid')) {
            throw new Exception("Paramètres manquant 'projectid'");
        }
        $cmd = $oscarCmd . ' indexproject \'{"projectid":' . $params->projectid . '}\'';
        echo "[worker] exec $cmd\n";
        exec($cmd);
    } catch (Exception $e) {
        echo "[ERR] " . $e->getMessage() . "\n";
    }
}

function oscarJob_updateIndexPerson(GearmanJob $job)
{
    global $oscarCmd;
+1 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ class OscarActivitySearchReindexCommand extends OscarAdvancedCommandAbstract
    protected static $defaultName = OscarCommandAbstract::COMMAND_ACTIVITY_SEARCH_REINDEX;

    const ARGUMENT_ACTIVITY_ID = 'activityid';
    const ARGUMENT_PROJECT_ID = 'projectid';

    protected function configure()
    {
+1 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ abstract class OscarCommandAbstract extends Command

    const COMMAND_ACTIVITY_SEARCH = 'activity:search';
    const COMMAND_ACTIVITY_SEARCH_REINDEX = 'activity:search:reindex';
    const COMMAND_PROJECT_SEARCH_REINDEX = 'project:search:reindex';
    const COMMAND_ACTIVITY_SEARCH_REINDEX_ALL = 'activity:search-rebuild';
    const COMMAND_ACTIVITY_NOTIFICATION_UPDATE = 'activity:notification:update';

+12 −0
Original line number Diff line number Diff line
@@ -80,6 +80,18 @@ class OscarConsoleCommand extends OscarCommandAbstract
                $input = new ArrayInput($arguments);
                return $command->run($input, $output);

            case "indexproject":

                $command = $this->getApplication()->find(OscarCommandAbstract::COMMAND_PROJECT_SEARCH_REINDEX);

                $arguments = [
                    OscarActivitySearchReindexCommand::ARGUMENT_PROJECT_ID => $params['projectid'],
                    '--force' => null
                ];

                $input = new ArrayInput($arguments);
                return $command->run($input, $output);

            case "indexperson":
                $command = $this->getApplication()->find(OscarCommandAbstract::COMMAND_PERSON_SEARCH_REINDEX);

+50 −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 Exception;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class OscarProjectSearchReindexCommand extends OscarAdvancedCommandAbstract
{
    protected static $defaultName = OscarCommandAbstract::COMMAND_PROJECT_SEARCH_REINDEX;

    const ARGUMENT_PROJECT_ID = 'projectid';

    protected function configure()
    {
        parent::configure();
        $this
            ->setDescription("Reconstruction de l'index de recherche pour un projet")
            ->addArgument(self::ARGUMENT_PROJECT_ID, InputArgument::REQUIRED, "ID du projet");
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        parent::execute($input, $output);

        $projectId = $input->getArgument(self::ARGUMENT_PROJECT_ID);

        try {
            $project = $this->getProjectGrantService()->getProjectService()->getProject($projectId);

            if (!$this->ask("Réindexer le projet '$project' ?")) {
                return 0;
            }

            $this->getProjectGrantService()->getSearchEngineProjectStrategy()->updateProject($project);

            return $this->finalSuccess("Index de recherche mis à jour pour '$project'");
        } catch (Exception $e) {
            return $this->finalFatalError($e);
        }
    }
}
 No newline at end of file
Loading