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/Eurotools/euro-tools.nl/app/KommaApp/Shop/ArtisanCommands/IndexSearch.php
<?php

namespace App\KommaApp\Shop\ArtisanCommands;

use App\KommaApp\Kms\Core\AbstractTranslatableModel;
use App\KommaApp\Kms\Core\AbstractTranslationModel;
use App\KommaApp\Shop\Catalog\Kms\CatalogService;
use App\KommaApp\Shop\Categories\Models\Category;
use App\KommaApp\Shop\Categories\Models\CategoryTranslation;
use App\KommaApp\Shop\Products\Product\Product;
use App\KommaApp\Shop\Products\Product\ProductTranslation;
use App\KommaApp\Shop\Products\ProductComposite\ProductComposite;
use App\KommaApp\Shop\Products\ProductComposite\ProductCompositeTranslation;
use App\KommaApp\Shop\Products\ProductGroup\ProductGroup;
use App\KommaApp\Shop\Products\ProductGroup\ProductGroupTranslation;
use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\Model;
use ZendSearch\Lucene\SearchIndexInterface;

class IndexSearch extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'shop:searchindex {action? : index, flush. Defaults to index}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Imports the products, groups and composites into the search index so they can be searched trough';

    /**
     * IndexCatalog constructor.
     */
    public function __construct( )
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $action = $this->argument('action');
        if(!$action) $action = null;

        switch ($action)
        {
            case null:
            case "index":
                $this->index();
                break;
            case "flush":
                $this->flush();
                break;
        }

        CatalogService::manageSearchabilityForGivenOrAllTranslatablesWhere(null,'active', 0);
        return null;
    }

    /**
     * Flush imported searchable models from the search databases
     */
    private function flush()
    {
        $this->info('Flushing models for the search index. Please wait...');
        foreach (CatalogService::$searchableModelClasses as $searchModelClassName) $this->call('scout:flush', ['model' => $searchModelClassName]);
        $this->info('Flushing complete');
    }

    /**
     * Import searchable models in the search databases
     */
    private function index()
    {
        $this->info('Importing models for the search index. Please wait...');
        foreach (CatalogService::$searchableModelClasses as $searchModelClassName) $this->call('scout:import', ['model' => $searchModelClassName]);
        $this->info('Importing complete');
    }
}