Commit 39811005 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Scripts unicaen/code : correction du nom des fichiers autre que these/annexe ;...

Scripts unicaen/code : correction du nom des fichiers autre que these/annexe ; création des fichiers sur disques à partir de la bdd.
parent 0981918a
Loading
Loading
Loading
Loading
+63 −0
Original line number Diff line number Diff line
<?php
/**
 * @var $this \Zend\View\Renderer\PhpRenderer
 * @var $controller \UnicaenCode\Controller\Controller
 * @var $viewName string
 */

use Application\Entity\Db\Fichier;
use Application\Entity\Db\NatureFichier;
use Application\Filter\NomFichierFormatter;
use Application\Service\Fichier\FichierService;

set_time_limit(120);

/** @var FichierService $fs */
$fs = $controller->getServiceLocator()->get('FichierService');
//$rootdir = $fs->getRootDirectoryPath();
$rootdir = '/tmp/sygal-files';

$repo = $fs->getEntityManager()->getRepository(Fichier::class);
$qb = $repo->createQueryBuilder('f');
$qb
    ->addSelect('nf, t')
    ->join('f.nature', 'nf')
    ->join('f.these', 't')
    ->where('1 = pasHistorise(f)')
//    ->andWhere($qb->expr()->notIn('nf.code', [NatureFichier::CODE_THESE_PDF, NatureFichier::CODE_FICHIER_NON_PDF]))
    ->orderBy('nf.code');
/** @var Fichier[] $fichiers */
$fichiers = $qb/*->setMaxResults(50)*/->getQuery()->getResult();

$nomFichierFormatter = new NomFichierFormatter();

$newNoms = [];
?>

<table class="table table-extra-condensed">
    <thead>
        <tr>
            <th>Nature</th>
            <th>Nom</th>
            <th>Nom original</th>
            <th>New nom</th>
        </tr>
    </thead>
    <tbody>
        <?php foreach ($fichiers as $fichier): ?>
        <tr>
            <?php
            $newNom = $nomFichierFormatter->filter($fichier);
            $newNoms[] = $newNom;
            ?>
            <td><?php echo $fichier->getNature()->getCode() ?></td>
            <td><?php echo $fichier->getNom() ?></td>
            <td><?php echo $fichier->getNomOriginal() ?></td>
            <td><?php echo $newNom !== $fichier->getNom() ? $newNom : "Inutile"; ?></td>
        </tr>
        <?php endforeach ?>
    </tbody>
</table>

<?php
var_dump(count($newNoms), count(array_unique($newNoms)));
 No newline at end of file
+6 −6
Original line number Diff line number Diff line
@@ -7,7 +7,6 @@

use Application\Entity\Db\ContenuFichier;
use Application\Service\Fichier\FichierService;
use UnicaenApp\Util;

//////////////////////////////////////////////////////////////////////////
//
@@ -20,6 +19,7 @@ set_time_limit(120);
/** @var FichierService $fs */
$fs = $controller->getServiceLocator()->get('FichierService');
$rootdir = $fs->getRootDirectoryPath();
//$rootdir = '/tmp/sygal-files';

$repo = $fs->getEntityManager()->getRepository(ContenuFichier::class);
$qb = $repo->createQueryBuilder('cf')
@@ -27,6 +27,7 @@ $qb = $repo->createQueryBuilder('cf')
    ->join('cf.fichier', 'f')
    ->join('f.nature', 'nf')
    ->where('1 = pasHistorise(f)');
/** @var ContenuFichier[] $result */
$result = $qb/*->setMaxResults(50)*/->getQuery()->getArrayResult();

$createdFiles = [];
@@ -34,7 +35,6 @@ $existingFiles = [];
$totalSize = 0;

