From 53537ff61e4a9517e0a5b5d5cc42339d75c9e7fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Wed, 23 Mar 2022 16:04:24 +0100 Subject: [PATCH] Ticket 739 : Pagination sur ReindexElasticMedia command --- app/Console/Commands/ReindexElasticMedia.php | 67 ++++++++++++++++ app/Console/Commands/reindexElasticMedia.php | 81 -------------------- 2 files changed, 67 insertions(+), 81 deletions(-) create mode 100644 app/Console/Commands/ReindexElasticMedia.php delete mode 100644 app/Console/Commands/reindexElasticMedia.php diff --git a/app/Console/Commands/ReindexElasticMedia.php b/app/Console/Commands/ReindexElasticMedia.php new file mode 100644 index 0000000..0a1f53b --- /dev/null +++ b/app/Console/Commands/ReindexElasticMedia.php @@ -0,0 +1,67 @@ +info('Reindexation de la base médias dans Elasticsearch...'); + $this->info('Test Présence...'); + if (Media::indexExists()) { + $this->info('Suppression index...'); + Media::deleteIndex(); + } + $this->info('Création...'); + Media::createIndex(); + + $pageNumber = 0; + $perPage = 200; + + /** @var \Illuminate\Pagination\LengthAwarePaginator $medias */ + $medias = Media::paginate($perPage); + $bar = $this->output->createProgressBar(count($medias)); + + $bar->start($medias->total()); + + // * LOOP + do { + if ($pageNumber > 0) { + /** @var \Illuminate\Pagination\LengthAwarePaginator $medias */ + $medias = Media::paginate($perPage, ['*'], 'page', $pageNumber); + } + foreach ($medias as $media) { + $media->addToIndex(); + $bar->advance(); + } + ++$pageNumber; + } while ($medias->hasMorePages()); + + + $bar->finish(); + $this->line(''); + $this->info('Fin du traitement'); + } +} diff --git a/app/Console/Commands/reindexElasticMedia.php b/app/Console/Commands/reindexElasticMedia.php deleted file mode 100644 index 1744c68..0000000 --- a/app/Console/Commands/reindexElasticMedia.php +++ /dev/null @@ -1,81 +0,0 @@ -info('Reindexation de la base médias dans Elasticsearch...'); - $bReprise = false; - $startFrom = $this->argument('injectfrom'); - if($startFrom != "") { - $bReprise = true; - } else { - $startFrom = 1; - } - $this->info('Test Présence...'); - if (Media::indexExists() && !$bReprise) { - $this->info('Suppression index...'); - Media::deleteIndex(); - } - - if(!$bReprise) { - $this->info('Création...'); - Media::createIndex(); - } - - $medias = Media::all(); - $bar = $this->output->createProgressBar(count($medias)); - $bar->start(); - if($bReprise) - $bar->advance($startFrom); - - $i=1; - foreach ($medias as $media) { - if($i >= $startFrom) { - // ---- index le media dans Elasticsearch - $media->addToIndex(); - $bar->advance(); - } - unset($media); - $i++; - } - $bar->finish(); - $this->line(""); - $this->info('Fin du traitement'); - } -}