Commit fb263b07 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Finalisation script

parent 01fa0585
Loading
Loading
Loading
Loading
+6 −84
Original line number Diff line number Diff line
@@ -94,7 +94,8 @@ foreach ($dirs as $dir) {

if (count($intervenantsInvalides) > 0) {
    echo '<h1>Intervenants Invalides</h1>';
    echo implode(', ', $intervenantsInvalides);
    echo implode(',<br /> ', $intervenantsInvalides);
    die();
}

foreach ($intervenants as $code => $intervenant) {
@@ -106,7 +107,8 @@ foreach ($intervenants as $code => $intervenant) {
    }
}

var_dump($intervenants);
//var_dump($intervenants);
//die();

$count = count($intervenants);
$index = 0;
@@ -152,89 +154,9 @@ foreach ($intervenants as $code => $interv) {
            $pj->setValidation($validation);
            $container->get(PieceJointeService::class)->save($pj);
        }

        $container->get(WorkflowService::class)->calculerTableauxBord([], $intervenant);
        //$container->get(WorkflowService::class)->calculerTableauxBord([], $intervenant);
    } catch (\Exception $e) {
        echo 'ERREUR intervenant ' . $code . ' : ' . $e->getMessage();
    }
    echo "\n";
}
 No newline at end of file


foreach ($dirs as $i => $dir) {
    if (0 <= $i && $i < 9999999) {
        if ($dir == '.' || $dir == '..') continue;
        $code = explode('.', $dir)[0];

        echo ($i + 1) . '/' . (count($dirs) - 2) . ' ... ' . $code . ' - ';

        $intervenant = $si->getBySourceCode($code);

        if ($intervenant) {
            try {

                $sql     = "
                SELECT
                  count(*) NB
                FROM
                  fichier f
                  JOIN piece_jointe_fichier pjf ON pjf.fichier_id = f.id
                  JOIN piece_jointe pj ON pj.id = pjf.piece_jointe_id
                WHERE
                  f.nom = :nomFichier
                  AND pj.intervenant_id = :intervenant 
                ";
                $fExists = $si->getEntityManager()->getConnection()->fetchAll($sql, ['nomFichier' => $dir, 'intervenant' => $intervenant->getId()]);
                $fExists = (int)$fExists[0]['NB'] > 0;

                if ($fExists) {
                    echo 'CV Existe déjà';
                } else {
                    $fichier = new Fichier();
                    $fichier->setContenu(file_get_contents($repertoire . $dir));
                    $fichier->setNom($dir);
                    $fichier->setTaille(filesize($repertoire . $dir));
                    $fichier->setTypeMime($typeMime);

                    $valFichier = new Validation();
                    $valFichier->setIntervenant($intervenant);
                    $valFichier->setTypeValidation($tvFichier);
                    $valFichier->setStructure($intervenant->getStructure());
                    $container->get(ValidationService::class)->save($valFichier);
                    $fichier->setValidation($valFichier);

                    $pj = $container->get(PieceJointeService::class)->getByType($intervenant, $typePieceJointe);
                    if (!$pj || !$pj->estNonHistorise()) {
                        $pj = new PieceJointe();
                        $pj->setIntervenant($intervenant);
                        $pj->setType($typePieceJointe);
                        $container->get(PieceJointeService::class)->save($pj);
                    }
                    $container->get(FichierService::class)->save($fichier, 'bdd');

                    $sql = "INSERT INTO piece_jointe_fichier(piece_jointe_id,fichier_id) values (" . $pj->getId() . "," . $fichier->getId() . ")";
                    $si->getEntityManager()->getConnection()->exec($sql);

                    // Validation
                    if (!($pj->getValidation() && $pj->getValidation()->estNonHistorise())) {
                        $validation = new Validation();
                        $validation->setIntervenant($intervenant);
                        $validation->setTypeValidation($tvPJ);
                        $validation->setStructure($intervenant->getStructure());
                        $container->get(ValidationService::class)->save($validation);
                        $pj->setValidation($validation);
                        $container->get(PieceJointeService::class)->save($pj);
                    }

                    $container->get(WorkflowService::class)->calculerTableauxBord([], $intervenant);
                    echo 'CV Inséré';
                }
            } catch (\Exception $e) {
                echo 'ERREUR inconnue';
            }
        } else {
            echo 'ERREUR : intervenant inexistant';
        }
        echo "\n";
    }
}