Update photo import to laravel 6.4

This commit is contained in:
Deon George 2019-11-09 13:52:04 +11:00
parent f6b456aa3d
commit 83d6d1e055
18 changed files with 274 additions and 253 deletions

View File

@ -3,7 +3,6 @@
namespace App\Console\Commands; namespace App\Console\Commands;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\ModelNotFoundException;
class CatalogScan extends Command class CatalogScan extends Command
{ {
@ -31,56 +30,51 @@ class CatalogScan extends Command
*/ */
public function handle() public function handle()
{ {
$class = 'App\Model\\'.$this->argument('type'); $class = 'App\Models\\'.$this->argument('type');
if (! class_exists($class))
abort(500,sprintf('No class [%s]',$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())) $o = $class::findOrFail($this->argument('id'));
{
$this->warn(sprintf('Ignoring [%s], it is not readable',$o->file_path()));
exit;
}
$o->setDateCreated(); if (! is_readable($o->file_path())) {
$o->setSubSecTime(); $this->warn(sprintf('Ignoring [%s], it is not readable',$o->file_path()));
$o->setSignature(); exit;
$o->setMakeModel(); }
$o->setLocation();
$o->setHeightWidth();
$o->setThumbnail();
// If this is a duplicate $o->setDateCreated();
$x = $class::whereIN('id',$o->list_duplicate())->get(); $o->setSubSecTime();
if (count($x)) { $o->setSignature();
$break = FALSE; $o->setMakeModel();
$o->setLocation();
$o->setHeightWidth();
$o->setThumbnail();
foreach ($x as $oo) { // If this is a duplicate
// And that photo is not marked as a duplicate $x = $class::whereIN('id',$o->list_duplicate())->get();
if (! $oo->duplicate) if (count($x)) {
{ foreach ($x as $oo) {
$o->duplicate = '1'; // And that photo is not marked as a duplicate
$this->warn(sprintf('Image [%s] marked as a duplicate',$o->file_path())); 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 the file signature also matches, we'll mark it for deletion
if ($oo->file_signature AND $o->file_signature == $oo->file_signature) if ($oo->file_signature AND $o->file_signature == $oo->file_signature) {
{ $this->warn(sprintf('Image [%s] marked for deletion',$o->file_path()));
$this->warn(sprintf('Image [%s] marked for deletion',$o->file_path())); $o->remove = '1';
$o->remove = '1'; }
break;
} }
break;
} }
} }
}
$o->scanned = '1'; $o->scanned = '1';
if ($o->getDirty()) if ($o->getDirty())
$this->warn(sprintf('Image [%s] metadata changed',$o->file_path())); $this->warn(sprintf('Image [%s] metadata changed',$o->file_path()));
$o->save(); $o->save();
} }
} }

View File

