Skip to content
Snippets Groups Projects
Commit c1e7f300 authored by Henri-Damien LAURENT's avatar Henri-Damien LAURENT
Browse files

hotline#143478 : cosmogramme : recent files are not kept

parent 94703882
Branches
Tags
2 merge requests!4289Hotline,!4287hotline#143478 : cosmogramme : recent files are not kept
Pipeline #15379 passed with stage
in 26 minutes and 48 seconds
- 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
......@@ -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++;
}
}
}
......@@ -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
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment