From 83d6d1e05549afb0a9194b068ac40897ac703a78 Mon Sep 17 00:00:00 2001 From: Deon George Date: Sat, 9 Nov 2019 13:52:04 +1100 Subject: [PATCH] Update photo import to laravel 6.4 --- app/Console/Commands/CatalogScan.php | 74 ++++++------ app/Console/Commands/PhotoImport.php | 54 +++++---- app/Console/Commands/PhotoMove.php | 108 +++++++++--------- app/Http/Controllers/PhotoController.php | 85 +++++++------- app/Jobs/CatalogScan.php | 15 +-- app/Jobs/PhotoDelete.php | 8 +- app/Jobs/PhotoMove.php | 10 +- app/Jobs/VideoDelete.php | 8 +- app/Jobs/VideoMove.php | 10 +- app/Models/Abstracted/Catalog.php | 16 +-- app/Providers/AppServiceProvider.php | 35 +++--- app/Traits/Files.php | 49 +++++--- .../2014_10_12_000000_create_users_table.php | 8 +- ...12_100000_create_password_resets_table.php | 9 +- .../views/catalog/duplicatereview.blade.php | 4 +- resources/views/photo/view.blade.php | 8 +- resources/views/vendor/.gitkeep | 1 - routes/web.php | 25 +++- 18 files changed, 274 insertions(+), 253 deletions(-) delete mode 100644 resources/views/vendor/.gitkeep diff --git a/app/Console/Commands/CatalogScan.php b/app/Console/Commands/CatalogScan.php index ada08f5..a4f8a20 100644 --- a/app/Console/Commands/CatalogScan.php +++ b/app/Console/Commands/CatalogScan.php @@ -3,7 +3,6 @@ namespace App\Console\Commands; use Illuminate\Console\Command; -use Illuminate\Database\Eloquent\ModelNotFoundException; class CatalogScan extends Command { @@ -31,56 +30,51 @@ class CatalogScan extends Command */ public function handle() { - $class = 'App\Model\\'.$this->argument('type'); - - if (! class_exists($class)) - abort(500,sprintf('No class [%s]',$this->argument('type'))); + $class = 'App\Models\\'.$this->argument('type'); - $o = $class::findOrFail($this->argument('id')); + if (! class_exists($class)) + abort(500,sprintf('No class [%s]',$this->argument('type'))); - if (! is_readable($o->file_path())) - { - $this->warn(sprintf('Ignoring [%s], it is not readable',$o->file_path())); - exit; - } + $o = $class::findOrFail($this->argument('id')); - $o->setDateCreated(); - $o->setSubSecTime(); - $o->setSignature(); - $o->setMakeModel(); - $o->setLocation(); - $o->setHeightWidth(); - $o->setThumbnail(); + if (! is_readable($o->file_path())) { + $this->warn(sprintf('Ignoring [%s], it is not readable',$o->file_path())); + exit; + } - // If this is a duplicate - $x = $class::whereIN('id',$o->list_duplicate())->get(); - if (count($x)) { - $break = FALSE; + $o->setDateCreated(); + $o->setSubSecTime(); + $o->setSignature(); + $o->setMakeModel(); + $o->setLocation(); + $o->setHeightWidth(); + $o->setThumbnail(); - foreach ($x as $oo) { - // And that photo is not marked as a duplicate - if (! $oo->duplicate) - { - $o->duplicate = '1'; - $this->warn(sprintf('Image [%s] marked as a duplicate',$o->file_path())); + // If this is a duplicate + $x = $class::whereIN('id',$o->list_duplicate())->get(); + if (count($x)) { + foreach ($x as $oo) { + // And that photo is not marked as a duplicate + if (! $oo->duplicate) { + $o->duplicate = '1'; + $this->warn(sprintf('Image [%s] marked as a duplicate',$o->file_path())); - // If the file signature also matches, we'll mark it for deletion - if ($oo->file_signature AND $o->file_signature == $oo->file_signature) - { - $this->warn(sprintf('Image [%s] marked for deletion',$o->file_path())); - $o->remove = '1'; + // If the file signature also matches, we'll mark it for deletion + if ($oo->file_signature AND $o->file_signature == $oo->file_signature) { + $this->warn(sprintf('Image [%s] marked for deletion',$o->file_path())); + $o->remove = '1'; + } + + break; } - - break; } } - } - $o->scanned = '1'; + $o->scanned = '1'; - if ($o->getDirty()) - $this->warn(sprintf('Image [%s] metadata changed',$o->file_path())); + if ($o->getDirty()) + $this->warn(sprintf('Image [%s] metadata changed',$o->file_path())); - $o->save(); + $o->save(); } } diff --git a/app/Console/Commands/PhotoImport.php b/app/Console/Commands/PhotoImport.php index 5cacdff..3b1cf8b 100644 --- a/app/Console/Commands/PhotoImport.php +++ b/app/Console/Commands/PhotoImport.php @@ -2,19 +2,17 @@ namespace App\Console\Commands; -use Log; +use Illuminate\Support\Facades\Log; use Illuminate\Console\Command; use Illuminate\Foundation\Bus\DispatchesJobs; -use App\Model\Person; -use App\Model\PhotoPerson; -use App\Model\Photo; -use App\Model\PhotoTag; -use App\Model\Tag; + +use App\Models\{Person,Photo,Tag}; +use App\Traits\Files; class PhotoImport extends Command { use DispatchesJobs; - use \App\Traits\Files; + use Files; /** * The name and signature of the console command. @@ -53,7 +51,11 @@ class PhotoImport extends Command */ public function handle() { - $files = $this->getFiles(['dir'=>$this->option('dir'),'file'=>$this->option('file')],'photo'); + $files = $this->getFiles([ + 'dir'=>$this->option('dir'), + 'file'=>$this->option('file') + ],'photo'); + if (! count($files)) exit; @@ -65,22 +67,21 @@ class PhotoImport extends Command $t = $p = array(); // Tags - if ($this->option('tags')) - { + if ($this->option('tags')) { $tags = explode(',',$this->option('tags')); $t = Tag::whereIn('tag',$tags)->pluck('id')->toArray(); - if (! $t OR count($t) != count($tags)) - { + + if (! $t OR count($t) != count($tags)) { $this->error(sprintf('Tag [%s] dont exist',join('|',$tags))); abort(501); } } // People - if ($this->option('people')) - { + if ($this->option('people')) { $tags = explode(',',$this->option('people')); $p = Person::whereIn('tag',$tags)->pluck('id')->toArray(); + if (! $p OR count($p) != count($tags)) { $this->error(sprintf('People [%s] dont exist',join('|',$tags))); @@ -89,18 +90,15 @@ class PhotoImport extends Command } $c = 0; - foreach ($files as $file) - { + foreach ($files as $file) { $bar->advance(); - if (preg_match('/@__thumb/',$file) OR preg_match('/\/._/',$file)) - { + 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'))) - { + if (! in_array(strtolower(pathinfo($file,PATHINFO_EXTENSION)),config('photo.import.accepted'))) { $this->warn(sprintf('Ignoring [%s]',$file)); continue; } @@ -112,21 +110,21 @@ class PhotoImport extends Command $o = Photo::where('filename',$file)->first(); - if (is_null($o)) - { + // The photo doesnt exist + if (is_null($o)) { $o = new Photo; $o->filename = $file; } - if (! is_readable($o->file_path())) - { + if ($o->exists) + $this->warn(sprintf('%s [%s] already in DB: %s',$o->objectType(),$file,$o->id)); + + // Make sure we can read the photo. + if (! is_readable($o->file_path())) { $this->warn(sprintf('Ignoring [%s], it is not readable',$o->file_path())); continue; } - if ($o->exists) - $this->warn(sprintf('%s [%s] already in DB: %s',$o->objectType(),$file,$o->id)); - $o->save(); if ($o->wasRecentlyCreated) @@ -145,4 +143,4 @@ class PhotoImport extends Command return $this->info(sprintf('Photos processed: %s',$c)); } -} +} \ No newline at end of file diff --git a/app/Console/Commands/PhotoMove.php b/app/Console/Commands/PhotoMove.php index 7d31dac..62320ac 100644 --- a/app/Console/Commands/PhotoMove.php +++ b/app/Console/Commands/PhotoMove.php @@ -2,14 +2,15 @@ namespace App\Console\Commands; -use DB; -use Log; +use Illuminate\Support\Facades\Log; use Illuminate\Console\Command; -use App\Model\Photo; + +use App\Traits\Files; +use App\Models\Photo; class PhotoMove extends Command { - use \App\Traits\Files; + use Files; /** * The name and signature of the console command. @@ -44,61 +45,54 @@ class PhotoMove extends Command */ 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',$this->option('id')); - } - else - { - $po = Photo::notRemove()->notDuplicate(); - } + if ($this->option('file')) { + $po = Photo::notRemove()->notDuplicate()->where('filename',Photo::path($this->option('file'))); - if (! $po) - exit; + } elseif ($this->option('id')) { + $po = Photo::notRemove()->notDuplicate()->where('id',$this->option('id')); - // 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 ($o = $photo->shift()) - { - if (($x = $o->moveable()) === TRUE) { - Log::info(sprintf('%s: Moving (%s)[%s]',__METHOD__,$o->id,$o->filename)); - - if ($this->makeParentDir(dirname($o->file_path(FALSE,TRUE))) AND rename($o->file_path(),$o->file_path(FALSE,TRUE))) - { - // Convert the path to a relative one. - $o->filename = $o->file_path(TRUE,TRUE); - - // @todo If the DB update failed, move it back. - if (! $o->save()) # AND ! rename($path,$o->file_path())) - { - $this->error(sprintf('Save after rename failed for (%s)',$o->id)); - continue; - } - } - else - { - $this->error(sprintf('Rename failed for (%s)',$o->id)); - continue; - } - - chmod($o->file_path(),0444); - } - else - { - if ($x > 0) - $this->warn(sprintf('Unable to move (%s) [%s] to [%s], moveable returned (%s)',$o->id,$o->file_path(),$o->file_path(FALSE,TRUE),$x)); - } + } else { + $po = Photo::notRemove()->notDuplicate(); } - $bar->advance(); - }); + if (! $po) + exit; + + // 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 ($o = $photo->shift()) { + if (($x = $o->moveable()) === TRUE) { + Log::info(sprintf('%s: Moving (%s)[%s]',__METHOD__,$o->id,$o->filename)); + + if ($this->makeParentDir(dirname($o->file_path(FALSE,TRUE))) AND rename($o->file_path(),$o->file_path(FALSE,TRUE))) { + // Convert the path to a relative one. + $o->filename = $o->file_path(TRUE,TRUE); + + // @todo If the DB update failed, move it back. + if (! $o->save()) # AND ! rename($path,$o->file_path())) + { + $this->error(sprintf('Save after rename failed for (%s)',$o->id)); + continue; + } + + } else { + $this->error(sprintf('Rename failed for (%s)',$o->id)); + continue; + } + + chmod($o->file_path(),0444); + + } else { + if ($x > 0) + $this->warn(sprintf('Unable to move (%s) [%s] to [%s], moveable returned (%s)',$o->id,$o->file_path(),$o->file_path(FALSE,TRUE),$x)); + } + } + + $bar->advance(); + }); } -} +} \ No newline at end of file diff --git a/app/Http/Controllers/PhotoController.php b/app/Http/Controllers/PhotoController.php index a1b61a0..7ad2e94 100644 --- a/app/Http/Controllers/PhotoController.php +++ b/app/Http/Controllers/PhotoController.php @@ -2,11 +2,9 @@ namespace App\Http\Controllers; -use Illuminate\Http\Response; use Illuminate\Http\Request; -use App\Http\Requests; -use App\Model\Photo; +use App\Models\Photo; use App\Jobs\PhotoDelete; class PhotoController extends Controller @@ -23,86 +21,89 @@ class PhotoController extends Controller public function delete($id) { - $po = Photo::notRemove()->findOrFail($id); + $po = Photo::notRemove()->findOrFail($id); - if ($po) - { - $po->remove = TRUE; - $po->save(); - } + if ($po) + { + $po->remove = TRUE; + $po->save(); + } - return redirect()->action('PhotoController@info',[$id]); + return redirect()->action('PhotoController@info',[$id]); } public function deletes($id=NULL) { - return view('catalog.deletereview',['return'=>url('/p/deletes'),'catalog'=>is_null($id) ? Photo::where('remove',1)->paginate(50) : Photo::where('id',$id)->paginate(1)]); + return view('catalog.deletereview',['return'=>url('/p/deletes'),'catalog'=>is_null($id) ? Photo::where('remove',1)->paginate(50) : Photo::where('id',$id)->paginate(1)]); } public function deletesUpdate(Request $request) { - foreach ($request->input('remove') as $id=>$k) - { - $o = Photo::findOrFail($id); + foreach ($request->input('remove') as $id=>$k) + { + $o = Photo::findOrFail($id); - if ($o->remove AND $request->input('remove.'.$id)) - $this->dispatch((new PhotoDelete($o))->onQueue('delete')); - } + if ($o->remove AND $request->input('remove.'.$id)) + $this->dispatch((new PhotoDelete($o))->onQueue('delete')); + } - return redirect()->action('PhotoController@deletes',$request->input('pagenext') ? '?page='.$request->input('pagenext') : NULL); + return redirect()->action('PhotoController@deletes',$request->input('pagenext') ? '?page='.$request->input('pagenext') : NULL); } public function duplicates($id=NULL) { - return view('catalog.duplicatereview',['return'=>url('/p/duplicates'),'catalog'=>is_null($id) ? Photo::notRemove()->where('duplicate',1)->paginate(50) : Photo::where('id',$id)->paginate(1)]); + return view('catalog.duplicatereview',[ + 'return'=>url('/p/duplicates'), + 'catalog'=>is_null($id) ? Photo::notRemove()->where('duplicate',1)->paginate(50) : Photo::where('id',$id)->paginate(1) + ]); } public function duplicatesUpdate(Request $request) { - foreach ($request->input('items') as $id) - { - $po = Photo::findOrFail($id); + foreach ($request->input('items') as $id) + { + $po = Photo::findOrFail($id); - // Set if duplicate - $po->duplicate = $request->input('duplicate.'.$id) ? 1 : NULL; + // Set if duplicate + $po->duplicate = $request->input('duplicate.'.$id) ? 1 : NULL; - // Set if flag - $po->flag = $request->input('flag.'.$id) ? 1 : NULL; + // Set if flag + $po->flag = $request->input('flag.'.$id) ? 1 : NULL; - // Set if delete - $po->remove = $request->input('remove.'.$id) ? 1 : NULL; + // Set if delete + $po->remove = $request->input('remove.'.$id) ? 1 : NULL; - $po->isDirty() AND $po->save(); - } + $po->isDirty() AND $po->save(); + } - return redirect()->action('PhotoController@duplicates','?page='.$request->input('page')); + return redirect()->action('PhotoController@duplicates','?page='.$request->input('page')); } public function info($id) { - return view('photo.view', ['photo'=> Photo::findOrFail($id)]); + return view('photo.view', ['photo'=> Photo::findOrFail($id)]); } public function thumbnail($id) { - return response(Photo::findOrFail($id)->thumbnail(TRUE))->header('Content-Type','image/jpeg'); + return response(Photo::findOrFail($id)->thumbnail(TRUE))->header('Content-Type','image/jpeg'); } public function undelete($id) { - $po = Photo::findOrFail($id); + $po = Photo::findOrFail($id); - if ($po) - { - $po->remove = NULL; - $po->save(); - } + if ($po) + { + $po->remove = NULL; + $po->save(); + } - return redirect()->action('PhotoController@info',[$id]); + return redirect()->action('PhotoController@info',[$id]); } public function view($id) { - return response(Photo::findOrFail($id)->image())->header('Content-Type','image/jpeg'); + return response(Photo::findOrFail($id)->image())->header('Content-Type','image/jpeg'); } -} +} \ No newline at end of file diff --git a/app/Jobs/CatalogScan.php b/app/Jobs/CatalogScan.php index cee62aa..d583a69 100644 --- a/app/Jobs/CatalogScan.php +++ b/app/Jobs/CatalogScan.php @@ -2,12 +2,13 @@ namespace App\Jobs; -use Log; -use App\Jobs\Job; +use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Queue\SerializesModels; use Illuminate\Queue\InteractsWithQueue; -use Illuminate\Contracts\Queue\ShouldQueue; -use Artisan; +use Illuminate\Support\Facades\Log; +use Illuminate\Support\Facades\Artisan; + +use App\Models\Abstracted\Catalog; class CatalogScan extends Job implements ShouldQueue { @@ -21,8 +22,7 @@ class CatalogScan extends Job implements ShouldQueue * * @return void */ - public function __construct(\App\Model\Abstracted\Catalog $o) - { + public function __construct(Catalog $o) { $this->o = $o; } @@ -34,6 +34,7 @@ class CatalogScan extends Job implements ShouldQueue public function handle() { Log::info(sprintf('%s: Scanning [%s|%s]',__METHOD__,$this->o->objecttype(),$this->o->id)); + Artisan::call('catalog:scan',['type'=>$this->o->objecttype(),'id'=>$this->o->id]); } -} +} \ No newline at end of file diff --git a/app/Jobs/PhotoDelete.php b/app/Jobs/PhotoDelete.php index 26574d6..ae6cda1 100644 --- a/app/Jobs/PhotoDelete.php +++ b/app/Jobs/PhotoDelete.php @@ -2,16 +2,16 @@ namespace App\Jobs; -use Log; -use App\Jobs\Job; +use Illuminate\Support\Facades\Log; use Illuminate\Queue\SerializesModels; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Queue\ShouldQueue; -use App\Model\Photo; + +use App\Models\Photo; class PhotoDelete extends Job implements ShouldQueue { - use InteractsWithQueue, SerializesModels; + use InteractsWithQueue,SerializesModels; private $photo; diff --git a/app/Jobs/PhotoMove.php b/app/Jobs/PhotoMove.php index 380fde3..a8913a8 100644 --- a/app/Jobs/PhotoMove.php +++ b/app/Jobs/PhotoMove.php @@ -2,17 +2,17 @@ namespace App\Jobs; -use Log; -use App\Jobs\Job; +use Illuminate\Support\Facades\Log; use Illuminate\Queue\SerializesModels; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Queue\ShouldQueue; -use App\Model\Photo; -use Artisan; +use Illuminate\Support\Facades\Artisan; + +use App\Models\Photo; class PhotoMove extends Job implements ShouldQueue { - use InteractsWithQueue, SerializesModels; + use InteractsWithQueue,SerializesModels; private $photo; diff --git a/app/Jobs/VideoDelete.php b/app/Jobs/VideoDelete.php index 2c29a16..56a1971 100644 --- a/app/Jobs/VideoDelete.php +++ b/app/Jobs/VideoDelete.php @@ -2,16 +2,16 @@ namespace App\Jobs; -use Log; -use App\Jobs\Job; +use Illuminate\Support\Facades\Log; use Illuminate\Queue\SerializesModels; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Queue\ShouldQueue; -use App\Model\Video; + +use App\Models\Video; class VideoDelete extends Job implements ShouldQueue { - use InteractsWithQueue, SerializesModels; + use InteractsWithQueue,SerializesModels; private $video; diff --git a/app/Jobs/VideoMove.php b/app/Jobs/VideoMove.php index a63475f..8864618 100644 --- a/app/Jobs/VideoMove.php +++ b/app/Jobs/VideoMove.php @@ -2,17 +2,17 @@ namespace App\Jobs; -use Log; -use App\Jobs\Job; +use Illuminate\Support\Facades\Log; use Illuminate\Queue\SerializesModels; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Queue\ShouldQueue; -use App\Model\Video; -use Artisan; +use Illuminate\Support\Facades\Artisan; + +use App\Models\Video; class VideoMove extends Job implements ShouldQueue { - use InteractsWithQueue, SerializesModels; + use InteractsWithQueue,SerializesModels; private $video; diff --git a/app/Models/Abstracted/Catalog.php b/app/Models/Abstracted/Catalog.php index f1dba61..172e10b 100644 --- a/app/Models/Abstracted/Catalog.php +++ b/app/Models/Abstracted/Catalog.php @@ -62,13 +62,13 @@ abstract class Catalog extends Model }); } - abstract public function setDateCreated(); - abstract public function setLocation(); - abstract public function setMakeModel(); - abstract public function setSignature(); - abstract public function setSubSecTime(); - abstract public function setThumbnail(); - abstract public function view(); + abstract public function setDateCreated(); + abstract public function setLocation(); + abstract public function setMakeModel(); + abstract public function setSignature(); + abstract public function setSubSecTime(); + abstract public function setThumbnail(); + abstract public function view(); /** * Date the multimedia was created @@ -282,7 +282,7 @@ abstract class Catalog extends Model { return DB::table($this->getTable()) ->where('id','<',$this->id) - ->orderby('id','DEC') + ->orderby('id','DESC') ->first(); } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 8a71c5c..731ef3b 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -2,6 +2,7 @@ namespace App\Providers; +use Illuminate\Support\Facades\Log; use Illuminate\Support\ServiceProvider; use Illuminate\Foundation\Bus\DispatchesJobs; @@ -29,22 +30,22 @@ class AppServiceProvider extends ServiceProvider */ public function boot() { - // Any photo saved, queue it to be moved. - Photo::saved(function($photo) { - if ($photo->scanned AND ! $photo->duplicate AND ! $photo->remove AND ($x=$photo->moveable()) === TRUE) - { - Log::info(sprintf('%s: Need to Move [%s]',__METHOD__,$photo->id.'|'.serialize($x))); - $this->dispatch((new PhotoMove($photo))->onQueue('move')); - } - }); + // Any photo saved, queue it to be moved. + Photo::saved(function($photo) { + if ($photo->scanned AND ! $photo->duplicate AND ! $photo->remove AND ($x=$photo->moveable()) === TRUE) { + Log::info(sprintf('%s: Need to Move [%s]',__METHOD__,$photo->id.'|'.serialize($x))); - // Any video saved, queue it to be moved. - Video::saved(function($video) { - if ($video->scanned AND ! $video->duplicate AND ! $video->remove AND ($x=$video->moveable()) === TRUE) - { - Log::info(sprintf('%s: Need to Move [%s]',__METHOD__,$video->id.'|'.serialize($x))); - $this->dispatch((new VideoMove($video))->onQueue('move')); - } - }); + $this->dispatch((new PhotoMove($photo))->onQueue('move')); + } + }); + + // Any video saved, queue it to be moved. + Video::saved(function($video) { + if ($video->scanned AND ! $video->duplicate AND ! $video->remove AND ($x=$video->moveable()) === TRUE) { + Log::info(sprintf('%s: Need to Move [%s]',__METHOD__,$video->id.'|'.serialize($x))); + + $this->dispatch((new VideoMove($video))->onQueue('move')); + } + }); } -} +} \ No newline at end of file diff --git a/app/Traits/Files.php b/app/Traits/Files.php index 8b166e3..ad00b7a 100644 --- a/app/Traits/Files.php +++ b/app/Traits/Files.php @@ -2,15 +2,15 @@ namespace App\Traits; -use Log; -use App\Model\Photo; +use Illuminate\Support\Collection; +use Illuminate\Support\Facades\Log; trait Files { /** * Get a list of files */ - public function getFiles(array $option,$type) + public function getFiles(array $option,string $type): Collection { // Make sure we got a directory or a file to import if (is_null($option['file']) AND is_null($option['dir'])) @@ -18,38 +18,42 @@ trait Files Log::info(sprintf('%s: Processing: %s',__METHOD__,($option['file'] ? $option['file'] : $option['dir']))); - $files = []; + $files = collect(); $dir = ''; - if ($option['dir']) - { + if ($option['dir'] AND is_dir($option['dir'])) { // Remove our trailing slash from the directory. $dir = preg_replace('/\/$/','',$option['dir']); // Exclude . & .. from the path. - $files = array_diff(scandir($dir),array('.','..')); + $files = $files->merge(array_diff(scandir($dir),array('.','..'))); - } - elseif ($option['file'] AND file_exists($option['file'])) - { + } elseif ($option['file'] AND ! is_dir($option['file']) AND file_exists($option['file'])) { $dir = dirname($option['file']); - $files = array(basename($option['file'])); + + $files->push(basename($option['file'])); } - // Determine if our dir is releative to where we store data + // Determine if our dir is relative to where we store data $dir = static::path($dir,$type); // Add our path if ($dir) - array_walk($files,function(&$value,$key,$path='') { - if ($path) { - $value = sprintf('%s/%s',$path,$value); - } - },$dir); + $files->transform(function($value) use ($dir) { + return sprintf('%s/%s',$dir,$value); + }); + + Log::info(sprintf('%s: Processing: %s (%s)',__METHOD__,($option['file'] ? $option['file'] : $option['dir']),count($files))); return $files; } + /** + * Recursively make a parent dir to hold files. + * + * @param $dir + * @return bool + */ public function makeParentDir($dir) { if (is_dir($dir)) @@ -61,8 +65,15 @@ trait Files return is_writable(dirname($dir)) AND mkdir($dir); } - public static function path($path,$type) + /** + * Return if the dir is a sub dir of our config. + * + * @param $path + * @param $type + * @return string + */ + public static function path($path,$type): string { return (strpos($path,config($type.'.dir').'/') === 0) ? str_replace(config($type.'.dir').'/','',$path) : $path; } -} +} \ No newline at end of file diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index 59aa01a..a91e1d3 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -1,7 +1,8 @@ increments('id'); + $table->bigIncrements('id'); $table->string('name'); $table->string('email')->unique(); + $table->timestamp('email_verified_at')->nullable(); $table->string('password'); $table->rememberToken(); $table->timestamps(); @@ -29,6 +31,6 @@ class CreateUsersTable extends Migration */ public function down() { - Schema::drop('users'); + Schema::dropIfExists('users'); } } diff --git a/database/migrations/2014_10_12_100000_create_password_resets_table.php b/database/migrations/2014_10_12_100000_create_password_resets_table.php index 00057f9..0ee0a36 100644 --- a/database/migrations/2014_10_12_100000_create_password_resets_table.php +++ b/database/migrations/2014_10_12_100000_create_password_resets_table.php @@ -1,7 +1,8 @@ string('email')->index(); - $table->string('token')->index(); - $table->timestamp('created_at'); + $table->string('token'); + $table->timestamp('created_at')->nullable(); }); } @@ -26,6 +27,6 @@ class CreatePasswordResetsTable extends Migration */ public function down() { - Schema::drop('password_resets'); + Schema::dropIfExists('password_resets'); } } diff --git a/resources/views/catalog/duplicatereview.blade.php b/resources/views/catalog/duplicatereview.blade.php index ec2f90f..ff1fb12 100644 --- a/resources/views/catalog/duplicatereview.blade.php +++ b/resources/views/catalog/duplicatereview.blade.php @@ -1,4 +1,4 @@ -@extends('layouts.app') +@extends('adminlte::layouts.app') ['id','idlink'], @@ -13,7 +13,7 @@ 'Delete'=>['remove','removecheckbox'], ];?> -@section('content') +@section('main-content')
diff --git a/resources/views/photo/view.blade.php b/resources/views/photo/view.blade.php index 576eef9..4fc70d6 100644 --- a/resources/views/photo/view.blade.php +++ b/resources/views/photo/view.blade.php @@ -1,6 +1,6 @@ -@extends('layouts.app') +@extends('adminlte::layouts.app') -@section('content') +@section('main-content')
@@ -41,7 +41,7 @@
- +
diff --git a/resources/views/vendor/.gitkeep b/resources/views/vendor/.gitkeep deleted file mode 100644 index 8b13789..0000000 --- a/resources/views/vendor/.gitkeep +++ /dev/null @@ -1 +0,0 @@ - diff --git a/routes/web.php b/routes/web.php index 810aa34..c747c5a 100644 --- a/routes/web.php +++ b/routes/web.php @@ -11,6 +11,25 @@ | */ -Route::get('/', function () { - return view('welcome'); -}); +#Route::get('/', function () { +# return view('welcome'); +#}); + +Route::get('/p/deletes/{id?}','PhotoController@deletes')->where('id','[0-9]+'); +Route::get('/v/deletes/{id?}','VideoController@deletes')->where('id','[0-9]+'); +Route::get('/p/duplicates/{id?}','PhotoController@duplicates')->where('id','[0-9]+'); +Route::get('/v/duplicates/{id?}','VideoController@duplicates')->where('id','[0-9]+'); +Route::get('/p/info/{id}','PhotoController@info')->where('id','[0-9]+'); +Route::get('/v/info/{id}','VideoController@info')->where('id','[0-9]+'); +Route::get('/p/thumbnail/{id}','PhotoController@thumbnail')->where('id','[0-9]+'); +Route::get('/p/view/{id}','PhotoController@view')->where('id','[0-9]+'); +Route::get('/v/view/{id}','VideoController@view')->where('id','[0-9]+'); + +Route::post('/p/delete/{id}','PhotoController@delete')->where('id','[0-9]+'); +Route::post('/v/delete/{id}','VideoController@delete')->where('id','[0-9]+'); +Route::post('/p/duplicates','PhotoController@duplicatesUpdate'); +Route::post('/v/duplicates','VideoController@duplicatesUpdate'); +Route::post('/p/deletes','PhotoController@deletesUpdate'); +Route::post('/v/deletes','VideoController@deletesUpdate'); +Route::post('/p/undelete/{id}','PhotoController@undelete')->where('id','[0-9]+'); +Route::post('/v/undelete/{id}','VideoController@undelete')->where('id','[0-9]+'); \ No newline at end of file