Loading module/Application/src/Application/Controller/FichierController.php +10 −1 Changes for module/Application/src/Application/Controller/FichierController.php: 10 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ use Application\Entity\Db\Fichier; use Application\Entity\Db\NatureFichier; use Application\Provider\Privilege\FichierPrivileges; use Application\RouteMatch; use Application\Service\Fichier\Exception\FichierServiceException; use Application\Service\Fichier\FichierServiceAwareTrait; use Application\View\Helper\Sortable; use BjyAuthorize\Exception\UnAuthorizedException; Loading Loading @@ -91,7 +92,11 @@ class FichierController extends AbstractController $fichier = $this->requestFichier(); // injection préalable du contenu du fichier pour pouvoir utiliser le plugin Uploader try { $contenuFichier = $this->fichierService->fetchContenuFichier($fichier); } catch (FichierServiceException $e) { throw new RuntimeException("Impossible d'obtenir le contenu du fichier", null, $e); } $fichier->setContenuFichierData($contenuFichier); $this->uploader()->download($fichier); Loading @@ -103,11 +108,15 @@ class FichierController extends AbstractController /** @var Fichier|null $fichier */ $fichier = $this->fichierService->getRepository()->findOneBy(['idPermanent' => $idPermanent]); if( $fichier === null) { throw new RuntimeException("Fichier introuvable"); throw new RuntimeException("Fichier introuvable en base de données"); } // injection préalable du contenu du fichier pour pouvoir utiliser le plugin Uploader try { $contenuFichier = $this->fichierService->fetchContenuFichier($fichier); } catch (FichierServiceException $e) { throw new RuntimeException("Impossible d'obtenir le contenu du fichier", null, $e); } $fichier->setContenuFichierData($contenuFichier); $this->uploader()->download($fichier); Loading module/Application/src/Application/Controller/FichierTheseController.php +5 −0 Changes for module/Application/src/Application/Controller/FichierTheseController.php: 5 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -10,6 +10,7 @@ use Application\Entity\Db\VersionFichier; use Application\EventRouterReplacerAwareTrait; use Application\Filter\IdifyFilterAwareTrait; use Application\RouteMatch; use Application\Service\Fichier\Exception\FichierServiceException; use Application\Service\Fichier\FichierServiceAwareTrait; use Application\Service\FichierThese\Exception\DepotImpossibleException; use Application\Service\FichierThese\Exception\ValidationImpossibleException; Loading Loading @@ -171,7 +172,11 @@ class FichierTheseController extends AbstractController } // injection préalable du contenu du fichier pour pouvoir utiliser le plugin Uploader try { $contenuFichier = $this->fichierService->fetchContenuFichier($fichier); } catch (FichierServiceException $e) { throw new RuntimeException("Impossible d'obtenir le contenu du fichier", null, $e); } $fichier->setContenuFichierData($contenuFichier); // Envoi du fichier au client (navigateur) Loading module/Application/src/Application/Service/Fichier/Exception/FichierServiceException.php 0 → 100644 +8 −0 Changes for module/Application/src/Application/Service/Fichier/Exception/FichierServiceException.php: 8 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace Application\Service\Fichier\Exception; class FichierServiceException extends \Exception { } No newline at end of file module/Application/src/Application/Service/Fichier/FichierService.php +8 −8 Changes for module/Application/src/Application/Service/Fichier/FichierService.php: 8 added lines, 8 removed lines. Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ use Application\Entity\Db\VersionFichier; use Application\Filter\AbstractNomFichierFormatter; use Application\Filter\NomFichierFormatter; use Application\Service\BaseService; use Application\Service\Fichier\Exception\FichierServiceException; use Application\Service\File\FileServiceAwareTrait; use Application\Service\NatureFichier\NatureFichierServiceAwareTrait; use Application\Service\ValiditeFichier\ValiditeFichierServiceAwareTrait; Loading Loading @@ -177,7 +178,7 @@ class FichierService extends BaseService * * @param Fichier[] $fichiers */ public function supprimerFichiers(array $fichiers) public function supprimerFichiers(array $fichiers, bool $throwExceptionOnFileError = false) { $filePaths = []; $this->entityManager->beginTransaction(); Loading @@ -202,12 +203,12 @@ class FichierService extends BaseService // suppression des fichiers physiques sur le disque $notDeletedFiles = []; foreach ($filePaths as $filePath) { $success = unlink($filePath); $success = file_exists($filePath) && unlink($filePath); if ($success === false) { $notDeletedFiles[] = $filePath; } } if ($notDeletedFiles) { if ($throwExceptionOnFileError && $notDeletedFiles) { throw new RuntimeException( "Les fichiers suivants n'ont pas pu être supprimés sur le disque : " . implode(', ', $notDeletedFiles)); } Loading @@ -218,19 +219,18 @@ class FichierService extends BaseService * * @param Fichier $fichier * @return string * @throws \Application\Service\Fichier\Exception\FichierServiceException */ public function fetchContenuFichier(Fichier $fichier) public function fetchContenuFichier(Fichier $fichier): string { $filePath = $this->computeDestinationFilePathForFichier($fichier); if (!is_readable($filePath)) { throw new RuntimeException( throw new FichierServiceException( "Le fichier suivant n'existe pas ou n'est pas accessible sur le serveur : " . $filePath); } $contenuFichier = file_get_contents($filePath); return $contenuFichier; return file_get_contents($filePath); } /** Loading Loading
module/Application/src/Application/Controller/FichierController.php +10 −1 Changes for module/Application/src/Application/Controller/FichierController.php: 10 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ use Application\Entity\Db\Fichier; use Application\Entity\Db\NatureFichier; use Application\Provider\Privilege\FichierPrivileges; use Application\RouteMatch; use Application\Service\Fichier\Exception\FichierServiceException; use Application\Service\Fichier\FichierServiceAwareTrait; use Application\View\Helper\Sortable; use BjyAuthorize\Exception\UnAuthorizedException; Loading Loading @@ -91,7 +92,11 @@ class FichierController extends AbstractController $fichier = $this->requestFichier(); // injection préalable du contenu du fichier pour pouvoir utiliser le plugin Uploader try { $contenuFichier = $this->fichierService->fetchContenuFichier($fichier); } catch (FichierServiceException $e) { throw new RuntimeException("Impossible d'obtenir le contenu du fichier", null, $e); } $fichier->setContenuFichierData($contenuFichier); $this->uploader()->download($fichier); Loading @@ -103,11 +108,15 @@ class FichierController extends AbstractController /** @var Fichier|null $fichier */ $fichier = $this->fichierService->getRepository()->findOneBy(['idPermanent' => $idPermanent]); if( $fichier === null) { throw new RuntimeException("Fichier introuvable"); throw new RuntimeException("Fichier introuvable en base de données"); } // injection préalable du contenu du fichier pour pouvoir utiliser le plugin Uploader try { $contenuFichier = $this->fichierService->fetchContenuFichier($fichier); } catch (FichierServiceException $e) { throw new RuntimeException("Impossible d'obtenir le contenu du fichier", null, $e); } $fichier->setContenuFichierData($contenuFichier); $this->uploader()->download($fichier); Loading
module/Application/src/Application/Controller/FichierTheseController.php +5 −0 Changes for module/Application/src/Application/Controller/FichierTheseController.php: 5 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -10,6 +10,7 @@ use Application\Entity\Db\VersionFichier; use Application\EventRouterReplacerAwareTrait; use Application\Filter\IdifyFilterAwareTrait; use Application\RouteMatch; use Application\Service\Fichier\Exception\FichierServiceException; use Application\Service\Fichier\FichierServiceAwareTrait; use Application\Service\FichierThese\Exception\DepotImpossibleException; use Application\Service\FichierThese\Exception\ValidationImpossibleException; Loading Loading @@ -171,7 +172,11 @@ class FichierTheseController extends AbstractController } // injection préalable du contenu du fichier pour pouvoir utiliser le plugin Uploader try { $contenuFichier = $this->fichierService->fetchContenuFichier($fichier); } catch (FichierServiceException $e) { throw new RuntimeException("Impossible d'obtenir le contenu du fichier", null, $e); } $fichier->setContenuFichierData($contenuFichier); // Envoi du fichier au client (navigateur) Loading
module/Application/src/Application/Service/Fichier/Exception/FichierServiceException.php 0 → 100644 +8 −0 Changes for module/Application/src/Application/Service/Fichier/Exception/FichierServiceException.php: 8 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace Application\Service\Fichier\Exception; class FichierServiceException extends \Exception { } No newline at end of file
module/Application/src/Application/Service/Fichier/FichierService.php +8 −8 Changes for module/Application/src/Application/Service/Fichier/FichierService.php: 8 added lines, 8 removed lines. Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ use Application\Entity\Db\VersionFichier; use Application\Filter\AbstractNomFichierFormatter; use Application\Filter\NomFichierFormatter; use Application\Service\BaseService; use Application\Service\Fichier\Exception\FichierServiceException; use Application\Service\File\FileServiceAwareTrait; use Application\Service\NatureFichier\NatureFichierServiceAwareTrait; use Application\Service\ValiditeFichier\ValiditeFichierServiceAwareTrait; Loading Loading @@ -177,7 +178,7 @@ class FichierService extends BaseService * * @param Fichier[] $fichiers */ public function supprimerFichiers(array $fichiers) public function supprimerFichiers(array $fichiers, bool $throwExceptionOnFileError = false) { $filePaths = []; $this->entityManager->beginTransaction(); Loading @@ -202,12 +203,12 @@ class FichierService extends BaseService // suppression des fichiers physiques sur le disque $notDeletedFiles = []; foreach ($filePaths as $filePath) { $success = unlink($filePath); $success = file_exists($filePath) && unlink($filePath); if ($success === false) { $notDeletedFiles[] = $filePath; } } if ($notDeletedFiles) { if ($throwExceptionOnFileError && $notDeletedFiles) { throw new RuntimeException( "Les fichiers suivants n'ont pas pu être supprimés sur le disque : " . implode(', ', $notDeletedFiles)); } Loading @@ -218,19 +219,18 @@ class FichierService extends BaseService * * @param Fichier $fichier * @return string * @throws \Application\Service\Fichier\Exception\FichierServiceException */ public function fetchContenuFichier(Fichier $fichier) public function fetchContenuFichier(Fichier $fichier): string { $filePath = $this->computeDestinationFilePathForFichier($fichier); if (!is_readable($filePath)) { throw new RuntimeException( throw new FichierServiceException( "Le fichier suivant n'existe pas ou n'est pas accessible sur le serveur : " . $filePath); } $contenuFichier = file_get_contents($filePath); return $contenuFichier; return file_get_contents($filePath); } /** Loading