This commit is contained in:
Kekskurse 2021-01-20 00:02:04 +01:00
parent 0653a1474f
commit c7618a8338
4 changed files with 173 additions and 1 deletions

View File

@ -0,0 +1,48 @@
<?php
namespace App\Console\Commands;
use App\Jobs\EXIFAuslesen;
use App\Models\Image;
use Illuminate\Console\Command;
class EXIFRead extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'exit:read';
/**
* 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()
{
$images = Image::query()->where("exifRead", "=", 0)->limit(10)->get();
foreach ($images as $image) {
$this->info("Get Image ".$image->id);
EXIFAuslesen::dispatchSync($image->id);
}
}
}

View File

@ -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
];
/**

88
app/Jobs/EXIFAuslesen.php Normal file
View File

@ -0,0 +1,88 @@
<?php
namespace App\Jobs;
use App\Models\Access;
use App\Models\Gallery;
use App\Models\Image;
use App\Models\Tenant;
use Gumlet\ImageResize;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Storage;
class EXIFAuslesen implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*
* @return void
*/
private $image_id;
public function __construct($id)
{
$this->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();
}
}

View File

@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class ImageDetails extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table("images", function (Blueprint $table) {
$table->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()
{
//
}
}