diff --git a/app/Console/Commands/Import.php b/app/Console/Commands/Import.php index 44fc3e9..ec17ae4 100644 --- a/app/Console/Commands/Import.php +++ b/app/Console/Commands/Import.php @@ -53,7 +53,7 @@ class Import extends Command if (is_null($this->option('file')) AND is_null($this->option('dir'))) abort(500,'Missing filename, please use --file= OR --dir='); - Log::info('Processing: '.($this->option('file') ? $this->option('file') : $this->option('dir'))); + Log::info(sprintf('%s: Processing: %s',__METHOD__,($this->option('file') ? $this->option('file') : $this->option('dir')))); $files = []; diff --git a/app/Console/Commands/Move.php b/app/Console/Commands/Move.php index 0ce769a..c3ec50b 100644 --- a/app/Console/Commands/Move.php +++ b/app/Console/Commands/Move.php @@ -64,7 +64,7 @@ class Move extends Command while ($po = $photo->shift()) { if (($x = $po->moveable()) === TRUE) { - Log::info(sprintf('Moving: (%s)[%s]',$po->id,$po->filename)); + Log::info(sprintf('%s: Moving (%s)[%s]',__METHOD__,$po->id,$po->filename)); if (rename($po->file_path(),$po->file_path(FALSE,TRUE))) { diff --git a/app/Console/Commands/Update.php b/app/Console/Commands/Update.php new file mode 100644 index 0000000..520c883 --- /dev/null +++ b/app/Console/Commands/Update.php @@ -0,0 +1,135 @@ +option('file')) AND is_null($this->option('dir'))) + abort(500,'Missing filename, please use --file= OR --dir='); + + Log::info(sprintf('%s: Processing: %s',__METHOD__,($this->option('file') ? $this->option('file') : $this->option('dir')))); + + $files = []; + + if ($this->option('dir')) + { + // Remove our trailing slash from the directory. + $dir = preg_replace('/\/$/','',$this->option('dir')); + + // Exclude . & .. from the path. + $files = array_diff(scandir($dir),array('.','..')); + + } + elseif ($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 = Photo::path($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%) "); + + $c = 0; + foreach ($files as $file) + { + $bar->advance(); + + if (preg_match('/@__thumb/',$file) OR preg_match('/\/._/',$file)) + { + $this->warn(sprintf('Ignoring file [%s]',$file)); + continue; + } + + if (! in_array(strtolower(pathinfo($file,PATHINFO_EXTENSION)),config('photo.import.accepted'))) + { + $this->warn(sprintf('Ignoring [%s]',$file)); + continue; + } + + if ($this->option('verbose')) + $this->info(sprintf('Processing file [%s]',$file)); + + $c++; + + $po = Photo::where('filename',$file)->first(); + + if (is_null($po)) + { + $this->error(sprintf('File is not in the database [%s]?',$file)); + Log::error(sprintf('%s: File is not in the database [%s]?',__METHOD__,$file)); + continue; + } + + $po->signature = $po->property('signature'); + + try { + $po->thumbnail = exif_thumbnail($po->file_path()); + } catch (\Exception $e) { + // @todo Couldnt get the thumbnail, so we should create one. + } + + if ($po->isDirty()) + { + if (count($po->getDirty()) > 1 OR ! array_key_exists('signature',$po->getDirty())) + $this->error(sprintf('More than the signature changed for [%s] (%s)?',$po->id,join('|',array_keys($po->getDirty())))); + + $this->info(sprintf('Signature update for [%s]',$po->id)); + $po->save(); + } + } + + $bar->finish(); + + return $this->info(sprintf('Images processed: %s',$c)); + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index cdb6402..8f79ace 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -15,6 +15,7 @@ class Kernel extends ConsoleKernel protected $commands = [ Commands\Import::class, Commands\Move::class, + Commands\Update::class, ]; /** diff --git a/app/Http/Controllers/PhotoController.php b/app/Http/Controllers/PhotoController.php index 241157e..9e18607 100644 --- a/app/Http/Controllers/PhotoController.php +++ b/app/Http/Controllers/PhotoController.php @@ -49,7 +49,7 @@ class PhotoController extends Controller $this->dispatch((new PhotoDelete($photo))->onQueue('delete')); } - return $request->input('pagenext') ? redirect()->action('PhotoController@deletes','?page='.$request->input('pagenext')) : redirect('/'); + return redirect()->action('PhotoController@deletes',$request->input('pagenext') ? '?page='.$request->input('pagenext') : NULL); } public function duplicates($id=NULL) diff --git a/app/Jobs/PhotoDelete.php b/app/Jobs/PhotoDelete.php index db57d9c..cd986bb 100644 --- a/app/Jobs/PhotoDelete.php +++ b/app/Jobs/PhotoDelete.php @@ -34,7 +34,7 @@ class PhotoDelete extends Job implements ShouldQueue { if (! $this->photo->remove) { - Log::warning(__METHOD__.' NOT Deleting: '.$this->photo->file_path().', not marked for deletion'); + Log::warning(sprintf('%s: NOT Deleting [%s] not marked for deletion',__METHOD__,$this->photo->file_path())); exit; } @@ -46,13 +46,13 @@ class PhotoDelete extends Job implements ShouldQueue // Make sure our parent is writable if (! is_writable(dirname($this->photo->file_path()))) - Log::warning(__METHOD__.' NOT Deleting: '.$this->photo->file_path().', parent directory not writable'); + Log::warning(sprintf('%s: NOT Deleting [%s] parent directory not writable',__METHOD__,$this->photo->file_path())); // Perform delete if (file_exists($this->photo->file_path())) unlink($this->photo->file_path()); - Log::info(sprintf('%s: Deleted (%s): %s',__METHOD__,$this->photo->id,$this->photo->file_path())); + Log::warning(sprintf('%s: Deleted [%s]',__METHOD__,$this->photo->file_path())); $this->photo->delete(); } } diff --git a/app/Jobs/PhotoMove.php b/app/Jobs/PhotoMove.php index a565365..380fde3 100644 --- a/app/Jobs/PhotoMove.php +++ b/app/Jobs/PhotoMove.php @@ -33,7 +33,7 @@ class PhotoMove extends Job implements ShouldQueue */ public function handle() { - Log::info(__METHOD__.' Moving: '.$this->photo->id); - Artisan::call('photo:move',['--id' => $this->photo->id]); + Log::info(sprintf('%s: Moving [%s]',__METHOD__,$this->photo->id)); + Artisan::call('photo:move',['--id' => $this->photo->id]); } } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 12f10d5..64bc64e 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -23,7 +23,7 @@ class AppServiceProvider extends ServiceProvider Photo::saved(function($photo) { if (! $photo->duplicate AND ($x=$photo->moveable()) === TRUE) { - Log::info(__METHOD__.': Need to Move: '.$photo->id.'|'.serialize($x)); + Log::info(sprintf('%s: Need to Move [%s]',__METHOD__,$photo->id.'|'.serialize($x))); $this->dispatch((new PhotoMove($photo))->onQueue('move')); } }); diff --git a/composer.json b/composer.json index f551198..c9dfa4e 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,8 @@ "type": "project", "require": { "php": ">=5.5.9", - "laravel/framework": "5.2.*" + "laravel/framework": "5.2.*", + "james-heinrich/getid3": "^1.9" }, "require-dev": { "fzaninotto/faker": "~1.4", diff --git a/composer.lock b/composer.lock index 0ac80b8..02ff547 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "06f9a4d19eda3cf3c92386077c05117c", - "content-hash": "e32614d49ea2fa40cc882537b7125da4", + "hash": "affac35a14902f5a8a53ba6d87bd177a", + "content-hash": "5a0d9e754c1ab62331089e114bc104b3", "packages": [ { "name": "classpreloader/classpreloader", @@ -248,6 +248,42 @@ ], "time": "2015-04-20 18:58:01" }, + { + "name": "james-heinrich/getid3", + "version": "v1.9.12", + "source": { + "type": "git", + "url": "https://github.com/JamesHeinrich/getID3.git", + "reference": "41c05612d532d30f07680cad3a4a6efbec7fc7f5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/JamesHeinrich/getID3/zipball/41c05612d532d30f07680cad3a4a6efbec7fc7f5", + "reference": "41c05612d532d30f07680cad3a4a6efbec7fc7f5", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "getid3/getid3.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL" + ], + "description": "PHP script that extracts useful information from popular multimedia file formats", + "homepage": "http://www.getid3.org/", + "keywords": [ + "codecs", + "php", + "tags" + ], + "time": "2016-03-02 13:13:30" + }, { "name": "jeremeamia/SuperClosure", "version": "2.2.0",