diff --git a/app/Models/Make.php b/app/Models/Make.php new file mode 100644 index 0000000..82e81a9 --- /dev/null +++ b/app/Models/Make.php @@ -0,0 +1,10 @@ +belongsTo(Make::class); + } +} \ No newline at end of file diff --git a/app/Models/Photo.php b/app/Models/Photo.php index f6aaac0..92aa128 100644 --- a/app/Models/Photo.php +++ b/app/Models/Photo.php @@ -19,6 +19,11 @@ class Photo extends Abstracted\Catalog 8=>-90, ]; + public function software() + { + return $this->belongsTo(Software::class); + } + /** * Date the photo was taken */ @@ -38,7 +43,7 @@ class Photo extends Abstracted\Catalog if ($new) $file = sprintf('%s.%s',((is_null($this->date_created) OR ! $this->date_created) ? sprintf('UNKNOWN/%07s',$this->file_path_id()) - : sprintf('%s_%03s',date('Y/m/d-His',$this->date_created),$this->subsectime). + : sprintf('%s_%03s',$this->date_created->format('Y/m/d-His'),$this->subsectime). ($this->subsectime ? '' : sprintf('-%05s',$this->id))),$this->type()); return (($short OR preg_match('/^\//',$file)) ? '' : config('photo.dir').DIRECTORY_SEPARATOR).$file; diff --git a/app/Models/Software.php b/app/Models/Software.php new file mode 100644 index 0000000..cd714ca --- /dev/null +++ b/app/Models/Software.php @@ -0,0 +1,15 @@ +belongsTo(\App\Models\Model::class); + } +} \ No newline at end of file diff --git a/database/migrations/2019_11_22_203904_revert_index_photo.php b/database/migrations/2019_11_22_203904_revert_index_photo.php new file mode 100644 index 0000000..e2429e6 --- /dev/null +++ b/database/migrations/2019_11_22_203904_revert_index_photo.php @@ -0,0 +1,54 @@ +dropIndex(['signature']); + $table->dropIndex(['filename']); + $table->dropIndex(['remove']); + $table->dropIndex(['duplicate']); + $table->dropIndex(['date_created','subsectime','model','make']); + }); + Schema::table('videos', function (Blueprint $table) { + $table->dropIndex(['signature']); + $table->dropIndex(['filename']); + $table->dropIndex(['remove']); + $table->dropIndex(['duplicate']); + $table->dropIndex(['date_created','model','make']); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('photo', function (Blueprint $table) { + $table->index(['signature']); + $table->index(['filename']); + $table->index(['remove']); + $table->index(['duplicate']); + $table->index(['date_created','subsectime','model','make']); + }); + Schema::table('videos', function (Blueprint $table) { + $table->index(['signature']); + $table->index(['filename']); + $table->index(['remove']); + $table->index(['duplicate']); + $table->index(['date_created','model','make']); + }); + } +} diff --git a/database/migrations/2019_11_23_125316_create_makemodel_tables.php b/database/migrations/2019_11_23_125316_create_makemodel_tables.php new file mode 100644 index 0000000..3580d42 --- /dev/null +++ b/database/migrations/2019_11_23_125316_create_makemodel_tables.php @@ -0,0 +1,127 @@ +bigIncrements('id'); + $table->timestamps(); + $table->string('name')->unique(); + }); + + Schema::create('models', function (Blueprint $table) { + $table->bigIncrements('id'); + $table->timestamps(); + $table->string('name')->nullable(); + + $table->bigInteger('make_id')->unsigned()->nullable(); + $table->foreign('make_id')->references('id')->on('makes'); + $table->unique(['name','make_id']); + }); + + Schema::create('software', function (Blueprint $table) { + $table->bigIncrements('id'); + $table->timestamps(); + $table->string('name')->nullable(); + + $table->bigInteger('model_id')->unsigned()->nullable(); + $table->foreign('model_id')->references('id')->on('models'); + $table->unique(['name','model_id']); + }); + + Schema::table('photo', function (Blueprint $table) { + $table->bigInteger('software_id')->unsigned()->nullable(); + $table->foreign('software_id')->references('id')->on('software'); + }); + + $po = Photo::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::firstOrNew(['name'=>$o->model]); + if ($ma) + $mo->make_id = $ma->id; + $mo->save(); + + $so = Software::firstOrNew(['name'=>$o->software]); + if ($so) + $so->model_id = $mo->id; + $so->save(); + + foreach (Photo::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('photo', function (Blueprint $table) { + $table->dropColumn('make'); + $table->dropColumn('model'); + $table->dropColumn('software'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('photo', function (Blueprint $table) { + $table->string('make',32)->nullable(); + $table->string('model',128)->nullable(); + $table->string('software')->nullable(); + }); + + foreach (Photo::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->make) + $p->make = $s->model->make->name; + + $p->software_id = NULL; + $p->save(); + } + + Schema::table('photo', function (Blueprint $table) { + $table->dropForeign(['software_id']); + $table->dropColumn('software_id'); + }); + + Schema::dropIfExists('software'); + Schema::dropIfExists('models'); + Schema::dropIfExists('makes'); + } +}