This commit is contained in:
Kekskurse 2021-02-09 22:11:32 +01:00
parent 3ae8afd172
commit 7b3ab02c85
5 changed files with 159 additions and 3 deletions

View file

@ -0,0 +1,50 @@
<?php
namespace App\Console\Commands;
use App\Models\Image;
use Illuminate\Console\Command;
class ImageToServer extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'server:set-image';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Add to all Image with no server a new one';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$server = \App\Models\Server::query()->get();
#var_dump($server);exit();
$images = Image::query()->whereNull("servername")->get();
foreach($images as $image) {
$servername = $server[0]->servername;
$image->servername = $servername;
$image->saveOrFail();
}
}
}

View file

@ -0,0 +1,86 @@
<?php
namespace App\Console\Commands;
use App\Helper\Image;
use App\Helper\ImagePreparation;
use App\Http\Controllers\PublicController;
use App\Models\Storage;
use App\Models\Theme;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class ServerUpdateCache extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'server:update-cache';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle(Image $image)
{
$themeList = [];
$themesModel = Theme::query()->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);
}
}
}
}

View file

@ -6,7 +6,9 @@ use App\Console\Commands\CalculateSpace;
use App\Console\Commands\CalculateTraffic; use App\Console\Commands\CalculateTraffic;
use App\Console\Commands\EXIFRead; use App\Console\Commands\EXIFRead;
use App\Console\Commands\ImageCacheAll; use App\Console\Commands\ImageCacheAll;
use App\Console\Commands\ImageToServer;
use App\Console\Commands\Server; use App\Console\Commands\Server;
use App\Console\Commands\ServerUpdateCache;
use App\Console\Commands\ThemesScann; use App\Console\Commands\ThemesScann;
use App\Console\Commands\ThemesScannTenant; use App\Console\Commands\ThemesScannTenant;
use App\Console\Commands\UserAdmin; use App\Console\Commands\UserAdmin;
@ -27,7 +29,9 @@ class Kernel extends ConsoleKernel
EXIFRead::class, EXIFRead::class,
UserAdmin::class, UserAdmin::class,
ThemesScann::class, ThemesScann::class,
Server::class Server::class,
ImageToServer::class,
ServerUpdateCache::class
]; ];
/** /**

View file

@ -1,6 +1,7 @@
<?php <?php
namespace App\Helper; namespace App\Helper;
use App\Entity\File; use App\Entity\File;
use App\Log;
use Intervention\Image\ImageManager; use Intervention\Image\ImageManager;
class ImagePreparation { class ImagePreparation {
@ -39,7 +40,12 @@ class ImagePreparation {
$newHeight = $size; $newHeight = $size;
$newWidth = $img->getWidth() * ($newHeight / $img->getHeight()); $newWidth = $img->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; return $img;
} }

View file

@ -16,10 +16,16 @@ class Server extends Migration
Schema::create("servers", function (Blueprint $table) { Schema::create("servers", function (Blueprint $table) {
$table->id(); $table->id();
$table->timestamps(); $table->timestamps();
$table->string("servername"); $table->string("servername")->unique();
$table->timestamp("last_seen")->nullable(); $table->timestamp("last_seen")->nullable();
$table->bigInteger("storage")->comment("In Byte, for cache"); $table->bigInteger("storage")->comment("In Byte, for cache");
$table->bigInteger("userd")->comment("Userd Space in Byte")->nullable(); $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() public function down()
{ {
Schema::dropIfExists("servers"); Schema::dropIfExists("servers");
/*Schema::table("images", function (Blueprint $table) {
$table->dropConstrainedForeignId("servername");
$table->dropColumn("servername");
});*/
} }
} }