This commit is contained in:
Kekskurse 2021-01-17 03:20:21 +01:00
parent 92439a4cdb
commit b799ee6c74
3 changed files with 55 additions and 6 deletions

View file

@ -0,0 +1,51 @@
<?php
namespace App\Console\Commands;
use App\Http\Controllers\PublicController;
use App\Jobs\ResizeImage;
use App\Models\Image;
use Illuminate\Console\Command;
class ImageCacheAll extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'imagecache:get-all';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Cache All Images in All Sizes on this Server (be carefull, take space)';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$images = Image::query()->get();
foreach ($images as $image) {
foreach (PublicController::$size as $size) {
$this->info("Cache ".$image->id." as ".$size);
ResizeImage::dispatchSync($image->id, $size);
}
}
}
}

View file

@ -4,6 +4,7 @@ namespace App\Console;
use App\Console\Commands\CalculateSpace; use App\Console\Commands\CalculateSpace;
use App\Console\Commands\CalculateTraffic; use App\Console\Commands\CalculateTraffic;
use App\Console\Commands\ImageCacheAll;
use Illuminate\Console\Scheduling\Schedule; use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel; use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
@ -16,7 +17,8 @@ class Kernel extends ConsoleKernel
*/ */
protected $commands = [ protected $commands = [
CalculateSpace::class, CalculateSpace::class,
CalculateTraffic::class CalculateTraffic::class,
ImageCacheAll::class
]; ];
/** /**

View file

@ -21,12 +21,8 @@ use phpDocumentor\Reflection\Types\Integer;
class PublicController extends BaseController class PublicController extends BaseController
{ {
const SIZE_SMALL = 300; public static $size = ["pixel" => 100, "small" => 300, "medium" => 600, "big" => 1200];
const SIZE_MEDIUM = 600;
const SIZE_BIG = 1200;
const SIZE_PIXEL = 100;
private $size = ["pixel" => 100, "small" => 300, "medium" => 600, "big" => 1200];
use AuthorizesRequests, DispatchesJobs, ValidatesRequests; use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
public function listGalleriesView($name) { public function listGalleriesView($name) {