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