@ -2,19 +2,17 @@
namespace App\Console\Commands; namespace App\Console\Commands;
use Log; use Illuminate\Support\Facades\Log;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Foundation\Bus\DispatchesJobs;
use App\Model\Person;
use App\Model\PhotoPerson; use App\Models\{Person,Photo,Tag};
use App\Model\Photo; use App\Traits\Files;
use App\Model\PhotoTag;
use App\Model\Tag;
class PhotoImport extends Command class PhotoImport extends Command
{ {
use DispatchesJobs; use DispatchesJobs;
use \App\Traits\Files; use Files;
/** /**
* The name and signature of the console command. * The name and signature of the console command.
@ -53,7 +51,11 @@ class PhotoImport extends Command
*/ */
public function handle() 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)) if (! count($files))
exit; exit;
@ -65,22 +67,21 @@ class PhotoImport extends Command
$t = $p = array(); $t = $p = array();
// Tags // Tags
if ($this->option('tags')) if ($this->option('tags')) {
{
$tags = explode(',',$this->option('tags')); $tags = explode(',',$this->option('tags'));
$t = Tag::whereIn('tag',$tags)->pluck('id')->toArray(); $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))); $this->error(sprintf('Tag [%s] dont exist',join('|',$tags)));
abort(501); abort(501);
} }
} }
// People // People
if ($this->option('people')) if ($this->option('people')) {
{
$tags = explode(',',$this->option('people')); $tags = explode(',',$this->option('people'));
$p = Person::whereIn('tag',$tags)->pluck('id')->toArray(); $p = Person::whereIn('tag',$tags)->pluck('id')->toArray();
if (! $p OR count($p) != count($tags)) if (! $p OR count($p) != count($tags))
{ {
$this->error(sprintf('People [%s] dont exist',join('|',$tags))); $this->error(sprintf('People [%s] dont exist',join('|',$tags)));
@ -89,18 +90,15 @@ class PhotoImport extends Command
} }
$c = 0; $c = 0;
foreach ($files as $file) foreach ($files as $file) {
{
$bar->advance(); $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)); $this->warn(sprintf('Ignoring file [%s]',$file));
continue; 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)); $this->warn(sprintf('Ignoring [%s]',$file));
continue; continue;
} }
@ -112,21 +110,21 @@ class PhotoImport extends Command
$o = Photo::where('filename',$file)->first(); $o = Photo::where('filename',$file)->first();
if (is_null($o)) // The photo doesnt exist
{ if (is_null($o)) {
$o = new Photo; $o = new Photo;
$o->filename = $file; $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())); $this->warn(sprintf('Ignoring [%s], it is not readable',$o->file_path()));
continue; continue;
} }
if ($o->exists)
$this->warn(sprintf('%s [%s] already in DB: %s',$o->objectType(),$file,$o->id));
$o->save(); $o->save();
if ($o->wasRecentlyCreated) if ($o->wasRecentlyCreated)
@ -145,4 +143,4 @@ class PhotoImport extends Command
return $this->info(sprintf('Photos processed: %s',$c)); return $this->info(sprintf('Photos processed: %s',$c));
} }
} }

View File

