Enabled move and queue processing
This commit is contained in:
@@ -9,13 +9,9 @@ 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.
|
||||
*
|
||||
@@ -77,7 +73,7 @@ class Import extends Command
|
||||
}
|
||||
|
||||
// Determine if our dir is releative to where we store data
|
||||
$dir = preg_replace('/^\//','',str_replace(config('photo.dir'),'',$dir));
|
||||
$dir = Photo::path($dir);
|
||||
|
||||
// Add our path
|
||||
if ($dir)
|
||||
@@ -150,8 +146,8 @@ class Import extends Command
|
||||
$po->width = $po->io()->getImageWidth();
|
||||
$po->orientation = $po->io()->getImageOrientation();
|
||||
|
||||
$po->gps_lat = $po->latlon(preg_split('/,\s?/',$po->io()->getImageProperty('exif:GPSLatitude')),$po->io()->getImageProperty('exif:GPSLatitudeRef'));
|
||||
$po->gps_lon = $po->latlon(preg_split('/,\s?/',$po->io()->getImageProperty('exif:GPSLongitude')),$po->io()->getImageProperty('exif:GPSLongitudeRef'));
|
||||
$po->gps_lat = Photo::latlon(preg_split('/,\s?/',$po->io()->getImageProperty('exif:GPSLatitude')),$po->io()->getImageProperty('exif:GPSLatitudeRef'));
|
||||
$po->gps_lon = Photo::latlon(preg_split('/,\s?/',$po->io()->getImageProperty('exif:GPSLongitude')),$po->io()->getImageProperty('exif:GPSLongitudeRef'));
|
||||
|
||||
try {
|
||||
$po->thumbnail = exif_thumbnail($po->file_path());
|
||||
@@ -218,8 +214,6 @@ class Import extends Command
|
||||
$x->photo_id = $po->id;
|
||||
$x->save();
|
||||
}
|
||||
|
||||
$this->dispatch((new PhotoMove($po))->onQueue('move'));
|
||||
}
|
||||
|
||||
$bar->finish();
|
||||
|
99
app/Console/Commands/Move.php
Normal file
99
app/Console/Commands/Move.php
Normal file
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use DB;
|
||||
use Log;
|
||||
use Illuminate\Console\Command;
|
||||
use App\Model\Photo;
|
||||
|
||||
class Move extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'photo:move
|
||||
{--file= : Photo File}
|
||||
{--id= : Photo ID}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Moves Photos to their new location';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
if ($this->option('file'))
|
||||
{
|
||||
$po = Photo::notRemove()->notDuplicate()->where('filename',Photo::path($this->option('file')));
|
||||
}
|
||||
elseif ($this->option('id'))
|
||||
{
|
||||
$po = Photo::notRemove()->notDuplicate()->where('id',Photo::path($this->option('id')));
|
||||
}
|
||||
else
|
||||
{
|
||||
$po = Photo::notRemove()->notDuplicate();
|
||||
}
|
||||
|
||||
// Show a progress bar
|
||||
$bar = $this->output->createProgressBar($po->count());
|
||||
$bar->setFormat("%current%/%max% [%bar%] %percent:3s%% (%memory%) (%remaining%) ");
|
||||
$bar->setRedrawFrequency(100);
|
||||
|
||||
$po->chunk(1,function($photo) use ($bar) {
|
||||
while ($po = $photo->shift())
|
||||
{
|
||||
if (($x = $po->moveable()) === TRUE) {
|
||||
Log::info(sprintf('Moving: (%s)[%s]',$po->id,$po->filename));
|
||||
|
||||
if (rename($po->file_path(),$po->file_path(FALSE,TRUE)))
|
||||
{
|
||||
// Convert the path to a relative one.
|
||||
$po->filename = $po->file_path(TRUE,TRUE);
|
||||
|
||||
// @todo If the DB update failed, move it back.
|
||||
if (! $po->save()) # AND ! rename($path,$po->file_path()))
|
||||
{
|
||||
$this->error(sprintf('Save after rename failed for (%s)',$po->id));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error(sprintf('Rename failed for (%s)',$po->id));
|
||||
continue;
|
||||
}
|
||||
|
||||
chmod($po->file_path(),0444);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($x > 0)
|
||||
$this->warn(sprintf('Unable to move (%s) [%s] to [%s], moveable returned (%s)',$po->id,$po->file_path(),$po->file_path(FALSE,TRUE),$x));
|
||||
}
|
||||
}
|
||||
|
||||
$bar->advance();
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user