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

Add SW 6.6 compatibility #10

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}
},
"require": {
"spatie/image-optimizer": "1.3.2"
"spatie/image-optimizer": "1.7.2"
},
"require-dev": {
"phpro/grumphp-shim": "^1.3",
Expand Down
23 changes: 10 additions & 13 deletions src/Command/MediaOptimizeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,30 @@
namespace RuneLaenen\MediaOptimizer\Command;

use Shopware\Core\Content\Media\MediaEntity;
use Shopware\Core\Content\Media\Pathname\UrlGeneratorInterface;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\Dbal\Common\RepositoryIterator;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Spatie\ImageOptimizer\OptimizerChain;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(
name: 'rl:media:optimize',
description: 'Optimize media files',
)]
class MediaOptimizeCommand extends Command
{
protected static $defaultName = 'rl:media:optimize';

/**
* @var EntityRepositoryInterface
* @var EntityRepository
*/
private $mediaRepository;

Expand All @@ -48,26 +52,19 @@ class MediaOptimizeCommand extends Command
*/
private $sizePost = 0;

/**
* @var UrlGeneratorInterface
*/
private $urlGenerator;

/**
* @var string
*/
private $projectDir;

public function __construct(
EntityRepositoryInterface $mediaRepository,
EntityRepository $mediaRepository,
OptimizerChain $optimizerChain,
UrlGeneratorInterface $urlGenerator,
string $projectDir
) {
parent::__construct();
$this->mediaRepository = $mediaRepository;
$this->optimizerChain = $optimizerChain;
$this->urlGenerator = $urlGenerator;
$this->projectDir = $projectDir;
}

Expand All @@ -83,7 +80,7 @@ public function configure(): void
);
}

public function run(InputInterface $input, OutputInterface $output)
public function run(InputInterface $input, OutputInterface $output): int
{
if ($input->getOption('info')) {
$optimizers = $this->optimizerChain->getOptimizers();
Expand Down Expand Up @@ -157,7 +154,7 @@ private function createCriteria(): Criteria

private function optimize(MediaEntity $media): void
{
$mediaLocation = $this->projectDir . '/public/' . $this->urlGenerator->getRelativeMediaUrl($media);
$mediaLocation = $this->projectDir . '/public/' . $media->getPath();
if (!file_exists($mediaLocation)) {
return;
}
Expand Down
1 change: 0 additions & 1 deletion src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<tag name="console.command" />
<argument type="service" id="media.repository"/>
<argument type="service" id="Spatie\ImageOptimizer\OptimizerChain"/>
<argument type="service" id="Shopware\Core\Content\Media\Pathname\UrlGeneratorInterface"/>
<argument>%kernel.project_dir%</argument>
</service>

Expand Down