foreach ($result as $cf) {
    /** @var ContenuFichier $cf */
    $dir = $rootdir . '/' . strtolower($cf['fichier']['nature']['code']);

    $filename = $cf['fichier']['nom'];
@@ -57,9 +57,9 @@ foreach ($result as $cf) {
    if (! file_exists($filepath)) {
        throw new \UnicaenApp\Exception\RuntimeException("Created file not found : " . $filepath);
    }
    if (($size = filesize($filepath)) !== $filesize) {
        throw new \UnicaenApp\Exception\RuntimeException("Size mismatch ($size !== $filesize) for " . $filepath);
    }
//    if (($size = filesize($filepath)) !== $filesize) {
//        throw new \UnicaenApp\Exception\RuntimeException("Size mismatch ($size !== $filesize) for " . $filepath);
//    }

    $createdFiles[] = $filepath;
    $totalSize += filesize($filepath);
@@ -70,4 +70,4 @@ var_dump($existingFiles);
echo 'Fichiers créés :';
var_dump($createdFiles);
echo 'Taille totale :';
var_dump($totalSize . ' (' . $totalSize/1024/1024 . 'Go)');
 No newline at end of file
var_dump($totalSize . ' (' . $totalSize/1024/1024 . ' Mo)');

code/test.php

deleted100644 → 0
+0 −82
Original line number Diff line number Diff line
<?php
/**
 * @var $this \Zend\View\Renderer\PhpRenderer
 * @var $controller \UnicaenCode\Controller\Controller
 * @var $viewName string
 */

use Application\Entity\Db\These;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\ClassMetadata;

/** @var EntityManager $em */
$em = $controller->getServiceLocator()->get('doctrine.entitymanager.orm_default');

/** @var ClassMetadata[] $doctrineMetadatas */
$doctrineMetadatas = $em->getMetadataFactory()->getAllMetadata();
//$em->getMetadataFactory()->setCacheDriver(new FilesystemCache('/tmp/doctrine'));

$namespace = 'Application\Entity\Db';

$doctrineMetadatas = array_filter($doctrineMetadatas, function(ClassMetadata $meta) use ($namespace) {
    return $meta->namespace === $namespace;
});
$doctrineMetadatas = array_filter($doctrineMetadatas, function(ClassMetadata $meta) use ($namespace) {
    return !in_array(substr($meta->name, strlen($namespace) + 1), [
        'Privilege',
        'Role',
        'Utilisateur',
        'WfEtape',
        'Parametre',
        'Variable',
        'ImportObserv',
        'ImportObservResult',
        'Civilite',
        'VWfEtapePertin',
        'Env',
        'VWorkflow',
    ]);
});
//var_dump($metas);

var_dump(preg_match("#1\s234,00#", "1 234,00"));

$metadatas = [];
foreach ($doctrineMetadatas as $meta) {
    $obj = new stdClass();
    $obj->name = $meta->name;
    $obj->columnNames = array_keys($meta->columnNames);
    $obj->associationMappings = array_keys($meta->associationMappings);
    $metadatas[$meta->name] = $obj;
//    var_dump($obj);
}

//var_dump($metadatas[These::class]);


// 'These.etatThese = E and These.codeUniteRecherche = E400 and These.dateSoutenance <= 30'

$qb = $em->getRepository(These::class)->createQueryBuilder('these')
    ->select('these, d, i')
    ->join('these.directeurs', 'd')
    ->join('d.individu', 'i')
    ->andWhere('these.codeUniteRecherche = \'EA4651\'')
    ;
//var_dump($qb->getQuery()->getArrayResult());

?>
<table class="table table-bordered">
    <tr>
        <th>name</th>
        <th>columnNames</th>
        <th>associationMappings</th>
    </tr>
    <?php foreach ($metadatas as $metadata): ?>
        <tr>
            <td><?php print_r($metadata->name) ?> </td>
            <td><?php print_r(implode('<br>', $metadata->columnNames )) ?> </td>
            <td><?php print_r(implode('<br>', $metadata->associationMappings)) ?> </td>
        </tr>
    <?php endforeach ?>
</table>
+62 −0
Original line number Diff line number Diff line
<?php
/**
 * @var $this \Zend\View\Renderer\PhpRenderer
 * @var $controller \UnicaenCode\Controller\Controller
 * @var $viewName string
 */

use Application\Entity\Db\Fichier;
use Application\Entity\Db\NatureFichier;
use Application\Filter\NomFichierFormatter;
use Application\Service\Fichier\FichierService;
use Doctrine\ORM\EntityManager;

set_time_limit(120);

/** @var FichierService $fs */
$fs = $controller->getServiceLocator()->get('FichierService');
//$rootdir = $fs->getRootDirectoryPath();
$rootdir = '/tmp/sygal-files';

$repo = $fs->getEntityManager()->getRepository(Fichier::class);
$qb = $repo->createQueryBuilder('f');
$qb
    ->addSelect('nf, t')
    ->join('f.nature', 'nf')
    ->join('f.these', 't')
    ->where('1 = pasHistorise(f)')
//    ->andWhere($qb->expr()->in('nf.code', [NatureFichier::CODE_THESE_PDF, NatureFichier::CODE_FICHIER_NON_PDF]))
    ->orderBy('nf.code');
/** @var Fichier[] $fichiers */
$fichiers = $qb/*->setMaxResults(50)*/->getQuery()->getResult();

$nomFichierFormatter = new NomFichierFormatter();

foreach ($fichiers as $fichier) {
    $newNom = $nomFichierFormatter->filter($fichier);
    $fichier->setNom($newNom);
}

/** @var EntityManager $em */
$em = $controller->getServiceLocator()->get('doctrine.entitymanager.orm_default');
$em->flush($fichiers);
?>

<table>
    <thead>
        <tr>
            <th>Nature</th>
            <th>Nom</th>
            <th>Nom original</th>
        </tr>
    </thead>
    <tbody>
        <?php foreach ($fichiers as $fichier): ?>
        <tr>
            <td><?php echo $fichier->getNature()->getCode() ?></td>
            <td><?php echo $fichier->getNom() ?></td>
            <td><?php echo $fichier->getNomOriginal() ?></td>
        </tr>
        <?php endforeach ?>
    </tbody>
</table>
 No newline at end of file
+1 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ services:
    volumes:
     - .:/var/www/html/sygal
     - /var/sygal-files:/var/sygal-files
     - /tmp:/tmp
    working_dir: /var/www/html/sygal
    network_mode: bridge