File: D:/HostingSpaces/Lacom/lacom.nl/app/KommaApp/Shop/ArtisanCommands/IndexCatalog.php
<?php
namespace App\KommaApp\Shop\ArtisanCommands;
use App\KommaApp\Shop\Catalog\CatalogService;
use App\KommaApp\Shop\Catalog\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;
}
}
}