@ -2,14 +2,15 @@
namespace App\Console\Commands; namespace App\Console\Commands;
use DB; use Illuminate\Support\Facades\Log;
use Log;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use App\Model\Photo;
use App\Traits\Files;
use App\Models\Photo;
class PhotoMove extends Command class PhotoMove extends Command
{ {
use \App\Traits\Files; use Files;
/** /**
* The name and signature of the console command. * The name and signature of the console command.
@ -44,61 +45,54 @@ class PhotoMove extends Command
*/ */
public function handle() public function handle()
{ {
if ($this->option('file')) if ($this->option('file')) {
{ $po = Photo::notRemove()->notDuplicate()->where('filename',Photo::path($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 (! $po) } elseif ($this->option('id')) {
exit; $po = Photo::notRemove()->notDuplicate()->where('id',$this->option('id'));
// Show a progress bar } else {
$bar = $this->output->createProgressBar($po->count()); $po = Photo::notRemove()->notDuplicate();
$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(); 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();
});
} }
} }

View File

@ -2,11 +2,9 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Illuminate\Http\Response;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Http\Requests; use App\Models\Photo;
use App\Model\Photo;
use App\Jobs\PhotoDelete; use App\Jobs\PhotoDelete;
class PhotoController extends Controller class PhotoController extends Controller
@ -23,86 +21,89 @@ class PhotoController extends Controller
public function delete($id) public function delete($id)
{ {
$po = Photo::notRemove()->findOrFail($id); $po = Photo::notRemove()->findOrFail($id);
if ($po) if ($po)
{ {
$po->remove = TRUE; $po->remove = TRUE;
$po->save(); $po->save();
} }
return redirect()->action('PhotoController@info',[$id]); return redirect()->action('PhotoController@info',[$id]);
} }
public function deletes($id=NULL) 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) public function deletesUpdate(Request $request)
{ {
foreach ($request->input('remove') as $id=>$k) foreach ($request->input('remove') as $id=>$k)
{ {
$o = Photo::findOrFail($id); $o = Photo::findOrFail($id);
if ($o->remove AND $request->input('remove.'.$id)) if ($o->remove AND $request->input('remove.'.$id))
$this->dispatch((new PhotoDelete($o))->onQueue('delete')); $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) 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) public function duplicatesUpdate(Request $request)
{ {
foreach ($request->input('items') as $id) foreach ($request->input('items') as $id)
{ {
$po = Photo::findOrFail($id); $po = Photo::findOrFail($id);
// Set if duplicate // Set if duplicate
$po->duplicate = $request->input('duplicate.'.$id) ? 1 : NULL; $po->duplicate = $request->input('duplicate.'.$id) ? 1 : NULL;
// Set if flag // Set if flag
$po->flag = $request->input('flag.'.$id) ? 1 : NULL; $po->flag = $request->input('flag.'.$id) ? 1 : NULL;
// Set if delete // Set if delete
$po->remove = $request->input('remove.'.$id) ? 1 : NULL; $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) public function info($id)
{ {
return view('photo.view', ['photo'=> Photo::findOrFail($id)]); return view('photo.view', ['photo'=> Photo::findOrFail($id)]);
} }
public function thumbnail($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) public function undelete($id)
{ {
$po = Photo::findOrFail($id); $po = Photo::findOrFail($id);
if ($po) if ($po)
{ {
$po->remove = NULL; $po->remove = NULL;
$po->save(); $po->save();
} }
return redirect()->action('PhotoController@info',[$id]); return redirect()->action('PhotoController@info',[$id]);
} }
public function view($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');
} }
} }

View File

@ -2,12 +2,13 @@
namespace App\Jobs; namespace App\Jobs;
use Log; use Illuminate\Contracts\Queue\ShouldQueue;
use App\Jobs\Job;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Support\Facades\Log;
use Artisan; use Illuminate\Support\Facades\Artisan;
use App\Models\Abstracted\Catalog;
class CatalogScan extends Job implements ShouldQueue class CatalogScan extends Job implements ShouldQueue
{ {
@ -21,8 +22,7 @@ class CatalogScan extends Job implements ShouldQueue
* *
* @return void * @return void
*/ */
public function __construct(\App\Model\Abstracted\Catalog $o) public function __construct(Catalog $o) {
{
$this->o = $o; $this->o = $o;
} }
@ -34,6 +34,7 @@ class CatalogScan extends Job implements ShouldQueue
public function handle() public function handle()
{ {
Log::info(sprintf('%s: Scanning [%s|%s]',__METHOD__,$this->o->objecttype(),$this->o->id)); 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]); Artisan::call('catalog:scan',['type'=>$this->o->objecttype(),'id'=>$this->o->id]);
} }
} }

View File

@ -2,16 +2,16 @@
namespace App\Jobs; namespace App\Jobs;
use Log; use Illuminate\Support\Facades\Log;
use App\Jobs\Job;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Contracts\Queue\ShouldQueue;
use App\Model\Photo;
use App\Models\Photo;
class PhotoDelete extends Job implements ShouldQueue class PhotoDelete extends Job implements ShouldQueue
{ {
use InteractsWithQueue, SerializesModels; use InteractsWithQueue,SerializesModels;
private $photo; private $photo;

View File

@ -2,17 +2,17 @@
namespace App\Jobs; namespace App\Jobs;
use Log; use Illuminate\Support\Facades\Log;
use App\Jobs\Job;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Contracts\Queue\ShouldQueue;
use App\Model\Photo; use Illuminate\Support\Facades\Artisan;
use Artisan;
use App\Models\Photo;
class PhotoMove extends Job implements ShouldQueue class PhotoMove extends Job implements ShouldQueue
{ {
use InteractsWithQueue, SerializesModels; use InteractsWithQueue,SerializesModels;
private $photo; private $photo;

View File

@ -2,16 +2,16 @@
namespace App\Jobs; namespace App\Jobs;
use Log; use Illuminate\Support\Facades\Log;
use App\Jobs\Job;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Contracts\Queue\ShouldQueue;
use App\Model\Video;
use App\Models\Video;
class VideoDelete extends Job implements ShouldQueue class VideoDelete extends Job implements ShouldQueue
{ {
use InteractsWithQueue, SerializesModels; use InteractsWithQueue,SerializesModels;
private $video; private $video;

View File

@ -2,17 +2,17 @@
namespace App\Jobs; namespace App\Jobs;
use Log; use Illuminate\Support\Facades\Log;
use App\Jobs\Job;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Contracts\Queue\ShouldQueue;
use App\Model\Video; use Illuminate\Support\Facades\Artisan;
use Artisan;
use App\Models\Video;
class VideoMove extends Job implements ShouldQueue class VideoMove extends Job implements ShouldQueue
{ {
use InteractsWithQueue, SerializesModels; use InteractsWithQueue,SerializesModels;
private $video; private $video;

View File

@ -62,13 +62,13 @@ abstract class Catalog extends Model
}); });
} }
abstract public function setDateCreated(); abstract public function setDateCreated();
abstract public function setLocation(); abstract public function setLocation();
abstract public function setMakeModel(); abstract public function setMakeModel();
abstract public function setSignature(); abstract public function setSignature();
abstract public function setSubSecTime(); abstract public function setSubSecTime();
abstract public function setThumbnail(); abstract public function setThumbnail();
abstract public function view(); abstract public function view();
/** /**
* Date the multimedia was created * Date the multimedia was created
@ -282,7 +282,7 @@ abstract class Catalog extends Model
{ {
return DB::table($this->getTable()) return DB::table($this->getTable())
->where('id','<',$this->id) ->where('id','<',$this->id)
->orderby('id','DEC') ->orderby('id','DESC')
->first(); ->first();
} }

View File

@ -2,6 +2,7 @@
namespace App\Providers; namespace App\Providers;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Foundation\Bus\DispatchesJobs;
@ -29,22 +30,22 @@ class AppServiceProvider extends ServiceProvider
*/ */
public function boot() public function boot()
{ {
// Any photo saved, queue it to be moved. // Any photo saved, queue it to be moved.
Photo::saved(function($photo) { Photo::saved(function($photo) {
if ($photo->scanned AND ! $photo->duplicate AND ! $photo->remove AND ($x=$photo->moveable()) === TRUE) 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)));
Log::info(sprintf('%s: Need to Move [%s]',__METHOD__,$photo->id.'|'.serialize($x)));
$this->dispatch((new PhotoMove($photo))->onQueue('move'));
}
});
// Any video saved, queue it to be moved. $this->dispatch((new PhotoMove($photo))->onQueue('move'));
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))); // Any video saved, queue it to be moved.
$this->dispatch((new VideoMove($video))->onQueue('move')); 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'));
}
});
} }
} }

