diff --git a/app/Console/Commands/Import.php b/app/Console/Commands/Import.php index bac1a8b..7f79da7 100644 --- a/app/Console/Commands/Import.php +++ b/app/Console/Commands/Import.php @@ -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(); diff --git a/app/Jobs/PhotoMove.php b/app/Jobs/PhotoMove.php new file mode 100644 index 0000000..cc1fb37 --- /dev/null +++ b/app/Jobs/PhotoMove.php @@ -0,0 +1,37 @@ +photo = $photo; + } + + /** + * Execute the job. + * + * @return void + */ + public function handle() + { + Log::info('Moving: '.$this->photo->id); + } +} diff --git a/database/migrations/2016_06_22_221832_create_jobs_table.php b/database/migrations/2016_06_22_221832_create_jobs_table.php new file mode 100644 index 0000000..81b2d29 --- /dev/null +++ b/database/migrations/2016_06_22_221832_create_jobs_table.php @@ -0,0 +1,37 @@ +bigIncrements('id'); + $table->string('queue'); + $table->longText('payload'); + $table->tinyInteger('attempts')->unsigned(); + $table->tinyInteger('reserved')->unsigned(); + $table->unsignedInteger('reserved_at')->nullable(); + $table->unsignedInteger('available_at'); + $table->unsignedInteger('created_at'); + $table->index(['queue', 'reserved', 'reserved_at']); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('jobs'); + } +} diff --git a/database/migrations/2016_06_22_230327_create_failed_jobs_table.php b/database/migrations/2016_06_22_230327_create_failed_jobs_table.php new file mode 100644 index 0000000..3d733b6 --- /dev/null +++ b/database/migrations/2016_06_22_230327_create_failed_jobs_table.php @@ -0,0 +1,33 @@ +increments('id'); + $table->text('connection'); + $table->text('queue'); + $table->longText('payload'); + $table->timestamp('failed_at')->useCurrent(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('failed_jobs'); + } +}