Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean #92

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 58 additions & 12 deletions src/Command/ReprocessImageOptimalCropCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@

use AnzuSystems\CoreDamBundle\Command\Traits\OutputUtilTrait;
use AnzuSystems\CoreDamBundle\Domain\Image\ImageFacade;
use AnzuSystems\CoreDamBundle\Entity\ImageFile;
use AnzuSystems\CoreDamBundle\Repository\ImageFileRepository;
use Exception;
use Generator;
use SplFileObject;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(
Expand All @@ -21,7 +25,9 @@
final class ReprocessImageOptimalCropCommand extends Command
{
use OutputUtilTrait;
private const string IMAGE_FILE_ARG = 'image';
private const string IMAGE_FILE_OPT = 'image';

private const string IMAGE_ID_FILE_PATH = 'file';
private const int MAX_ASSETS_PER_JOB = 20;

public function __construct(
Expand All @@ -34,9 +40,13 @@ public function __construct(
public function configure(): void
{
$this
->addArgument(
name: self::IMAGE_FILE_ARG,
mode: InputArgument::REQUIRED,
->addOption(
name: self::IMAGE_FILE_OPT,
mode: InputOption::VALUE_REQUIRED,
)
->addOption(
name: self::IMAGE_ID_FILE_PATH,
mode: InputOption::VALUE_REQUIRED,
)
;
}
Expand All @@ -46,17 +56,53 @@ public function configure(): void
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$imageId = $input->getArgument(self::IMAGE_FILE_ARG);
$image = $this->imageFileRepository->find($imageId);
$progressBar = new ProgressBar($output);
$progressBar->start();
foreach ($this->getImages($input) as $image) {
$this->imageFacade->reprocessOptimalCrop($image);
}

$progressBar->finish();
$output->writeln('');

return Command::SUCCESS;
}

/**
* @return Generator<ImageFile>
*/
private function getImages(InputInterface $input): Generator
{
$imageId = $input->getOption(self::IMAGE_FILE_OPT);

if (null === $image) {
$output->writeln("<error>Image not found: ({$imageId})</error>");
if (is_string($imageId)) {
$image = $this->imageFileRepository->find($imageId);

return Command::FAILURE;
if ($image instanceof ImageFile) {
yield $image;
}
}

$this->imageFacade->reprocessOptimalCrop($image);
$filePath = $input->getOption(self::IMAGE_ID_FILE_PATH);
if (null === $filePath || false === file_exists($filePath)) {
return;
}

return Command::SUCCESS;
$csv = new SplFileObject($filePath);
$csv->setFlags(SplFileObject::SKIP_EMPTY);

while (false === $csv->eof()) {
$row = $csv->fgetcsv();

if (false === is_array($row) || false === isset($row[0])) {
continue;
}

$image = $this->imageFileRepository->find($imageId);

if ($image instanceof ImageFile) {
yield $image;
}
}
}
}
5 changes: 0 additions & 5 deletions src/Domain/AssetFile/FileStash.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ class FileStash
*/
private array $fileDeleteStash = [];

/**
* @var array<string, array<int, string>>
*/
private array $backup = [];

public function __construct(
private readonly FileSystemProvider $fileSystemProvider,
) {
Expand Down
1 change: 0 additions & 1 deletion src/Domain/Image/Crop/CropProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public function applyCrop(ImageFile $image, ImageCropDto $imageCrop): string
optimalResize: $optimalResize,
imageCrop: $imageCrop
);
// dd($optimalResize->getFilePath());

$fileStream = $this->fileSystemProvider
->getFilesystemByStorable($image)
Expand Down
Loading