diff --git a/VERSIONS_HOTLINE/28103 b/VERSIONS_HOTLINE/28103 new file mode 100644 index 0000000000000000000000000000000000000000..9e229b1b29c7328d8fc15093e66721804ba4154c --- /dev/null +++ b/VERSIONS_HOTLINE/28103 @@ -0,0 +1 @@ + - ticket #28103 : Correction de l'exécution des batchs qui empêchait le moissonage des vignettes d'album 1dtouch \ No newline at end of file diff --git a/application/modules/admin/views/scripts/batch/index.phtml b/application/modules/admin/views/scripts/batch/index.phtml index f3785319ebe0aec694b01a7ef53cebc8f4c1048a..3073302f02165f8ff63ee81112d44f91d860ce86 100644 --- a/application/modules/admin/views/scripts/batch/index.phtml +++ b/application/modules/admin/views/scripts/batch/index.phtml @@ -7,7 +7,7 @@ echo $this->bouton('id=add', ); echo $this->tagModelTable( - $this->batchs, + $this->batchs, [$this->_('Libelle'), $this->_('Dernière exécution')], ['Libelle', 'last_run'], [ @@ -16,12 +16,13 @@ echo $this->tagModelTable( if ('MOISSONNAGE_CYBERLIBRIS' == $batch->getType()) return ''; - $action = (in_array($batch->getType(), - ['AUTOCOMPLETE_RECORD_TITLE', 'AUTOCOMPLETE_RECORD_AUTHOR'])) ? - 'run-ajax' : 'run'; - return $this->tagAnchor(['action' => $action, 'id' => $batch->getId()], + $action = (in_array($batch->getType(), + ['AUTOCOMPLETE_RECORD_TITLE', + 'AUTOCOMPLETE_RECORD_AUTHOR', + 'INDEX_RESSOURCES_NUMERIQUES'])) ? + 'run-ajax' : 'run'; + return $this->tagAnchor(['action' => $action, 'id' => $batch->getId()], $this->boutonIco('type=test', 'bulle=Lancer')); }], 'batchs'); - ?> diff --git a/library/Class/Batch/IndexRessourcesNumeriques.php b/library/Class/Batch/IndexRessourcesNumeriques.php index 77a0b1aa4647afa32cf36ab04f2d0aedaf6acc9b..dd30d9e7448d8a2b4c9f1b9f94eb88367e3a2bb8 100644 --- a/library/Class/Batch/IndexRessourcesNumeriques.php +++ b/library/Class/Batch/IndexRessourcesNumeriques.php @@ -7,9 +7,10 @@ class Class_Batch_IndexRessourcesNumeriques extends Class_Batch_Abstract { return $this->_("Indexer les ressources numériques"); } + public function run() { $current_page = -1; - do { + do { $albums = Class_Album::findAllBy(['limitPage' => [$current_page += 1, 100]]); foreach ($albums as $album) @@ -24,6 +25,32 @@ class Class_Batch_IndexRessourcesNumeriques extends Class_Batch_Abstract { (new Storm_Cache())->clean(); } + + public function runStep($params) { + $response = new stdClass; + if (empty($params) || !isset($params['done'])) { + $response->done = 0; + $response->total= 0; + return $response; + } + + $done = $params['done']; + $page_size = 100; + $page = ($done / $page_size) + 1; + $response->total = Class_Album::count(); + + $models = Class_Album::findAllBy(['limitPage' => [$page, $page_size]]); + foreach($models as $models) + $models->index(); + + $response->done = ($response->total > $done + $page_size) ? + $done + $page_size : + $done + count($models); + + return $response; + } + + public function isEnabled() { $types = Class_Batch::getRessourcesNumeriqueTypes(); foreach ($types as $instance) { diff --git a/library/Class/Cosmogramme/Integration/PhaseBatchs.php b/library/Class/Cosmogramme/Integration/PhaseBatchs.php index 887bd37f63b384eac29d3d8c4b7d6c5652c77372..8bb8714e42e16a16365b50f96011055f5cc2e77e 100644 --- a/library/Class/Cosmogramme/Integration/PhaseBatchs.php +++ b/library/Class/Cosmogramme/Integration/PhaseBatchs.php @@ -38,15 +38,25 @@ class Class_Cosmogramme_Integration_PhaseBatchs return; } - $batchs = Class_Batch::findAllBy(['order' => 'id']); - foreach($batchs as $batch) { + foreach(Class_Batch::findAllBy(['order' => 'id']) as $batch) { if ($this->_getData('pointeur_reprise') > $batch->getId()) continue; - $this->_runOne($batch); + + $this->_resetHttpClient() + ->_runOne($batch); } } + protected function _resetHttpClient() { + if (!$client = Zend_Registry::get('httpClient')) + return $this; + + $client->setAuth(null); + return $this; + } + + protected function _runOne($batch) { $this->_log->ecrire('<span class="vert">' . $batch->getLibelle().':'); $this->_setData('pointeur_reprise', $batch->getId()); diff --git a/library/Class/WebService/OAI.php b/library/Class/WebService/OAI.php index 9abb3b4b3aa648511da2ad82a2ffb76763a4a7f2..ad3cfced020f303aaba93e6623529c025065acdb 100644 --- a/library/Class/WebService/OAI.php +++ b/library/Class/WebService/OAI.php @@ -41,8 +41,10 @@ class Class_WebService_OAI extends Class_WebService_Abstract { protected $web_client; protected $numeric_resource_class = 'Class_WebService_BibNumerique_Numilog_LivreNumerique'; protected $_listRecordsResumptionToken; - protected $metadata_prefix='oai_dc'; + protected $metadata_prefix = 'oai_dc'; protected $_first_page = 1; + protected $_logger; + const ListSets = 'ListSets'; const ListRecords = 'ListRecords'; @@ -96,7 +98,23 @@ class Class_WebService_OAI extends Class_WebService_Abstract { $parameters = array_merge(['verb' => $verb], $parameters); $url = $this->oai_handler.'?'.http_build_query($parameters); - return $this->getContent($url); + $response = $this->getContent($url); + $this->_log($url, $response); + + return $response; + } + + + protected function _log($url, $response) { + if (!$this->_logger) + return; + $this->_logger->log($url, $response); + } + + + public function setLogger($logger) { + $this->_logger = $logger; + return $this; } diff --git a/tests/library/Class/Cosmogramme/Integration/PhaseBatchsTest.php b/tests/library/Class/Cosmogramme/Integration/PhaseBatchsTest.php index 6463d52559add4dea8474ff323d98402a87c235a..5814fa6d1156f02f1424f07a956701aa77417724 100644 --- a/tests/library/Class/Cosmogramme/Integration/PhaseBatchsTest.php +++ b/tests/library/Class/Cosmogramme/Integration/PhaseBatchsTest.php @@ -21,7 +21,7 @@ abstract class PhaseBatchsTestCase extends Class_Cosmogramme_Integration_PhaseTestCase { - protected $_batch; + protected $_batch, $_registry_http_client, $_mock_http_client; protected function _prepareFixtures() { $this->fixture('Class_Batch', @@ -41,8 +41,20 @@ abstract class PhaseBatchsTestCase extends Class_Cosmogramme_Integration_PhaseTe public function setUp() { parent::setUp(); + + $this->_registry_http_client = Zend_Registry::get('httpClient'); + $this->_mock_http_client = $this->mock(); + $this->_mock_http_client->whenCalled('setAuth')->answers($this->_mock_http_client); + Zend_Registry::set('httpClient', $this->_mock_http_client); + $this->_buildPhase('Batchs')->run(); } + + + public function tearDown() { + Zend_Registry::set('httpClient', $this->_registry_http_client); + parent::tearDown(); + } } @@ -102,6 +114,16 @@ class PhaseBatchsCronRunTest extends PhaseBatchsTestCase { public function shouldDisplayElapsedTime() { $this->assertLogContains('Temps de traitement'); } + + + /** + * @test + * @see http://forge.afi-sa.fr/issues/28103 + */ + public function httpAuthShouldHaveBeenReset() { + $this->assertTrue($this->_mock_http_client + ->methodHasBeenCalled('setAuth')); + } }