View File

@ -2,15 +2,15 @@
namespace App\Traits; namespace App\Traits;
use Log; use Illuminate\Support\Collection;
use App\Model\Photo; use Illuminate\Support\Facades\Log;
trait Files trait Files
{ {
/** /**
* Get a list of 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 // Make sure we got a directory or a file to import
if (is_null($option['file']) AND is_null($option['dir'])) 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']))); Log::info(sprintf('%s: Processing: %s',__METHOD__,($option['file'] ? $option['file'] : $option['dir'])));
$files = []; $files = collect();
$dir = ''; $dir = '';
if ($option['dir']) if ($option['dir'] AND is_dir($option['dir'])) {
{
// Remove our trailing slash from the directory. // Remove our trailing slash from the directory.
$dir = preg_replace('/\/$/','',$option['dir']); $dir = preg_replace('/\/$/','',$option['dir']);
// Exclude . & .. from the path. // Exclude . & .. from the path.
$files = array_diff(scandir($dir),array('.','..')); $files = $files->merge(array_diff(scandir($dir),array('.','..')));
} } elseif ($option['file'] AND ! is_dir($option['file']) AND file_exists($option['file'])) {
elseif ($option['file'] AND file_exists($option['file']))
{
$dir = dirname($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); $dir = static::path($dir,$type);
// Add our path // Add our path
if ($dir) if ($dir)
array_walk($files,function(&$value,$key,$path='') { $files->transform(function($value) use ($dir) {
if ($path) { return sprintf('%s/%s',$dir,$value);
$value = sprintf('%s/%s',$path,$value); });
}
},$dir); Log::info(sprintf('%s: Processing: %s (%s)',__METHOD__,($option['file'] ? $option['file'] : $option['dir']),count($files)));
return $files; return $files;
} }
/**
* Recursively make a parent dir to hold files.
*
* @param $dir
* @return bool
*/
public function makeParentDir($dir) public function makeParentDir($dir)
{ {
if (is_dir($dir)) if (is_dir($dir))
@ -61,8 +65,15 @@ trait Files
return is_writable(dirname($dir)) AND mkdir($dir); 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; return (strpos($path,config($type.'.dir').'/') === 0) ? str_replace(config($type.'.dir').'/','',$path) : $path;
} }
} }

