Move video over to software_id

This commit is contained in:
Deon George 2019-12-26 15:56:31 +11:00
parent 99ca07201e
commit 80a76559e5
8 changed files with 148 additions and 22 deletions

View File

@ -38,8 +38,15 @@ class CatalogMove extends Command
abort(500,sprintf('No class [%s]',$this->argument('type'))); abort(500,sprintf('No class [%s]',$this->argument('type')));
foreach ($class::where('filename','LIKE','%INCOMING%')->get() as $o) { foreach ($class::where('filename','LIKE','%INCOMING%')->get() as $o) {
if ($o->scanned AND ! $o->duplicate AND ! $o->remove AND ($x=$o->moveable()) === TRUE) { // Catch any files that are already there.
$this->warn(sprintf('Ignoring [%s], it is not readable',$o->file_path())); 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; continue;
} }

View File

@ -5,9 +5,9 @@ namespace App\Models\Abstracted;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Schema; 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 abstract class Catalog extends Model
{ {
@ -18,6 +18,11 @@ abstract class Catalog extends Model
return $this->belongsToMany(Person::class); return $this->belongsToMany(Person::class);
} }
public function software()
{
return $this->belongsTo(Software::class);
}
public function tags() public function tags()
{ {
return $this->belongsToMany(Tag::class); return $this->belongsToMany(Tag::class);

View File

@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Model as EloquentModel;
class Model extends EloquentModel class Model extends EloquentModel
{ {
protected $fillable = ['name']; protected $fillable = ['name','make_id'];
public function make() public function make()
{ {

View File

@ -20,11 +20,6 @@ class Photo extends Abstracted\Catalog
8=>-90, 8=>-90,
]; ];
public function software()
{
return $this->belongsTo(Software::class);
}
public function getIDLinkAttribute() public function getIDLinkAttribute()
{ {
return $this->HTMLLinkAttribute($this->id,url('p/info').'/'); 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')); $this->gps_lon = static::latlon(preg_split('/,\s?/',$this->property('exif:GPSLongitude')),$this->property('exif:GPSLongitudeRef'));
} }
// @todo Now set software_id
public function setMakeModel() public function setMakeModel()
{ {
$this->make = $this->property('exif:Make') ? $this->property('exif:Make') : NULL; $ma = Make::firstOrCreate([
$this->model = $this->property('exif:Model') ? $this->property('exif:Model') : NULL; 'name'=>$this->property('exif:Make') ?: NULL,
$this->software = $this->property('exif:Software') ? $this->property('exif:Software') : 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() public function setSignature()

View File

@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Model;
class Software extends Model class Software extends Model
{ {
protected $fillable = ['name']; protected $fillable = ['name','model_id'];
public function model() public function model()
{ {

View File

@ -141,12 +141,24 @@ class Video extends Abstracted\Catalog
$this->gps_altitude = $this->property('gps_altitude'); $this->gps_altitude = $this->property('gps_altitude');
} }
// @todo Now set software_id
public function setMakeModel() public function setMakeModel()
{ {
$this->make = $this->property('make'); $ma = Make::firstOrCreate([
$this->model = $this->property('model'); 'name'=>$this->property('make') ?: NULL,
$this->software = $this->property('software'); ]);
$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->type = $this->property('type');
$this->length = round($this->property('length'),2); $this->length = round($this->property('length'),2);
$this->codec = $this->property('codec'); $this->codec = $this->property('codec');

View File

@ -0,0 +1,98 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use App\Models\{Software,Video,Make,Model};
class SoftwareidVideos extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('videos', function (Blueprint $table) {
$table->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');
});
}
}

View File

@ -57,9 +57,7 @@
<dt>Sample Rate</dt><dd>{{ $o->samplerate }}<dd> <dt>Sample Rate</dt><dd>{{ $o->samplerate }}<dd>
<hr> <hr>
<dt>Date Taken</dt><dd>{{ $o->date_taken() }}<dd> <dt>Date Taken</dt><dd>{{ $o->date_taken() }}<dd>
<dt>Camera</dt><dd>{{ $o->make }}<dd> <dt>Camera</dt><dd>{{ $o->device() }}<dd>
<dt>Model</dt><dd>{{ $o->model }}<dd>
<dt>Software</dt><dd>{{ $o->software }}<dd>
<dt>Identifier</dt><dd>{{ $o->identifier }}<dd> <dt>Identifier</dt><dd>{{ $o->identifier }}<dd>
<hr> <hr>
<dt>Location</dt> <dt>Location</dt>