2018-01-11 12:59:53 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
use Illuminate\Foundation\Bus\DispatchesJobs;
|
2019-11-09 03:58:15 +00:00
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
2018-01-11 12:59:53 +00:00
|
|
|
use App\Jobs\CatalogScan;
|
2020-01-02 21:21:55 +00:00
|
|
|
use App\Traits\Type;
|
2018-01-11 12:59:53 +00:00
|
|
|
|
2020-01-02 21:04:15 +00:00
|
|
|
class CatalogScanAll extends Command
|
2018-01-11 12:59:53 +00:00
|
|
|
{
|
2020-01-02 21:21:55 +00:00
|
|
|
use DispatchesJobs,Type;
|
2018-01-11 12:59:53 +00:00
|
|
|
|
2019-11-09 03:58:15 +00:00
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2020-01-02 21:04:15 +00:00
|
|
|
protected $signature = 'catalog:scanall'.
|
|
|
|
' {type : Photo | Video }'.
|
|
|
|
' {--scanned : Rescan Scanned Photos}';
|
2019-11-09 03:58:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2020-01-02 21:04:15 +00:00
|
|
|
protected $description = '(re)Scan Media';
|
2019-11-09 03:58:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new command instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
2020-01-02 21:04:15 +00:00
|
|
|
$class = $this->getModelType($this->argument('type'));
|
2019-11-09 03:58:15 +00:00
|
|
|
|
2020-01-02 21:04:15 +00:00
|
|
|
if ($this->option('scanned')) {
|
2020-01-02 21:21:55 +00:00
|
|
|
$class::whereNotNull('scanned')
|
|
|
|
->update(['scanned'=>NULL]);
|
2020-01-02 21:04:15 +00:00
|
|
|
}
|
|
|
|
|
2020-01-02 21:21:55 +00:00
|
|
|
$c = 0;
|
|
|
|
$class::NotScanned()->each(function ($item) use ($c) {
|
2019-11-09 03:58:15 +00:00
|
|
|
if ($item->remove) {
|
|
|
|
Log::warning(sprintf('Not scanning [%s], marked for removal',$item->id));
|
|
|
|
return;
|
2018-01-11 12:59:53 +00:00
|
|
|
}
|
|
|
|
|
2019-11-09 03:58:15 +00:00
|
|
|
$this->dispatch((new CatalogScan($item))->onQueue('scan'));
|
2020-01-04 13:28:00 +00:00
|
|
|
$c++;
|
2019-11-09 03:58:15 +00:00
|
|
|
});
|
|
|
|
|
2020-01-02 21:21:55 +00:00
|
|
|
Log::info(sprintf('Processed [%s]',$c));
|
2019-11-09 03:58:15 +00:00
|
|
|
}
|
|
|
|
}
|