Start of console commands enhancements
This commit is contained in:
67
app/Console/Commands/CatalogScanAll.php
Normal file
67
app/Console/Commands/CatalogScanAll.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
use App\Models\Photo;
|
||||
use App\Jobs\CatalogScan;
|
||||
|
||||
class CatalogScanAll extends Command
|
||||
{
|
||||
use DispatchesJobs;
|
||||
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'catalog:scanall'.
|
||||
' {type : Photo | Video }'.
|
||||
' {--scanned : Rescan Scanned Photos}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '(re)Scan Media';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$class = $this->getModelType($this->argument('type'));
|
||||
|
||||
if ($this->option('scanned')) {
|
||||
$class::update(['scanned'=>NULL]);
|
||||
}
|
||||
|
||||
$class::NotScanned()->each(function ($item) {
|
||||
if ($item->remove) {
|
||||
Log::warning(sprintf('Not scanning [%s], marked for removal',$item->id));
|
||||
return;
|
||||
}
|
||||
|
||||
Log::info(sprintf('%s: Rescanning [%s]',$item->type,$item->id));
|
||||
$this->dispatch((new CatalogScan($item))->onQueue('scan'));
|
||||
});
|
||||
|
||||
Log::info(sprintf('Processed [%s]',$o->count()));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user