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/fire-tech/fire-tech.nl/app/KommaApp/Shop/ArtisanCommands/IndexCatalog.php
<?php

namespace App\KommaApp\Shop\ArtisanCommands;

use App\KommaApp\Shop\Catalog\Kms\CatalogServiceInterface;
use Illuminate\Console\Command;

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

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Indexes the shop catalog. You can specify an action argument that can be index, clear or clean depending on what you want to do';

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

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $catalogService = \App::make(CatalogServiceInterface::class);

        $action = $this->argument('action');
        if(!$action) $action = null;

        switch ($action)
        {
            case null:
            case "index":
                echo 'indexing...'.PHP_EOL;
                $catalogService->createIndex();
                echo 'indexing done!'.PHP_EOL;
                break;
            case "clear":
                echo 'clearing index...'.PHP_EOL;
                $catalogService->clearIndex();
                echo 'cleared index!'.PHP_EOL;
                break;
            case "clean":
                echo 'cleaning...'.PHP_EOL;
                $catalogService->doHouseKeeping();
                echo 'cleaning done!'.PHP_EOL;
                break;
        }
    }
}