Enabled photos to be moved via a queue

This commit is contained in:
Deon George
2016-06-23 07:07:44 +10:00
parent e297c5ca7e
commit 4c317a811c
4 changed files with 126 additions and 11 deletions

View File

@@ -9,9 +9,13 @@ use App\Model\PhotoPerson;
use App\Model\Photo;
use App\Model\PhotoTag;
use App\Model\Tag;
use Illuminate\Foundation\Bus\DispatchesJobs;
use App\Jobs\PhotoMove;
class Import extends Command
{
use DispatchesJobs;
/**
* The name and signature of the console command.
*
@@ -65,22 +69,24 @@ class Import extends Command
// Exclude . & .. from the path.
$files = array_diff(scandir($dir),array('.','..'));
// Determine if our dir is releative to where we store data
$dir = preg_replace('/^\//','',str_replace(config('photo.dir'),'',$dir));
// Add our path
if ($dir)
array_walk($files,function(&$value,$key,$path='') {
if ($path) {
$value = sprintf('%s/%s',$path,$value);
}
},$dir);
}
elseif ($this->option('file'))
{
$files = array($this->option('file'));
$dir = dirname($this->option('file'));
$files = array(basename($this->option('file')));
}
// Determine if our dir is releative to where we store data
$dir = preg_replace('/^\//','',str_replace(config('photo.dir'),'',$dir));
// Add our path
if ($dir)
array_walk($files,function(&$value,$key,$path='') {
if ($path) {
$value = sprintf('%s/%s',$path,$value);
}
},$dir);
// Show a progress bar
$bar = $this->output->createProgressBar(count($files));
$bar->setFormat("%current%/%max% [%bar%] %percent:3s%% (%memory%) (%remaining%) ");
@@ -212,6 +218,8 @@ class Import extends Command
$x->photo_id = $po->id;
$x->save();
}
$this->dispatch((new PhotoMove($po))->onQueue('move'));
}
$bar->finish();