diff --git a/app/Console/Commands/ImageToServer.php b/app/Console/Commands/ImageToServer.php new file mode 100644 index 0000000..702fcff --- /dev/null +++ b/app/Console/Commands/ImageToServer.php @@ -0,0 +1,50 @@ +get(); + #var_dump($server);exit(); + $images = Image::query()->whereNull("servername")->get(); + foreach($images as $image) { + $servername = $server[0]->servername; + $image->servername = $servername; + $image->saveOrFail(); + } + } +} diff --git a/app/Console/Commands/ServerUpdateCache.php b/app/Console/Commands/ServerUpdateCache.php new file mode 100644 index 0000000..60c5aa3 --- /dev/null +++ b/app/Console/Commands/ServerUpdateCache.php @@ -0,0 +1,86 @@ +where("typ", "=", "gallery")->get(); + foreach ($themesModel as $tm) { + $themeList[$tm->name] = $tm; + } + + $sql = 'SELECT images.id, images.path, images.driver, tenants.template, tenants.gallery_default_theme FROM images LEFT JOIN tenants ON tenants.id = images.tenant WHERE servername = "'.env("APP_SERVER").'";'; + $res = DB::select($sql); + foreach ($res as $re) { + $this->info("Image: ".$re->id); + $theme = $themeList[$re->template]; + if(is_null($theme)) { + $this->info("Error Theme not found: ".$re->template); + exit(); + continue; + } + if($theme->img_pixel) { + $image->getImageById($re->id, PublicController::$size["pixel"]); + } + if($theme->img_small) { + $image->getImageById($re->id, PublicController::$size["small"]); + } + if($theme->img_medium) { + $image->getImageById($re->id, PublicController::$size["medium"]); + } + if($theme->img_big) { + $image->getImageById($re->id, PublicController::$size["big"]); + } + } + + $list = \Illuminate\Support\Facades\Storage::disk("cache")->allFiles(""); + foreach($list as $l) { + if(preg_match("@^\d*_orginal_@", $l)) { + \Illuminate\Support\Facades\Storage::disk("cache")->delete($l); + //$this->info("To Delete: ".$l); + } + } + + + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 10a0953..4400331 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -6,7 +6,9 @@ use App\Console\Commands\CalculateSpace; use App\Console\Commands\CalculateTraffic; use App\Console\Commands\EXIFRead; use App\Console\Commands\ImageCacheAll; +use App\Console\Commands\ImageToServer; use App\Console\Commands\Server; +use App\Console\Commands\ServerUpdateCache; use App\Console\Commands\ThemesScann; use App\Console\Commands\ThemesScannTenant; use App\Console\Commands\UserAdmin; @@ -27,7 +29,9 @@ class Kernel extends ConsoleKernel EXIFRead::class, UserAdmin::class, ThemesScann::class, - Server::class + Server::class, + ImageToServer::class, + ServerUpdateCache::class ]; /** diff --git a/app/Helper/ImagePreparation.php b/app/Helper/ImagePreparation.php index 9717435..83d596b 100644 --- a/app/Helper/ImagePreparation.php +++ b/app/Helper/ImagePreparation.php @@ -1,6 +1,7 @@ getWidth() * ($newHeight / $img->getHeight()); } - $img->resize($newWidth, $newHeight); + if($newHeight >= $img->getHeight() || $newWidth >= $img->getWidth()) { + \Illuminate\Support\Facades\Log::debug("No resize because orginal is smaller"); + } else { + $img->resize($newWidth, $newHeight); + } + return $img; } diff --git a/database/migrations/2021_02_09_172928_server.php b/database/migrations/2021_02_09_172928_server.php index 8a65b51..5aa606e 100644 --- a/database/migrations/2021_02_09_172928_server.php +++ b/database/migrations/2021_02_09_172928_server.php @@ -16,10 +16,16 @@ class Server extends Migration Schema::create("servers", function (Blueprint $table) { $table->id(); $table->timestamps(); - $table->string("servername"); + $table->string("servername")->unique(); $table->timestamp("last_seen")->nullable(); $table->bigInteger("storage")->comment("In Byte, for cache"); $table->bigInteger("userd")->comment("Userd Space in Byte")->nullable(); + + }); + + Schema::table("images", function (Blueprint $table) { + $table->string("servername")->nullable(); + $table->foreign('servername')->references('servername')->on('servers'); }); } @@ -31,5 +37,9 @@ class Server extends Migration public function down() { Schema::dropIfExists("servers"); + /*Schema::table("images", function (Blueprint $table) { + $table->dropConstrainedForeignId("servername"); + $table->dropColumn("servername"); + });*/ } }