From 5526894f3bea8af8f52db96324ce0da318c78c47 Mon Sep 17 00:00:00 2001 From: Laurent Laffont <llaffont@afi-sa.fr> Date: Fri, 26 Oct 2018 10:51:35 +0200 Subject: [PATCH] hotline #81124 Cosmogramme : fix minimum integration file size computation --- VERSIONS_HOTLINE/81124 | 1 + .../Integration/PhasePrepareIntegrations.php | 12 +++---- .../PhasePrepareIntegrationsTest.php | 34 ++++++++++++++++++- 3 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 VERSIONS_HOTLINE/81124 diff --git a/VERSIONS_HOTLINE/81124 b/VERSIONS_HOTLINE/81124 new file mode 100644 index 00000000000..45f3dba511f --- /dev/null +++ b/VERSIONS_HOTLINE/81124 @@ -0,0 +1 @@ + - ticket #81124 : Cosmogramme : correction de la précision du calcul des tailles minimum des fichiers à intégrer \ No newline at end of file diff --git a/library/Class/Cosmogramme/Integration/PhasePrepareIntegrations.php b/library/Class/Cosmogramme/Integration/PhasePrepareIntegrations.php index a82d99b7e37..602a1eef9ba 100644 --- a/library/Class/Cosmogramme/Integration/PhasePrepareIntegrations.php +++ b/library/Class/Cosmogramme/Integration/PhasePrepareIntegrations.php @@ -188,19 +188,17 @@ class Class_Cosmogramme_Integration_PhasePrepareIntegrations extends Class_Cosmo return false; $file_type = $profil->getTypeFichier(); - $minsize = $majauto->getTailleMinImportTotal(); + $minsize = $majauto->getTailleMinImportTotal() * 1024 * 1024; $type_operation = $majauto->getTypeOperation(); if ($minsize > 0 && $file_type == 0 && $type_operation == 2) { - $file_size = filesize($file); - if ($file_size > 0) - $file_size = (int) (($file_size / 1024) / 1024); - + $file_size = $this->getFileSystem()->filesize($file); if ($file_size < $minsize) { $this->_log ->log(sprintf('<span class="rouge">%s</span></td>', - $this->_('Le fichier est trop petit : %s mo -> taille minimum attendue : %s mo', - $file_size, $minsize))); + $this->_('Le fichier est trop petit : %s o -> taille minimum attendue : %s o', + $file_size, + $minsize))); return false; } } diff --git a/tests/library/Class/Cosmogramme/Integration/PhasePrepareIntegrationsTest.php b/tests/library/Class/Cosmogramme/Integration/PhasePrepareIntegrationsTest.php index c6dac7b3f68..c6192da2af5 100644 --- a/tests/library/Class/Cosmogramme/Integration/PhasePrepareIntegrationsTest.php +++ b/tests/library/Class/Cosmogramme/Integration/PhasePrepareIntegrationsTest.php @@ -32,6 +32,18 @@ abstract class PhasePrepareIntegrationsWithOAITestCase ->with ('ftp/my-library.net/transferts/foo/mylibrarytotal.txt') ->answers(true) + ->whenCalled('filesize') + ->with ('ftp/my-library.net/transferts/foo/mylibrarytotal.txt') + ->answers(11000000) + + ->whenCalled('is_file') + ->with ('ftp/my-library.net/transferts/foo/toosmall.txt') + ->answers(true) + + ->whenCalled('filesize') + ->with ('ftp/my-library.net/transferts/foo/toosmall.txt') + ->answers(1000000) + ->whenCalled('is_file') ->with ('ftp/my-library.net/transferts/foo/20180517mylibraryincr.txt') ->answers(true) @@ -135,7 +147,7 @@ abstract class PhasePrepareIntegrationsWithOAITestCase 'type_doc' => 0, 'nom_fichier' => 'foo/mylibrarytotal.txt', 'rang' => 100, - 'taille_min_import_total' => 0]); + 'taille_min_import_total' => 10]); $this->fixture('Class_IntMajAuto', ['id' => 101, 'id_prog' => 101, @@ -159,6 +171,20 @@ abstract class PhasePrepareIntegrationsWithOAITestCase 'rang' => 102, 'taille_min_import_total' => 0]); + + + $this->fixture('Class_IntMajAuto', ['id' => 104, + 'id_prog' => 104, + 'id_bib' => 2, + 'libelle' => 'Notices - too small', + 'profil' => 102, + 'type_operation' => 2, + 'type_doc' => 0, + 'nom_fichier' => 'foo/toosmall.txt', + 'rang' => 100, + 'taille_min_import_total' => 10]); + + $this->fixture('Class_Cosmogramme_Integration', ['id' => 1, 'id_bib' => 2, @@ -249,6 +275,12 @@ class PhasePrepareIntegrationsWithOAITest extends PhasePrepareIntegrationsWithOA } + /** @test */ + public function logShouldContainsFileTooSmall() { + $this->assertLogContains('<td class="blank">foo/toosmall.txt</td><td class="blank"> <span class="rouge">Le fichier est trop petit : 1000000 o -> taille minimum attendue : 10485760 o'); + } + + /** * @expectedException Class_Cosmogramme_Integration_PhasePrepareIntegrationsException * @expectedExceptionMessage La variable ftp_path n'est pas définie -- GitLab