Files
lucent-laravel/src/Commands/RebuildThumbnails.php
T
2025-07-03 15:28:52 +03:00

59 lines
1.5 KiB
PHP

<?php
namespace Lucent\Commands;
use DirectoryIterator;
use Exception;
use Illuminate\Console\Command;
use Intervention\Image\ImageManager;
use Lucent\Channel\ChannelService;
use Lucent\File\FileService;
use Lucent\Query\Query;
use Lucent\Schema\FilesSchema;
use Lucent\Schema\Schema;
use Lucent\Schema\Type;
class RebuildThumbnails extends Command
{
protected $signature = 'lucent:rebuild:thumbnails';
protected $description = 'Rebuilds thumbnails for path';
public function __construct(
public Query $query,
public FileService $fileService,
)
{
parent::__construct();
}
public function handle(ChannelService $channelService): int
{
$channelService->channel->schemas
->filter(fn(Schema $schema) => get_class($schema) === FilesSchema::class)
->map([$this, 'rebuildThumbnails']);
return 0;
}
public function rebuildThumbnails(FilesSchema $schema): void
{
$this->info("Rebuilding thumbnails for ". $schema->name);
$records = $this->query->limit(0)->filter(["schema" => $schema->name])->run()->records;
$disk = $this->fileService->loadDisk($schema->disk);
foreach ($records as $record) {
try{
$this->fileService->createTemplates($disk, $record->_file->path);
} catch (Exception $e) {
echo "File ". $record->_file->originalName . " could not be rebuilt \n" ;
}
}
}
}