Added photo:update to update signatures
This commit is contained in:
parent
f089c33b8b
commit
90c4468c43
@ -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 = [];
|
||||
|
||||
|
@ -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)))
|
||||
{
|
||||
|
135
app/Console/Commands/Update.php
Normal file
135
app/Console/Commands/Update.php
Normal file
@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Log;
|
||||
use Illuminate\Console\Command;
|
||||
use App\Model\Photo;
|
||||
|
||||
class Update extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'photo:update
|
||||
{--dir= : Directory to Parse}
|
||||
{--file= : File to import}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Update Signatures';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
// Make sure we got a directory or a file to import
|
||||
if (is_null($this->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));
|
||||
}
|
||||
}
|
@ -15,6 +15,7 @@ class Kernel extends ConsoleKernel
|
||||
protected $commands = [
|
||||
Commands\Import::class,
|
||||
Commands\Move::class,
|
||||
Commands\Update::class,
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -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)
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
@ -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'));
|
||||
}
|
||||
});
|
||||
|
@ -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",
|
||||
|
40
composer.lock
generated
40
composer.lock
generated
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user