From 80a76559e5ee732742f44008c50f946f37c29bc3 Mon Sep 17 00:00:00 2001 From: Deon George Date: Thu, 26 Dec 2019 15:56:31 +1100 Subject: [PATCH] Move video over to software_id --- app/Console/Commands/CatalogMove.php | 11 ++- app/Models/Abstracted/Catalog.php | 9 +- app/Models/Model.php | 2 +- app/Models/Photo.php | 24 +++-- app/Models/Software.php | 2 +- app/Models/Video.php | 20 +++- .../2019_12_26_125230_softwareid_videos.php | 98 +++++++++++++++++++ resources/views/video/view.blade.php | 4 +- 8 files changed, 148 insertions(+), 22 deletions(-) create mode 100644 database/migrations/2019_12_26_125230_softwareid_videos.php diff --git a/app/Console/Commands/CatalogMove.php b/app/Console/Commands/CatalogMove.php index 2f7a614..945057d 100644 --- a/app/Console/Commands/CatalogMove.php +++ b/app/Console/Commands/CatalogMove.php @@ -38,8 +38,15 @@ class CatalogMove extends Command abort(500,sprintf('No class [%s]',$this->argument('type'))); foreach ($class::where('filename','LIKE','%INCOMING%')->get() as $o) { - if ($o->scanned AND ! $o->duplicate AND ! $o->remove AND ($x=$o->moveable()) === TRUE) { - $this->warn(sprintf('Ignoring [%s], it is not readable',$o->file_path())); + // Catch any files that are already there. + if ($o->moveable() === 1) { + $o->duplicate = TRUE; + $o->save(); + continue; + } + + if (! $o->scanned OR $o->duplicate OR $o->remove OR ($x=$o->moveable()) !== TRUE) { + $this->warn(sprintf('Ignoring [%s]...',$o->file_path())); continue; } diff --git a/app/Models/Abstracted/Catalog.php b/app/Models/Abstracted/Catalog.php index df5fbd9..cb35bec 100644 --- a/app/Models/Abstracted/Catalog.php +++ b/app/Models/Abstracted/Catalog.php @@ -5,9 +5,9 @@ namespace App\Models\Abstracted; use Carbon\Carbon; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Schema; -use DB; +use Illuminate\Support\Facades\DB; -use App\Models\{Person,Tag}; +use App\Models\{Person,Software,Tag}; abstract class Catalog extends Model { @@ -18,6 +18,11 @@ abstract class Catalog extends Model return $this->belongsToMany(Person::class); } + public function software() + { + return $this->belongsTo(Software::class); + } + public function tags() { return $this->belongsToMany(Tag::class); diff --git a/app/Models/Model.php b/app/Models/Model.php index 8576d8d..c8cb47d 100644 --- a/app/Models/Model.php +++ b/app/Models/Model.php @@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Model as EloquentModel; class Model extends EloquentModel { - protected $fillable = ['name']; + protected $fillable = ['name','make_id']; public function make() { diff --git a/app/Models/Photo.php b/app/Models/Photo.php index 2dca845..9608427 100644 --- a/app/Models/Photo.php +++ b/app/Models/Photo.php @@ -20,11 +20,6 @@ class Photo extends Abstracted\Catalog 8=>-90, ]; - public function software() - { - return $this->belongsTo(Software::class); - } - public function getIDLinkAttribute() { return $this->HTMLLinkAttribute($this->id,url('p/info').'/'); @@ -184,12 +179,23 @@ class Photo extends Abstracted\Catalog $this->gps_lon = static::latlon(preg_split('/,\s?/',$this->property('exif:GPSLongitude')),$this->property('exif:GPSLongitudeRef')); } - // @todo Now set software_id public function setMakeModel() { - $this->make = $this->property('exif:Make') ? $this->property('exif:Make') : NULL; - $this->model = $this->property('exif:Model') ? $this->property('exif:Model') : NULL; - $this->software = $this->property('exif:Software') ? $this->property('exif:Software') : NULL; + $ma = Make::firstOrCreate([ + 'name'=>$this->property('exif:Make') ?: NULL, + ]); + + $mo = Model::firstOrCreate([ + 'name'=>$this->property('exif:Model') ?: NULL, + 'make_id'=>$ma->id, + ]); + + $so = Software::firstOrCreate([ + 'name'=>$this->property('exif:Software') ?: NULL, + 'model_id'=>$mo->id, + ]); + + $this->software_id = $so->id; } public function setSignature() diff --git a/app/Models/Software.php b/app/Models/Software.php index cd714ca..9cab5f9 100644 --- a/app/Models/Software.php +++ b/app/Models/Software.php @@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Model; class Software extends Model { - protected $fillable = ['name']; + protected $fillable = ['name','model_id']; public function model() { diff --git a/app/Models/Video.php b/app/Models/Video.php index 639ec3f..f247421 100644 --- a/app/Models/Video.php +++ b/app/Models/Video.php @@ -141,12 +141,24 @@ class Video extends Abstracted\Catalog $this->gps_altitude = $this->property('gps_altitude'); } - // @todo Now set software_id public function setMakeModel() { - $this->make = $this->property('make'); - $this->model = $this->property('model'); - $this->software = $this->property('software'); + $ma = Make::firstOrCreate([ + 'name'=>$this->property('make') ?: NULL, + ]); + + $mo = Model::firstOrCreate([ + 'name'=>$this->property('model') ?: NULL, + 'make_id'=>$ma->id, + ]); + + $so = Software::firstOrCreate([ + 'name'=>$this->property('software') ?: NULL, + 'model_id'=>$mo->id, + ]); + + $this->software_id = $so->id; + $this->type = $this->property('type'); $this->length = round($this->property('length'),2); $this->codec = $this->property('codec'); diff --git a/database/migrations/2019_12_26_125230_softwareid_videos.php b/database/migrations/2019_12_26_125230_softwareid_videos.php new file mode 100644 index 0000000..d0b5b7c --- /dev/null +++ b/database/migrations/2019_12_26_125230_softwareid_videos.php @@ -0,0 +1,98 @@ +bigInteger('software_id')->unsigned()->nullable(); + $table->foreign('software_id')->references('id')->on('software'); + }); + + $po = Video::select(['make','model','software']) + ->groupBy(['make','model','software']); + + foreach ($po->get() as $o) { + if (! $o->make AND ! $o->model AND ! $o->software) + continue; + + $ma = NULL; + + dump(['make'=>$o->make,'model'=>$o->model,'software'=>$o->software]); + if ($o->make) + $ma = Make::firstOrCreate(['name'=>$o->make]); + + $mo = Model::firstOrCreate([ + 'name'=>$o->model ?: NULL, + 'make_id'=>$ma->id, + ]); + + $so = Software::firstOrCreate([ + 'name'=>$o->software ?: NULL, + 'model_id'=>$mo->id, + ]); + + foreach (Video::where('make',$o->make) + ->where('model',$o->model) + ->where('software',$o->software) + ->get() as $p) { + + $p->software_id = $so->id; + $p->make = $p->model = $p->software = NULL; + $p->save(); + } + } + + Schema::table('videos', function (Blueprint $table) { + $table->dropColumn('make'); + $table->dropColumn('model'); + $table->dropColumn('software'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + /* + Schema::table('videos', function (Blueprint $table) { + $table->string('make',32)->nullable(); + $table->string('model',128)->nullable(); + $table->string('software')->nullable(); + }); + */ + + foreach (Video::whereNotNULL('software_id')->get() as $p) + { + $s = $p->software()->first(); + $p->software = $s->name; + + if ($s->model) + $p->model = $s->model->name; + + if ($s->model_id AND $s->model->make_id) + $p->make = $s->model->make->name; + + $p->software_id = NULL; + $p->save(); + } + + Schema::table('videos', function (Blueprint $table) { + $table->dropForeign(['software_id']); + $table->dropColumn('software_id'); + }); + } +} diff --git a/resources/views/video/view.blade.php b/resources/views/video/view.blade.php index ed0d2b3..45d1839 100644 --- a/resources/views/video/view.blade.php +++ b/resources/views/video/view.blade.php @@ -57,9 +57,7 @@
Sample Rate
{{ $o->samplerate }}

Date Taken
{{ $o->date_taken() }}
-
Camera
{{ $o->make }}
-
Model
{{ $o->model }}
-
Software
{{ $o->software }}
+
Camera
{{ $o->device() }}
Identifier
{{ $o->identifier }}

Location