Optimised scanning and importing
This commit is contained in:
58
app/Console/Commands/PhotoScanAll.php
Normal file
58
app/Console/Commands/PhotoScanAll.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Log;
|
||||
use App\Model\Photo;
|
||||
use App\Jobs\CatalogScan;
|
||||
|
||||
class PhotoScanAll extends Command
|
||||
{
|
||||
use DispatchesJobs;
|
||||
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'photo:scanall';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Command description';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
Photo::NotScanned()->chunk(200,function ($data) {
|
||||
foreach ($data as $o)
|
||||
{
|
||||
if ($o->remove) {
|
||||
Log::warning(sprintf('Not scanning [%s], marked for removal',$o->id));
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->dispatch((new CatalogScan($o))->onQueue('scan'));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user