diff --git a/cosmogramme/php/integre_traite_main.php b/cosmogramme/php/integre_traite_main.php index 2ec8fe031cb4c91caeecb7ffc3a28a7a038cedd7..af80b939a9fec51e04c84bc8faf0a6dece51ae9f 100644 --- a/cosmogramme/php/integre_traite_main.php +++ b/cosmogramme/php/integre_traite_main.php @@ -128,7 +128,6 @@ if ($_REQUEST['reprise'] == 'oui') { exit; } - setVariable('integration_date', $date); (new maj_auto())->supprimerEntetesPergame(); // ---------------------------------------------------------------- diff --git a/library/Class/Cosmogramme/Integration/PhasePrepareIntegrations.php b/library/Class/Cosmogramme/Integration/PhasePrepareIntegrations.php index c11810e66afe154fb2902f2106dcf7e8bc68846a..05a460aadf5dea2b3013bfe76d624b42d9140ad6 100644 --- a/library/Class/Cosmogramme/Integration/PhasePrepareIntegrations.php +++ b/library/Class/Cosmogramme/Integration/PhasePrepareIntegrations.php @@ -52,6 +52,9 @@ class Class_Cosmogramme_Integration_PhasePrepareIntegrations extends Class_Cosmo $this->_runOne($majauto); $this->_log->ecrire('</table>'); + + Class_CosmoVar::setValueOf('integration_date', + $this->getTimeSource()->dateDayAndHours()); } diff --git a/library/Class/TimeSource.php b/library/Class/TimeSource.php index 6c723f398bfb54def5f6baea54542174a6ed6ae6..54bc37b228bc3b4c748a80ccdfaedc13fa50adbc 100644 --- a/library/Class/TimeSource.php +++ b/library/Class/TimeSource.php @@ -31,7 +31,12 @@ class Class_TimeSource { public function dateYmd() { - return date('Y-m-d', $this->time()); + return $this->dateFormat('Y-m-d'); + } + + + public function dateDayAndHours() { + return $this->dateFormat('Y-m-d H:i:s'); } diff --git a/library/ZendAfi/View/Helper/Admin/CosmoStatus.php b/library/ZendAfi/View/Helper/Admin/CosmoStatus.php index c228c197ee90e1a29591cccaccca73ea395e09b9..b4731253a2e0e4a0c4afa7b6e881002d825f507a 100644 --- a/library/ZendAfi/View/Helper/Admin/CosmoStatus.php +++ b/library/ZendAfi/View/Helper/Admin/CosmoStatus.php @@ -23,13 +23,18 @@ class ZendAfi_View_Helper_Admin_CosmoStatus extends ZendAfi_View_Helper_BaseHelper { use Trait_TimeSource; + protected + $_date_integration, + $_clef_traitement; + public function cosmoStatus() { - $date_integration = Class_CosmoVar::getValueOf('integration_date'); + $this->_date_integration = Class_CosmoVar::getValueOf('integration_date'); + $this->_clef_traitement = Class_CosmoVar::getValueOf('clef_traitements'); return $this->title() - . $this->lastRun($date_integration) + . $this->lastRun() . $this->currentRun() - . $this->lag($date_integration) + . $this->lag() . $this->tasksWaiting(); } @@ -39,27 +44,34 @@ class ZendAfi_View_Helper_Admin_CosmoStatus extends ZendAfi_View_Helper_BaseHelp } - protected function lastRun($date_integration) { - return $this->info($this->_('Dernier traitement d\'intégration effectué le'), - Class_Date::getHumanDate($date_integration, 'd MMMM yyyy')); + protected function lastRun() { + return !$this->isRunning() + ? $this->info($this->_('Dernier traitement d\'intégration effectué le'), + Class_Date::getHumanDate($this->_date_integration, 'd MMMM yyyy')) + : ''; } protected function currentRun() { - return '1' == Class_CosmoVar::getValueOf('clef_traitements') - ? $this->info($this->_('La base est bloquée - phase de traitement'), - Class_CosmoVar::getValueOf('traitement_phase')) + return $this->isRunning() + ? $this->info($this->_('Traitement en cours depuis le'), + Class_Date::getHumanDate($this->_date_integration) + . ' (' . Class_CosmoVar::getValueOf('traitement_phase') . ')') : ''; } - protected function lag($date_integration) { - $ecart = $this->getTimeSource()->daysFrom(strtotime($date_integration)); - $frequence = (int)Class_CosmoVar::getValueOf('integration_frequence'); + protected function lag() { + if (!$this->_date_integration + || (!$frequence = (int)Class_CosmoVar::getValueOf('integration_frequence'))) + return ''; + + $diff = $this->getTimeSource()->daysFrom(strtotime($this->_date_integration)); + $late = $diff - $frequence; - return 0 < $frequence && $frequence < $ecart - ? $this->error($this->_('Les traitements d\'intégration n\'ont pas été effectués depuis'), - $this->_('%s jours', $ecart)) + return $frequence < $diff + ? $this->error($this->_('Traitements d\'intégration en retard de'), + $this->_('%s jours', $late)) : ''; } @@ -80,4 +92,9 @@ class ZendAfi_View_Helper_Admin_CosmoStatus extends ZendAfi_View_Helper_BaseHelp protected function info($label, $value) { return $this->view->ligneInfos($label, $value); } + + + protected function isRunning() { + return '1' == $this->_clef_traitement; + } } \ No newline at end of file diff --git a/tests/application/modules/admin/controllers/IndexControllerTest.php b/tests/application/modules/admin/controllers/IndexControllerTest.php index fb4564d68567ab06630ae8a2037d3b1d613542fe..4756d523364dbcc5a2d16e7dbce9adbeed4c7392 100644 --- a/tests/application/modules/admin/controllers/IndexControllerTest.php +++ b/tests/application/modules/admin/controllers/IndexControllerTest.php @@ -42,7 +42,7 @@ class Admin_IndexControllerTest extends Admin_IndexControllerTestCase { $this->fixture('Class_CosmoVar', ['id' => 'integration_date', 'clef' => 'integration_date', - 'valeur' => '2016-10-25']); + 'valeur' => '2016-10-25 13:12:34']); $this->fixture('Class_CosmoVar', ['id' => 'clef_traitements', @@ -57,9 +57,9 @@ class Admin_IndexControllerTest extends Admin_IndexControllerTestCase { $this->fixture('Class_CosmoVar', ['id' => 'integration_frequence', 'clef' => 'integration_frequence', - 'valeur' => '1']); + 'valeur' => '7']); - ZendAfi_View_Helper_Admin_CosmoStatus::setTimeSource(new TimeSourceForTest('2016-11-07 12:27:45')); + ZendAfi_View_Helper_Admin_CosmoStatus::setTimeSource(new TimeSourceForTest('2016-11-03 14:27:45')); $this->dispatch('/admin/index/index', true); } @@ -126,20 +126,15 @@ class Admin_IndexControllerTest extends Admin_IndexControllerTestCase { /** @test */ - public function lastIntegrationDateShouldBe2016_10_25() { - $this->assertXPathContentContains('//b', '25 octobre 2016'); - } - - - /** @test */ - public function integrationShouldBeInProgress() { - $this->assertXPathContentContains('//b', 'Execution des batchs programmés'); + public function integrationShouldBeRunningSince2016_10_25() { + $this->assertXPathContentContains('//b', '25 octobre 2016 13:12:34 (Execution des batchs programmés)', + $this->_response->getBody()); } /** @test */ - public function lastIntegrationShouldBeLateFrom14Days() { - $this->assertXPathContentContains('//b', '13 jours', $this->_response->getBody()); + public function lastIntegrationShouldBeLateFrom1Day() { + $this->assertXPathContentContains('//b', '1 jours', $this->_response->getBody()); } diff --git a/tests/library/Class/Cosmogramme/Integration/PhasePrepareIntegrationsTest.php b/tests/library/Class/Cosmogramme/Integration/PhasePrepareIntegrationsTest.php index ac7d1a7065320860eb08d8c0de50e2363cc3e5bf..79c815e03f47ae55a599dc3c83ef79d9ce91cb27 100644 --- a/tests/library/Class/Cosmogramme/Integration/PhasePrepareIntegrationsTest.php +++ b/tests/library/Class/Cosmogramme/Integration/PhasePrepareIntegrationsTest.php @@ -53,9 +53,7 @@ abstract class PhasePrepareIntegrationsWithOAITestCase extends Class_Cosmogramme ->beStrict(); Class_Cosmogramme_Integration_PhasePrepareIntegrations::setFileSystem($file_system); - - $time_source = $this->mock()->whenCalled('time')->answers(strtotime('2015-03-26')); - Class_Cosmogramme_Integration_PhasePrepareIntegrations::setTimeSource($time_source); + Class_Cosmogramme_Integration_PhasePrepareIntegrations::setTimeSource(new TimeSourceForTest('2015-03-26 14:00:00')); $this->_phase = $this->_buildPhase('PrepareIntegrations')->run(); } @@ -71,6 +69,9 @@ abstract class PhasePrepareIntegrationsWithOAITestCase extends Class_Cosmogramme $this->fixture('Class_CosmoVar', ['id' => 'ftp_path', 'valeur' => 'ftp/my-library.net/transferts/']); + $this->fixture('Class_CosmoVar', + ['id' => 'integration_date', 'valeur' => '2015-03-23 12:00:00']); + $this->fixture('Class_IntProfilDonnees', ['id' => 102, 'libelle' => 'Unimarc Pergame', @@ -155,6 +156,13 @@ abstract class PhasePrepareIntegrationsWithOAITestCase extends Class_Cosmogramme class PhasePrepareIntegrationsWithOAITest extends PhasePrepareIntegrationsWithOAITestCase { + /** @test */ + public function integrationDateShouldBe2016_11_09_14h() { + $this->assertEquals('2015-03-26 14:00:00', + Class_CosmoVar::getValueOf('integration_date')); + } + + /** @test */ public function twoIntegrationsShouldHaveBeenCreated() { $this->assertEquals(3, count(Class_Cosmogramme_Integration::findAll()));