-
packages/Webkul/Product/src/Console/Commands/Indexer.php
Open in GitHubuse Illuminate\Console\Command; use Webkul\Product\Helpers\Indexers\ElasticSearch; class Indexer extends Command { protected $indexers = [ 'elastic' => ElasticSearch::class, ]; protected $signature = 'indexer:index {--type=*} {--mode=*}'; protected $description = 'Automatically updates product price and inventory indices'; public function handle() { $start = microtime(true); $indexerIds = ['elastic']; if (! empty($this->option('type'))) { $indexerIds = $this->option('type'); } $mode = 'selective'; if (! empty($this->option('mode'))) { $mode = current($this->option('mode')); } foreach ($indexerIds as $indexerId) { if ( $indexerId == 'elastic' && core()->getConfigData('catalog.products.storefront.search_mode') != 'elastic' ) { continue; } $indexer = app($this->indexers[$indexerId]); if ($mode == 'full') { $indexer->reindexFull(); } else { if ($indexerId != 'inventory') { $indexer->reindexSelective(); } } } $end = microtime(true); echo 'The code took '.($end - $start)." seconds to complete.\n"; } }