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

Merge branch 'spartan' of git.unicaen.fr:open-source/oscar into spartan

parents 8c840eda eb859e83
Loading
Loading
Loading
Loading
+37 −87
Changes for bin/oscar-worker.php: 37 added lines, 87 removed lines.
Original line number Diff line number Diff line
@@ -13,6 +13,8 @@
// Chemin "simplifié"
chdir(dirname(__DIR__));

$oscarCmd = '/usr/bin/php bin/oscar.php console ';

// Autoload & Co
require __DIR__.'/../vendor/autoload.php';

@@ -28,139 +30,87 @@ $oscarConfigurationService = $app->getServiceManager()->get(\Oscar\Service\Oscar
// Worker
$worker = new GearmanWorker();
$worker->addServer($oscarConfigurationService->getGearmanHost());
$worker->addFunction('indexPerson', 'oscarJob_indexPerson');
$worker->addFunction('personSearchUpdate', 'oscarJob_indexPerson');
$worker->addFunction('indexActivity', 'oscarJob_indexActivity');
$worker->addFunction('activitySearchUpdate', 'oscarJob_indexActivity');
$worker->addFunction('notificationActivityPerson', 'oscarJob_notificationActivityPerson');
$worker->addFunction('purgeNotificationsPersonActivity', 'oscarJob_purgeNotificationsPersonActivity');

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

$worker->addFunction('hello', 'oscarJob_hello');

// Affiche dans le journalctl -u oscarworker.service -f
echo "OSCAR WORKER STARTED\n";
echo "Version: " . \Oscar\OscarVersion::getBuild() . "\n";
$execDev = "2";
echo "OSCAR WORKER STARTED ".\Oscar\OscarVersion::getBuild()."\n";

while($worker->work());

function getServiceManager(){
    global $app;
    return $app->getServiceManager();
}

while($worker->work());

function oscarJob_indexActivity(GearmanJob $job){
function oscarJob_updateIndexActivity(GearmanJob $job){
    global $oscarCmd;
    $params = json_decode($job->workload());



    try {
        if( !property_exists($params, 'activityid') ){
            throw new Exception("Paramètres manquant ID");
            throw new Exception("Paramètres manquant 'activityid'");
        }
        /** @var \Oscar\Service\ProjectGrantService $activityService */
        $activityService = getServiceManager()->get(\Oscar\Service\ProjectGrantService::class);


        $activityid = $params->activityid;
        $activityService->getLoggerService()->info("[GEARMAN] Indexation de Activity $activityid");
        $activity = $activityService->getActivityById($activityid);
        echo date('y-m-d H:i:s')." Rebuid Index [$activityid] $activity\n";
        $activityService->searchUpdate($activity);
        echo "[worker] indexactivity " . $activityid;
        exec($oscarCmd . ' indexactivity \'{"activityid":'. $params->activityid .'}\'');

    } catch (Exception $e) {
        $activityService->getLoggerService()->info("[GEARMAN] Error " . $e->getMessage());
        echo "[ERR] " . $e->getMessage() ."\n";
    }
}

function oscarJob_indexPerson(GearmanJob $job){
function oscarJob_updateIndexPerson(GearmanJob $job){
    global $oscarCmd;
    $params = json_decode($job->workload());

    try {
        if( !property_exists($params, 'personid') ){
            throw new Exception("Paramètres manquant ID");
            throw new Exception("Paramètres manquant 'personid'");
        }
        /** @var \Oscar\Service\PersonService $personService */
        $personService = getServiceManager()->get(\Oscar\Service\PersonService::class);

        $personId = $params->personid;

        getServiceManager()->get('Logger')->info("[GEARMAN] Indexation de Person $personId");
        $person = $personService->getPerson($personId);
        echo date('y-m-d H:i:s')." Rebuid Index [$personId] $person\n";
        $personService->getSearchEngineStrategy()->update($person);
        $personid = $params->personid;
        echo "[worker] indexperson " . $personid;
        exec($oscarCmd . ' indexperson \'{"personid":'. $personid .'}\'');

    } catch (Exception $e) {
        getServiceManager()->get('Logger')->info("[GEARMAN] Error " . $e->getMessage());
        echo "[ERR] " . $e->getMessage() . "\n";
    }
}

function oscarJob_notificationActivityPerson(GearmanJob $job){
function oscarJob_updateIndexOrganization(GearmanJob $job){
    global $oscarCmd;
    $params = json_decode($job->workload());

    try {
        if( !property_exists($params, 'personid') || !property_exists($params, 'activityid') ){
            throw new Exception("Paramètres manquant ID");
        if( !property_exists($params, 'organizationid') ){
            throw new Exception("Paramètres manquant 'organizationid'");
        }

        /** @var \Oscar\Service\ProjectGrantService $projectGrantService */
        $projectGrantService = getServiceManager()->get(\Oscar\Service\ProjectGrantService::class);

        /** @var \Oscar\Service\PersonService $personService */
        $personService = getServiceManager()->get(\Oscar\Service\PersonService::class);

        /** @var \Oscar\Service\NotificationService $notificationService */
        $notificationService = getServiceManager()->get(\Oscar\Service\NotificationService::class);

        $personId = $params->personid;
        $person = $personService->getPerson($personId);

        $activityId = $params->activityid;
        $activity = $projectGrantService->getActivityById($activityId);

        getServiceManager()->get('Logger')->info("[GEARMAN] Notification Person:$personId - Activity:$activityId");

        echo date('y-m-d H:i:s')." Notification Activity Person [$activityId, $personId] $activity >  $person\n";
        $notificationService->generateNotificationsForActivity($activity, $person);
        $organizationid = $params->organizationid;
        echo "[worker] indexorganization " . $organizationid;
        exec($oscarCmd . ' indexorganization \'{"organizationid":'. $organizationid .'}\'');

    } catch (Exception $e) {
        echo "[ERR] " . $e->getMessage() . "\n";
        getServiceManager()->get('Logger')->info("[GEARMAN] Error " . $e->getMessage());
    }
}

function oscarJob_updateNotificationsActivity(GearmanJob $job){
    global $oscarCmd;

function oscarJob_purgeNotificationsPersonActivity(GearmanJob $job){
    $params = json_decode($job->workload());

    try {
        if( !property_exists($params, 'personid') || !property_exists($params, 'activityid') ){
            throw new Exception("Paramètres manquant ID");
        if( !property_exists($params, 'activityid') ){
            throw new Exception("Paramètres manquant 'activityid'");
        }

        /** @var \Oscar\Service\ProjectGrantService $projectGrantService */
        $projectGrantService = getServiceManager()->get(\Oscar\Service\ProjectGrantService::class);

        /** @var \Oscar\Service\PersonService $personService */
        $personService = getServiceManager()->get(\Oscar\Service\PersonService::class);

        /** @var \Oscar\Service\NotificationService $notificationService */
        $notificationService = getServiceManager()->get(\Oscar\Service\NotificationService::class);

        $personId = $params->personid;
        $person = $personService->getPerson($personId);

        $activityId = $params->activityid;
        $activity = $projectGrantService->getActivityById($activityId);

        getServiceManager()->get('Logger')->info("[GEARMAN] Purge notification Person:$personId Activity:$activityId");

        echo date('y-m-d H:i:s')." PURGE Notification Activity Person [$activityId, $personId] $activity >  $person\n";
        $notificationService->purgeNotificationsPersonActivity($activity, $person);
        $activityid = $params->activityid;
        echo "[worker] notificationsactivity " . $activityid;
        exec($oscarCmd . ' notificationsactivity \'{"activityid":'. $params->activityid .'}\'');

    } catch (Exception $e) {
        getServiceManager()->get('Logger')->info("[GEARMAN] Error " . $e->getMessage());
        echo "[ERR] " . $e->getMessage() ."\n";
    }
}
@@ -186,7 +136,7 @@ function oscarJob_hello(GearmanJob $job){
        echo "Hello with " . print_r($params) . "\n";

        // Envoi d'un log vers OSCAR
        $loggerService->info("[GEARMAN] a bien reçu la tâche HELLO");
        getServiceManager()->get('Logger')->info(" > [gearman:call] TEST OK]");

        $job->sendComplete("TRAITEMENT RÉUSSI");

+1 −0
Changes for composer.json: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@
  "description": "",

  "require": {
    "mpdf/mpdf": "8.0.4 as 7.1.7",
    "unicaen/app": "^3.0",
    "unicaen/auth": "^3.2.0",
    "oro/doctrine-extensions": "^1.2",
+220 −175

File changed.

Preview size limit exceeded, changes collapsed.

+20 −7
Changes for config/autoload/global.php: 20 added lines, 7 removed lines.
Original line number Diff line number Diff line
@@ -227,13 +227,26 @@ return array(
        ],

        'horslots' => [
//            'conges' => [ 'code' => 'conges',  'label' => 'Congés',  'description' => 'Congès, RTT, récupération', 'icon' => true ],
//            'training' => [ 'code' => 'training',  'label' => 'Formation',  'description' => 'Vous avez suivi un formation, DIFF, etc...', 'icon' => true ],
//            'teaching' => [ 'code' => 'teaching',  'label' => 'Enseignement',  'description' => 'Cours, TD, fonction pédagogique', 'icon' => true ],
//            'sickleave' => [ 'code' => 'sickleave', 'label' => 'Arrêt maladie',  'description' => '', 'icon' => true ],
//            //  'absent' => [ 'code' => 'absent',  'label' => 'Absent',  'description' => '', 'icon' => true ],
//            'research' => [ 'code' => 'research', 'label' => 'Autre recherche',  'description' => 'Autre projet de recherche (sans feuille de temps)', 'icon' => true ],
//            'other' => [ 'code' => 'other', 'label' => 'Divers',  'description' => 'Autre activité', 'icon' => true ],
            ////////////////////////////////// EXEMPLE de CONFIGURATION DES HORS-LOTS
//            'conges' => [ 'code' => 'conges',  'label' => 'Congés',
//                'group' => 'abs',
//                'description' => 'Congès, RTT, récupération', 'icon' => true ],
//            'training' => [ 'code' => 'training',  'label' => 'Formation',
//                'group' => 'other',
//                'description' => 'Vous avez suivi un formation, DIFF, etc...', 'icon' => true ],
//            'teaching' => [ 'code' => 'teaching',  'label' => 'Enseignement',
//                'group' => 'education',
//                'description' => 'Cours, TD, fonction pédagogique', 'icon' => true ],
//            'sickleave' => [ 'code' => 'sickleave', 'label' => 'Arrêt maladie',
//                'group' => 'abs',
//                'description' => '', 'icon' => true ],
//            'research' => [ 'code' => 'research', 'label' => 'Autre recherche',
//                'group' => 'research',
//                'description' => 'Autre projet de recherche (sans feuille de temps)', 'icon' => true ],
//            'other' => [ 'code' => 'other', 'label' => 'Divers',
//                'group' => 'other',
//                'description' => 'Autre activité', 'icon' => true ],

        ],


+13 −0
Changes for doc/install-elasticsearch.md: 13 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -74,6 +74,17 @@ La commande `service --status-all` va vous permettre de lister les services char

> Attention : le [ - ] indique que le service est INACTIF

#### Sous systemd la commande a utiliser est la suivante

```
systemctl list-unit-files --type=service | grep elastic
```
> Attention: l'état disabled indique que le service est INACTIF

```
elasticsearch.service                      disabled 
```


### Elasticsearch en tant que service

@@ -100,6 +111,8 @@ systemctl stop elasticsearch.service

Vous pouvez tester l'état du service avec la commande `service elasticsearch status` :

Si vous êtes sous systemd, utilisez la commande `systemctl status elasticsearch.service` :

```
● elasticsearch.service - Elasticsearch
   Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; enabled; vendor preset: enabled)
Loading