HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/topswtw.komma.pro/app/commands/manualSearchIndexCommand.php
<?php

use Illuminate\Console\Command;
use Illuminate\Database\DatabaseManager;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Komma\Kms\Core\SearchIndex\SearchIndexService;

class manualSearchIndexCommand extends Command {

	/**
	 * The console command name.
	 *
	 * @var string
	 */
	protected $name = 'search:index';

	/**
	 * The console command description.
	 *
	 * @var string
	 */
	protected $description = 'Command description.';

    private $searchIndexService;

    /**
     * @var DatabaseManager
     */
    protected $db;

    /**
     * @var SearchIndexRepository
     */
    protected $searchIndexRepository;

    /**
     * @var ProductRepository
     */
    protected $productRepository;


	/**
	 * Execute the console command.
	 *
	 * @return mixed
	 */
	public function fire()
	{
        Log::info('Search index command os started on:'.date("Y-m-d H:i:s"));
        //Load the dependencies
        $this->loadDependencies();
        Log::info('All dependencies loaded');
        Log::info('We are going to index all');
        //start to index
        $this->feedSearchIndex();
        Log::info('Search index is completed on:'.date("Y-m-d H:i:s"));
	}

	/**
	 * Get the console command arguments.
	 *
	 * @return array
	 */
	protected function getArguments()
	{
		return array(
			array('type', InputArgument::REQUIRED, 'eg,proucts, categories, pages, all'),
		);
	}

	/**
	 * Get the console command options.
	 *
	 * @return array
	 */
	protected function getOptions()
	{
		return array(
//			array('example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null),
		);
	}

    /**
     * Load the classes, serives,... who are needed.
     * to feed the searchindex
     *
     */
    public function loadDependencies(){
        //Load the searchIndexService with full stack (therefore use App:make, thanks Mike).
        $this->searchIndexService= App::make('Komma\Kms\Core\SearchIndex\SearchIndexService');
    }

    /**
     * This funciton will create the search index
     *
     */
    public function feedSearchIndex(){

        $this->searchIndexService->reindex();

        //Switch based on the type
//        switch($this->argument('type')){
//            case 'categories' :
//                $this->searchIndexService->reindex('categories');
//                break;
//            case 'pages' :
//                $this->searchIndexService->reindex('pages');
//                break;
//            case 'products' :
//                $this->searchIndexService->reindex('products');
//                break;
//            case 'all' :
//                $this->searchIndexService->reindex();
//                break;
//            default :
//                Log::error($this->argument('type').', is not a valid type');
//        }
    }

}