From c7618a8338bd332183eece8ceae7c776b915740a Mon Sep 17 00:00:00 2001 From: Kekskurse Date: Wed, 20 Jan 2021 00:02:04 +0100 Subject: [PATCH] Stuff --- app/Console/Commands/EXIFRead.php | 48 ++++++++++ app/Console/Kernel.php | 4 +- app/Jobs/EXIFAuslesen.php | 88 +++++++++++++++++++ .../2021_01_19_224339_image_details.php | 34 +++++++ 4 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 app/Console/Commands/EXIFRead.php create mode 100644 app/Jobs/EXIFAuslesen.php create mode 100644 database/migrations/2021_01_19_224339_image_details.php diff --git a/app/Console/Commands/EXIFRead.php b/app/Console/Commands/EXIFRead.php new file mode 100644 index 0000000..c4f2d32 --- /dev/null +++ b/app/Console/Commands/EXIFRead.php @@ -0,0 +1,48 @@ +where("exifRead", "=", 0)->limit(10)->get(); + foreach ($images as $image) { + $this->info("Get Image ".$image->id); + EXIFAuslesen::dispatchSync($image->id); + } + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index f878d49..0c26ef6 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -4,6 +4,7 @@ namespace App\Console; use App\Console\Commands\CalculateSpace; use App\Console\Commands\CalculateTraffic; +use App\Console\Commands\EXIFRead; use App\Console\Commands\ImageCacheAll; use Illuminate\Console\Scheduling\Schedule; use Illuminate\Foundation\Console\Kernel as ConsoleKernel; @@ -18,7 +19,8 @@ class Kernel extends ConsoleKernel protected $commands = [ CalculateSpace::class, CalculateTraffic::class, - ImageCacheAll::class + ImageCacheAll::class, + EXIFRead::class ]; /** diff --git a/app/Jobs/EXIFAuslesen.php b/app/Jobs/EXIFAuslesen.php new file mode 100644 index 0000000..1ba2f1a --- /dev/null +++ b/app/Jobs/EXIFAuslesen.php @@ -0,0 +1,88 @@ +image_id = $id; + } + + /** + * Execute the job. + * + * @return void + */ + public function handle() + { + $image = Image::query()->where("id", "=", $this->image_id)->firstOrFail(); + $gallery = Gallery::query()->where("id", "=", $image->gallery)->firstOrFail(); + $tenant = Tenant::query()->where("id", "=", $gallery->tenant)->firstOrFail(); + $cacheName = "cache/".$tenant->url."_".$gallery->url."_".$image->id; + $tmpfname = tempnam("/tmp", "FOO"); + + //Check if orginal size is cached on the current system + if (Storage::disk('cache')->exists($cacheName."_orginal")) { + $file = Storage::disk("cache")->get($cacheName."_orginal"); + file_put_contents($tmpfname, $file); + } else { + $this->addAccessLog($tenant->id, $gallery->id, $image->id, "Access", $image->size); + $file = Storage::disk($image->driver)->get($image->path); + if(env("CACHE_ORGINAL")) + { + Storage::disk("cache")->put($cacheName."_orginal", $file); + } + file_put_contents($tmpfname, $file); + } + + $exit = exif_read_data($tmpfname); + + $image->exifRead = true; + if(array_key_exists("DateTimeOriginal", $exit)) + { + $image->DateTimeOriginal = $exit["DateTimeOriginal"]; + } + + if(empty($image->name)) { + $image->name = $image->filename; + } + $image->saveOrFail(); + unlink($tmpfname); + } + + private function addAccessLog(int $tenant, int $gallery, int $image, string $typ, int $size) { + $access = new Access(); + $access->year = date("Y"); + $access->month = date("m"); + $access->day = date("d"); + $access->hour = date("H"); + $access->image = $image; + $access->gallery = $gallery; + $access->tenant = $tenant; + $access->typ = $typ; + $access->size = $size; + $access->saveOrFail(); + } +} diff --git a/database/migrations/2021_01_19_224339_image_details.php b/database/migrations/2021_01_19_224339_image_details.php new file mode 100644 index 0000000..d65203a --- /dev/null +++ b/database/migrations/2021_01_19_224339_image_details.php @@ -0,0 +1,34 @@ +boolean("exifRead")->default(false); + $table->dateTime("DateTimeOriginal")->nullable()->default(null); + $table->integer("rating")->default(100); + $table->string("name")->nullable()->default(null); + $table->string("description")->nullable()->default(null); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +}