Commit 9fd3fbb4 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Merge branch 'fix-chemins-logos-#16813'

parents 0c77aa6a 20413443
Loading
Loading
Loading
Loading
Loading

code/check-nommage-fichier.php

deleted100644 → 0
+0 −65
Changes for code/check-nommage-fichier.php: 0 added lines, 65 removed lines.
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>Date</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->getHistoModification()->format('d/m/Y à H:i:s') ?></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
+0 −73
Changes for code/create-files-from-contenu-fichiers.php: 0 added lines, 73 removed lines.
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\ContenuFichier;
use Application\Service\Fichier\FichierService;

//////////////////////////////////////////////////////////////////////////
//
// Parcours en BDD des fichiers déposés pour les stocker sur le disque.
//
//////////////////////////////////////////////////////////////////////////

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')
    ->addSelect('f, nf')
    ->join('cf.fichier', 'f')
    ->join('f.nature', 'nf')
    ->where('1 = pasHistorise(f)');
/** @var ContenuFichier[] $result */
$result = $qb/*->setMaxResults(50)*/->getQuery()->getArrayResult();

$createdFiles = [];
$existingFiles = [];
$totalSize = 0;

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

    $filename = $cf['fichier']['nom'];
    $filesize = $cf['fichier']['taille'];
    $filepath = $dir . '/' . $filename;

    if (file_exists($filepath)) {
        $existingFiles[] = $filepath;
        $totalSize += filesize($filepath);
        continue;
    }

    if (! \Application\Util::createWritableFolder($dir, 0770)) {
        throw new RuntimeException("Le répertoire suivant n'a pas pu être créé sur le serveur : " . $dir);
    }

    $content = stream_get_contents($cf['data']);
    file_put_contents($filepath, $content);

    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);
//    }

    $createdFiles[] = $filepath;
    $totalSize += filesize($filepath);
}

echo 'Fichiers déjà présents :';
var_dump($existingFiles);
echo 'Fichiers créés :';
var_dump($createdFiles);
echo 'Taille totale :';
var_dump($totalSize . ' (' . $totalSize/1024/1024 . ' Mo)');

code/update-nommage-fichiers.php

deleted100644 → 0
+0 −68
Changes for code/update-nommage-fichiers.php: 0 added lines, 68 removed lines.
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();

$updatedFichiers = [];
foreach ($fichiers as $fichier) {
    $newNom = $nomFichierFormatter->filter($fichier);
    $updateRequired = $newNom !== $fichier->getNom();

    if ($updateRequired) {
        $fichier->setNom($newNom);
        $updatedFichiers[] = $fichier;
    }
}

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

<table>
    <thead>
    <tr>
        <th>Nature</th>
        <th>Nom</th>
        <th>Nom original</th>
    </tr>
    </thead>
    <tbody>
    <?php foreach ($updatedFichiers 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
+2 −0
Changes for composer.json: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -12,7 +12,9 @@
        "zendframework/zend-developer-tools":   "^1.0"
    },
    "require": {
        "ext-fileinfo":                         "*",
        "ext-json":                             "*",
        "ext-imagick":                          "*",
        "unicaen/app":                          "^1.3",
        "unicaen/auth":                         "^1.2",
        "unicaen/faq":                          "^1.0",
+7 −3
Changes for composer.lock: 7 added lines, 3 removed lines.
Original line number Diff line number Diff line
{
    "_readme": [
        "This file locks the dependencies of your project to a known state",
        "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
        "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
        "This file is @generated automatically"
    ],
    "content-hash": "bd8c3d3e91508f7df99c5680292ae9d2",
    "content-hash": "f887ed33b669d08f32be78e1333d31ee",
    "packages": [
        {
            "name": "beberlei/assert",
@@ -3841,6 +3841,10 @@
    },
    "prefer-stable": false,
    "prefer-lowest": false,
    "platform": [],
    "platform": {
        "ext-fileinfo": "*",
        "ext-json": "*",
        "ext-imagick": "*"
    },
    "platform-dev": []
}
Loading