From 484bcc236e28cf07e7ac60b142be1bdbee1aaa64 Mon Sep 17 00:00:00 2001 From: Kekskurse Date: Thu, 21 Jan 2021 01:31:02 +0100 Subject: [PATCH] Fast Log add tenant --- app/Helper/Access.php | 8 +++---- .../2021_01_20_232501_fast_access_log.php | 24 ++++++++++++++++++- 2 files changed, 26 insertions(+), 6 deletions(-) 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'); + }); + + } /**