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) {