diff --git a/VERSIONS_HOTLINE/143478 b/VERSIONS_HOTLINE/143478 new file mode 100644 index 0000000000000000000000000000000000000000..6ee8626fee5b8aa9eed36b14e4ef52721b32a44b --- /dev/null +++ b/VERSIONS_HOTLINE/143478 @@ -0,0 +1 @@ + - ticket #143478 : Cosmogramme : correction de la phase de suppression des fichiers d'intégrations. Les fichiers les plus anciens sont maintenant supprimés. \ No newline at end of file diff --git a/library/Class/Cosmogramme/Integration/PhaseFlushIntegrations.php b/library/Class/Cosmogramme/Integration/PhaseFlushIntegrations.php index 84ddc85ed4a4f374db239567a3e74c3a40ed6aa4..188710a21895c2710e94b274817f47424cb1623f 100644 --- a/library/Class/Cosmogramme/Integration/PhaseFlushIntegrations.php +++ b/library/Class/Cosmogramme/Integration/PhaseFlushIntegrations.php @@ -25,6 +25,9 @@ class Class_Cosmogramme_Integration_PhaseFlushIntegrations const MY_ID = 22; + protected $_count_archives=0, + $_count_deleted_files=0, + $_path; public function __construct($phase, $log, $chrono) { parent::__construct($phase, $log, $chrono); @@ -38,7 +41,7 @@ class Class_Cosmogramme_Integration_PhaseFlushIntegrations protected function _execute() { - if ( ! $path = Class_CosmoVar::getValueOf('integration_path')) + if ( ! $this->_path = Class_CosmoVar::getValueOf('integration_path')) return $this->_log->error($this->_('La configuration de CosmoVar integration_path est incorrecte. Aucun fichier d\'intégration ne sera supprimé.')); if ( ! $nb_max = Class_CosmoVar::getValueOf('integre_max_paniers')) @@ -52,27 +55,45 @@ class Class_Cosmogramme_Integration_PhaseFlushIntegrations $nb, $nb_max)); - $liste = Class_Cosmogramme_Integration::findAllBy(['traite not' => 'non', - 'destroy' => '0', - 'order' => 'id desc', - 'limit' => sprintf('%s, 10000', $nb_max)]); - Class_FileManager::beOpenBar(); - $count = 0; - foreach($liste as $integration) { - if ( ! $file = Class_FileManager::find($path . $integration->getFichier())) - continue; + $this->_count_archives = 0; + $this->_count_deleted_files = 0; - if ( false === (bool) Class_FileManager::delete($file)) - continue; + while($integrations = Class_Cosmogramme_Integration::findAllBy(['traite not' => 'non', + 'destroy' => '0', + 'order' => 'id desc', + 'limitPage' => [2, $nb_max]])) { + $this->_processPageIntegration($integrations); - $integration->setDestroy(1)->save(); - $count++; + $this->_cleanMemory(); } Class_FileManager::reset(); - $this->_log->success($this->_('%s fichiers d\'intégrations supprimés.', $count)); + $this->_log->success($this->_('%s intégrations ont été archivées. %s fichiers ont été supprimés.', + $this->_count_archives, + $this->_count_deleted_files)); + } + + + protected function _processPageIntegration($integrations){ + foreach($integrations as $integration) { + $integration + ->setDestroy(1) + ->save(); + + $this->_count_archives++; + + $integration_file_path = $this->_path . $integration->getFichier(); + if (!$file = Class_FileManager::find($integration_file_path)) + continue; + + if ( false === (bool) Class_FileManager::delete($file)) + continue; + + $this->_count_deleted_files++; + + } } } diff --git a/tests/library/Class/Cosmogramme/Integration/PhaseFlushIntegrationTest.php b/tests/library/Class/Cosmogramme/Integration/PhaseFlushIntegrationTest.php index fc98483c5a985a1622c3b86358ce4845fef7575a..3790bcb376a42a28f4007f7823c525a9db6df881 100644 --- a/tests/library/Class/Cosmogramme/Integration/PhaseFlushIntegrationTest.php +++ b/tests/library/Class/Cosmogramme/Integration/PhaseFlushIntegrationTest.php @@ -39,10 +39,18 @@ class PhaseFlushIntegrationWithFilesTestCase extends Class_Cosmogramme_Integrati $this->fixture(Class_Cosmogramme_Integration::class, ['id' => 3, - 'fichier' => 'integre3.pan']); + 'fichier' => 'integre1.pan']); $this->fixture(Class_Cosmogramme_Integration::class, ['id' => 4, + 'fichier' => 'integre2.pan']); + + $this->fixture(Class_Cosmogramme_Integration::class, + ['id' => 5, + 'fichier' => 'integre3.pan']); + + $this->fixture(Class_Cosmogramme_Integration::class, + ['id' => 6, 'fichier' => 'integre4.pan']); $integre2 = $this @@ -110,8 +118,8 @@ class PhaseFlushIntegrationWithFilesTestCase extends Class_Cosmogramme_Integrati /** @test */ - public function integrationsShouldHaveBeenSetToDestroy() { - $this->assertEquals(2, Class_Cosmogramme_Integration::countBy(['destroy' => 1])); + public function fourIntegrationsShouldHaveBeenSetToDestroy() { + $this->assertEquals(4, Class_Cosmogramme_Integration::countBy(['destroy' => 1])); } @@ -130,15 +138,29 @@ class PhaseFlushIntegrationWithFilesTestCase extends Class_Cosmogramme_Integrati /** @test */ - public function integrations3ShouldNotBeDestroy() { - $this->assertNotNull(Class_Cosmogramme_Integration::findFirstBy(['destroy' => 0, + public function integrations3ShouldBeDestroy() { + $this->assertNotNull(Class_Cosmogramme_Integration::findFirstBy(['destroy' => 1, 'id' => 3])); } /** @test */ - public function integrations4ShouldNotBeDestroy() { - $this->assertNotNull(Class_Cosmogramme_Integration::findFirstBy(['destroy' => 0, + public function integrations4ShouldBeDestroy() { + $this->assertNotNull(Class_Cosmogramme_Integration::findFirstBy(['destroy' => 1, 'id' => 4])); } -} + + + /** @test */ + public function integrations5ShouldNotBeDestroy() { + $this->assertNotNull(Class_Cosmogramme_Integration::findFirstBy(['destroy' => 0, + 'id' => 5])); + } + + + /** @test */ + public function integrations6ShouldNotBeDestroy() { + $this->assertNotNull(Class_Cosmogramme_Integration::findFirstBy(['destroy' => 0, + 'id' => 6])); + } +} \ No newline at end of file