View File

@ -1,7 +1,8 @@
<?php <?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateUsersTable extends Migration class CreateUsersTable extends Migration
{ {
@ -13,9 +14,10 @@ class CreateUsersTable extends Migration
public function up() public function up()
{ {
Schema::create('users', function (Blueprint $table) { Schema::create('users', function (Blueprint $table) {
$table->increments('id'); $table->bigIncrements('id');
$table->string('name'); $table->string('name');
$table->string('email')->unique(); $table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password'); $table->string('password');
$table->rememberToken(); $table->rememberToken();
$table->timestamps(); $table->timestamps();
@ -29,6 +31,6 @@ class CreateUsersTable extends Migration
*/ */
public function down() public function down()
{ {
Schema::drop('users'); Schema::dropIfExists('users');
} }
} }

View File

@ -1,7 +1,8 @@
<?php <?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePasswordResetsTable extends Migration class CreatePasswordResetsTable extends Migration
{ {
@ -14,8 +15,8 @@ class CreatePasswordResetsTable extends Migration
{ {
Schema::create('password_resets', function (Blueprint $table) { Schema::create('password_resets', function (Blueprint $table) {
$table->string('email')->index(); $table->string('email')->index();
$table->string('token')->index(); $table->string('token');
$table->timestamp('created_at'); $table->timestamp('created_at')->nullable();
}); });
} }
@ -26,6 +27,6 @@ class CreatePasswordResetsTable extends Migration
*/ */
public function down() public function down()
{ {
Schema::drop('password_resets'); Schema::dropIfExists('password_resets');
} }
} }

View File

@ -1,4 +1,4 @@
@extends('layouts.app') @extends('adminlte::layouts.app')
<?php $data = [ <?php $data = [
'ID'=>['id','idlink'], 'ID'=>['id','idlink'],
@ -13,7 +13,7 @@
'Delete'=>['remove','removecheckbox'], 'Delete'=>['remove','removecheckbox'],
];?> ];?>
@section('content') @section('main-content')
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="col-md-11 col-md-offset-1"> <div class="col-md-11 col-md-offset-1">

View File

@ -1,6 +1,6 @@
@extends('layouts.app') @extends('adminlte::layouts.app')
@section('content') @section('main-content')
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="col-md-10 col-md-offset-1"> <div class="col-md-10 col-md-offset-1">
@ -41,7 +41,7 @@
<?php else : ?> <?php else : ?>
<div id="map" style="width: 400px; height: 300px"></div> <div id="map" style="width: 400px; height: 300px"></div>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript"> <script type="text/javascript">
var myLatLng = {lat: {{ $photo->gps_lat }}, lng: {{ $photo->gps_lon }}}; var myLatLng = {lat: {{ $photo->gps_lat }}, lng: {{ $photo->gps_lon }}};
var map = new google.maps.Map(document.getElementById("map"), { var map = new google.maps.Map(document.getElementById("map"), {
zoom: 16, zoom: 16,
@ -52,7 +52,7 @@
map: map, map: map,
position: myLatLng, position: myLatLng,
}); });
</script> </script>
<?php endif ?> <?php endif ?>
</dd> </dd>
<br/> <br/>

View File

@ -1 +0,0 @@

View File

@ -11,6 +11,25 @@
| |
*/ */
Route::get('/', function () { #Route::get('/', function () {
return view('welcome'); # 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]+');