diff --git a/app/Helper/Access.php b/app/Helper/Access.php index 6176020..c26c70b 100644 --- a/app/Helper/Access.php +++ b/app/Helper/Access.php @@ -14,14 +14,12 @@ class Access { throw new \Exception("Invalide Typ for Access Log"); } - $this->addAccessLog(null, null, $image->id, $typ, $file->getSize()); + $this->addAccessLog($image->tenant, null, $image->id, $typ, $file->getSize()); } public function addById(int $image_id, File $file, string $typ) { - if(!in_array($typ, $this->valideTyps)) { - throw new \Exception("Invalide Typ for Access Log"); - } - $this->addAccessLog(null, null, $image_id, $typ, $file->getSize()); + $image = \App\Models\Image::query()->where("id", "=", $image_id)->firstOrFail(); + $this->add($image, $file, $typ); } public function addComplete(\App\Models\Image $image, Gallery $gallery, Tenant $tenant, File $file, string $typ) { diff --git a/database/migrations/2021_01_20_232501_fast_access_log.php b/database/migrations/2021_01_20_232501_fast_access_log.php index e54aed3..fbc479a 100644 --- a/database/migrations/2021_01_20_232501_fast_access_log.php +++ b/database/migrations/2021_01_20_232501_fast_access_log.php @@ -15,12 +15,34 @@ class FastAccessLog extends Migration { Schema::table("access", function(Blueprint $table) { $table->unsignedBigInteger("gallery")->nullable()->change(); - $table->unsignedBigInteger("tenant")->nullable()->change(); + //$table->unsignedBigInteger("tenant")->nullable()->change(); }); Schema::table("traffic", function(Blueprint $table) { $table->unsignedBigInteger("gallery")->nullable()->change(); }); + + Schema::table("images", function (Blueprint $table) { + $table->unsignedBigInteger("tenant"); + }); + + $images = \App\Models\Image::query()->get(); + foreach ($images as $image) { + if(is_null($image->gallery)) { + $image->tenant = 1; + $image->saveOrFail(); + } else { + $gallery = \App\Models\Gallery::query()->where("id", "=", $image->gallery)->firstOrFail(); + $image->tenant = $gallery->tenant; + $image->saveOrFail(); + } + } + + Schema::table("images", function (Blueprint $table) { + $table->foreign('tenant')->references('id')->on('tenants'); + }); + + } /**