Removed more redundant functions
This commit is contained in:
parent
9208ddf779
commit
431ceec69f
@ -1,145 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
|
||||
use App\Models\{Person,Photo,Tag};
|
||||
use App\Traits\Files;
|
||||
|
||||
class PhotoImport extends Command
|
||||
{
|
||||
use DispatchesJobs;
|
||||
use Files;
|
||||
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'photo:import
|
||||
{--dir= : Directory to Parse}
|
||||
{--file= : File to Import}
|
||||
{--ignoredupe : Ignore duplicate files}
|
||||
{--deletedupe : Delete duplicate files}
|
||||
{--people= : People to reference in photo}
|
||||
{--tags= : Add tag to photo}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Import photos into the database';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$files = $this->getFiles([
|
||||
'dir'=>$this->option('dir'),
|
||||
'file'=>$this->option('file')
|
||||
],'photo');
|
||||
|
||||
if (! count($files))
|
||||
exit;
|
||||
|
||||
// Show a progress bar
|
||||
$bar = $this->output->createProgressBar(count($files));
|
||||
$bar->setFormat("%current%/%max% [%bar%] %percent:3s%% (%memory%) (%remaining%) ");
|
||||
|
||||
$tags = NULL;
|
||||
$t = $p = array();
|
||||
|
||||
// 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)) {
|
||||
$this->error(sprintf('Tag [%s] dont exist',join('|',$tags)));
|
||||
abort(501);
|
||||
}
|
||||
}
|
||||
|
||||
// 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)));
|
||||
abort(501);
|
||||
}
|
||||
}
|
||||
|
||||
$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++;
|
||||
|
||||
$o = Photo::where('filename',$file)->first();
|
||||
|
||||
// The photo doesnt exist
|
||||
if (is_null($o)) {
|
||||
$o = new Photo;
|
||||
$o->filename = $file;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
$o->save();
|
||||
|
||||
if ($o->wasRecentlyCreated)
|
||||
$this->info(sprintf('%s [%s] stored in DB: %s',$o->objectType(),$file,$o->id));
|
||||
|
||||
// Record our people and tags
|
||||
if ($p)
|
||||
$o->People()->sync($p);
|
||||
if ($t)
|
||||
$o->Tags()->sync($t);
|
||||
|
||||
$this->dispatch((new \App\Jobs\CatalogScan($o))->onQueue('scan'));
|
||||
}
|
||||
|
||||
$bar->finish();
|
||||
|
||||
return $this->info(sprintf('Photos processed: %s',$c));
|
||||
}
|
||||
}
|
@ -40,19 +40,6 @@ abstract class Catalog extends Model
|
||||
return config(static::config.'.dir').'/';
|
||||
}
|
||||
|
||||
/**
|
||||
* Trim a string
|
||||
*
|
||||
* @param string $string
|
||||
* @param int $chrs
|
||||
* @return string
|
||||
* @todo This should go in as a helper
|
||||
*/
|
||||
public static function stringtrim(string $string,int $chrs=6)
|
||||
{
|
||||
return sprintf('%s...%s',substr($string,0,$chrs),substr($string,-1*$chrs));
|
||||
}
|
||||
|
||||
/* RELATIONS */
|
||||
|
||||
/**
|
||||
@ -259,48 +246,6 @@ abstract class Catalog extends Model
|
||||
|
||||
/* METHODS */
|
||||
|
||||
/**
|
||||
* Date the multimedia was created
|
||||
*
|
||||
* @deprecated use $this->created
|
||||
*/
|
||||
public function date_taken(): string
|
||||
{
|
||||
Log::alert(__METHOD__.' deprecated');
|
||||
return $this->created;
|
||||
}
|
||||
|
||||
/** @deprecated use $this->device */
|
||||
public function device(): string
|
||||
{
|
||||
Log::alert(__METHOD__.' deprecated');
|
||||
return $this->device;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the date of the file
|
||||
*/
|
||||
public function file_date(string $type): ?Carbon
|
||||
{
|
||||
if (! $this->isReadable())
|
||||
return NULL;
|
||||
|
||||
$t = NULL;
|
||||
|
||||
switch ($type) {
|
||||
case 'a': $t = fileatime($this->file_name(FALSE));
|
||||
break;
|
||||
|
||||
case 'c': $t = filectime($this->file_name(FALSE));
|
||||
break;
|
||||
|
||||
case 'm': $t = filemtime($this->file_name(FALSE));
|
||||
break;
|
||||
}
|
||||
|
||||
return $t ? Carbon::createfromTimestamp($t) : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the filename.
|
||||
* If short is TRUE, it is the filename that it should be called (and can be compared to $this->filename)
|
||||
@ -353,17 +298,6 @@ abstract class Catalog extends Model
|
||||
return trim(chunk_split(sprintf("%0{$depth}s",$this->id),$sep,'/'),'/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the file size
|
||||
* @deprecated use $this->getFileSizeAttribute())
|
||||
*/
|
||||
public function file_size()
|
||||
{
|
||||
Log::alert(__METHOD__.' deprecated');
|
||||
|
||||
return (! is_readable($this->file_name(FALSE))) ? NULL : filesize($this->file_name(FALSE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return HTML Checkbox for duplicate
|
||||
* @deprecated use a component
|
||||
@ -416,15 +350,6 @@ abstract class Catalog extends Model
|
||||
return $this->HTMLCheckbox('remove',$this->id,$this->remove);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the GPS coordinates
|
||||
* @deprecated use getGPSAttribute()
|
||||
*/
|
||||
public function gps(): string
|
||||
{
|
||||
return $this->getGPSAttribute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an HTML checkbox
|
||||
* @deprecated use a component
|
||||
@ -628,7 +553,7 @@ abstract class Catalog extends Model
|
||||
public function signature($short=FALSE)
|
||||
{
|
||||
return ($short && $this->signature)
|
||||
? static::stringtrim($this->signature)
|
||||
? stringtrim($this->signature)
|
||||
: $this->signature;
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,10 @@
|
||||
"App\\": "app/",
|
||||
"Database\\Factories\\": "database/factories/",
|
||||
"Database\\Seeders\\": "database/seeders/"
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"helpers.php"
|
||||
]
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
|
8
helpers.php
Normal file
8
helpers.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
if (! function_exists('stringtrim')) {
|
||||
function stringtrim(string $string,int $chrs=6)
|
||||
{
|
||||
return sprintf('%s...%s',substr($string,0,$chrs),substr($string,-1*$chrs));
|
||||
}
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
<a href="{{ url('p/view',$id) }}" target="{{ $id }}">
|
||||
<img class="p-3" src="{{ url('p/thumbnail',$id) }}">
|
||||
<img class="p-3 w-100" src="{{ url('p/thumbnail',$id) }}">
|
||||
</a>
|
@ -25,7 +25,7 @@
|
||||
<a class="page-link" href="{{ $x ? url('p/info',$x->id) : '#' }}"><<</a>
|
||||
</li>
|
||||
|
||||
<li class="page-item active" aria-current="page">
|
||||
<li class="page-item active">
|
||||
<span class="page-link">{{ $po->id }}</span>
|
||||
</li>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user