From b1161c4248ec14b82cbfaba82be58bb03b0d5c25 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Sat, 25 Jun 2022 11:18:00 +0200 Subject: [PATCH] Fix deprecations for commands while maintian lazyness (#2314) --- composer.json | 4 ++-- src/Command/AddMassMediaCommand.php | 4 ++++ src/Command/AddMediaCommand.php | 4 ++++ src/Command/CleanMediaCommand.php | 4 ++++ src/Command/FixMediaContextCommand.php | 4 ++++ src/Command/RefreshMetadataCommand.php | 4 ++++ src/Command/RemoveThumbsCommand.php | 4 ++++ src/Command/SyncThumbsCommand.php | 4 ++++ src/Command/UpdateCdnStatusCommand.php | 4 ++++ tests/App/AppKernel.php | 8 ++++++++ tests/App/Resources/config/config.yaml | 1 + tests/App/Resources/config/config_sonata_block_v4.yaml | 2 ++ 12 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 tests/App/Resources/config/config_sonata_block_v4.yaml diff --git a/composer.json b/composer.json index cd0781e42..429d842d7 100644 --- a/composer.json +++ b/composer.json @@ -84,7 +84,7 @@ "psalm/plugin-phpunit": "^0.16", "psalm/plugin-symfony": "^3.0", "sonata-project/admin-bundle": "^4.9", - "sonata-project/block-bundle": "^4.0", + "sonata-project/block-bundle": "^4.11", "sonata-project/classification-bundle": "^4.0", "sonata-project/doctrine-orm-admin-bundle": "^4.0", "symfony/browser-kit": "^4.4 || ^5.4 || ^6.0", @@ -100,7 +100,7 @@ "knplabs/knp-menu-bundle": "<3.0", "liip/imagine-bundle": "<2.0", "sonata-project/admin-bundle": "<4.9", - "sonata-project/block-bundle": "<4.0", + "sonata-project/block-bundle": "<4.11", "sonata-project/classification-bundle": "<4.0", "sonata-project/doctrine-orm-admin-bundle": "<4.0" }, diff --git a/src/Command/AddMassMediaCommand.php b/src/Command/AddMassMediaCommand.php index 9059149f2..b721eb594 100644 --- a/src/Command/AddMassMediaCommand.php +++ b/src/Command/AddMassMediaCommand.php @@ -15,13 +15,16 @@ use Sonata\Doctrine\Model\ClearableManagerInterface; use Sonata\MediaBundle\Model\MediaManagerInterface; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +#[AsCommand(name: 'sonata:media:add-multiple', description: 'Add medias in mass into the database')] final class AddMassMediaCommand extends Command { + // TODO: Remove static properties when support for Symfony < 6.0 is dropped. protected static $defaultName = 'sonata:media:add-multiple'; protected static $defaultDescription = 'Add medias in mass into the database'; @@ -47,6 +50,7 @@ protected function configure(): void \assert(null !== static::$defaultDescription); $this + // TODO: Remove setDescription when support for Symfony < 5.4 is dropped. ->setDescription(static::$defaultDescription) ->addOption('file', null, InputOption::VALUE_REQUIRED, 'The file to parse') ->addOption('delimiter', null, InputOption::VALUE_REQUIRED, 'Set the field delimiter (one character only)', ',') diff --git a/src/Command/AddMediaCommand.php b/src/Command/AddMediaCommand.php index 5c19b4569..9a6cf82b9 100644 --- a/src/Command/AddMediaCommand.php +++ b/src/Command/AddMediaCommand.php @@ -14,14 +14,17 @@ namespace Sonata\MediaBundle\Command; use Sonata\MediaBundle\Model\MediaManagerInterface; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +#[AsCommand(name: 'sonata:media:add', description: 'Add a media into the database')] final class AddMediaCommand extends Command { + // TODO: Remove static properties when support for Symfony < 6.0 is dropped. protected static $defaultName = 'sonata:media:add'; protected static $defaultDescription = 'Add a media into the database'; @@ -42,6 +45,7 @@ protected function configure(): void \assert(null !== static::$defaultDescription); $this + // TODO: Remove setDescription when support for Symfony < 5.4 is dropped. ->setDescription(static::$defaultDescription) ->addArgument('providerName', InputArgument::REQUIRED, 'The provider') ->addArgument('context', InputArgument::REQUIRED, 'The context') diff --git a/src/Command/CleanMediaCommand.php b/src/Command/CleanMediaCommand.php index 0163e759a..4ca164509 100755 --- a/src/Command/CleanMediaCommand.php +++ b/src/Command/CleanMediaCommand.php @@ -17,6 +17,7 @@ use Sonata\MediaBundle\Model\MediaManagerInterface; use Sonata\MediaBundle\Provider\FileProvider; use Sonata\MediaBundle\Provider\Pool; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -25,8 +26,10 @@ use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Finder\Finder; +#[AsCommand(name: 'sonata:media:clean-uploads', description: 'Find orphaned files in media upload directory')] final class CleanMediaCommand extends Command { + // TODO: Remove static properties when support for Symfony < 6.0 is dropped. protected static $defaultName = 'sonata:media:clean-uploads'; protected static $defaultDescription = 'Find orphaned files in media upload directory'; @@ -58,6 +61,7 @@ protected function configure(): void \assert(null !== static::$defaultDescription); $this + // TODO: Remove setDescription when support for Symfony < 5.4 is dropped. ->setDescription(static::$defaultDescription) ->addOption('dry-run', null, InputOption::VALUE_NONE, 'Execute the cleanup as a dry run. This doesn\'t remove any files'); } diff --git a/src/Command/FixMediaContextCommand.php b/src/Command/FixMediaContextCommand.php index e299db6f9..b364bd241 100755 --- a/src/Command/FixMediaContextCommand.php +++ b/src/Command/FixMediaContextCommand.php @@ -16,12 +16,15 @@ use Sonata\ClassificationBundle\Model\CategoryManagerInterface; use Sonata\ClassificationBundle\Model\ContextManagerInterface; use Sonata\MediaBundle\Provider\Pool; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +#[AsCommand(name: 'sonata:media:fix-media-context', description: 'Generate the default category for each media context')] final class FixMediaContextCommand extends Command { + // TODO: Remove static properties when support for Symfony < 6.0 is dropped. protected static $defaultName = 'sonata:media:fix-media-context'; protected static $defaultDescription = 'Generate the default category for each media context'; @@ -47,6 +50,7 @@ protected function configure(): void { \assert(null !== static::$defaultDescription); + // TODO: Remove setDescription when support for Symfony < 5.4 is dropped. $this->setDescription(static::$defaultDescription); } diff --git a/src/Command/RefreshMetadataCommand.php b/src/Command/RefreshMetadataCommand.php index a543f02a4..b0a684276 100644 --- a/src/Command/RefreshMetadataCommand.php +++ b/src/Command/RefreshMetadataCommand.php @@ -16,6 +16,7 @@ use Sonata\MediaBundle\Model\MediaManagerInterface; use Sonata\MediaBundle\Provider\MediaProviderInterface; use Sonata\MediaBundle\Provider\Pool; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Input\InputArgument; @@ -28,8 +29,10 @@ * * Useful if you have existing media content and added new formats. */ +#[AsCommand(name: 'sonata:media:refresh-metadata', description: 'Refresh meta information')] final class RefreshMetadataCommand extends Command { + // TODO: Remove static properties when support for Symfony < 6.0 is dropped. protected static $defaultName = 'sonata:media:refresh-metadata'; protected static $defaultDescription = 'Refresh meta information'; @@ -55,6 +58,7 @@ protected function configure(): void \assert(null !== static::$defaultDescription); $this + // TODO: Remove setDescription when support for Symfony < 5.4 is dropped. ->setDescription(static::$defaultDescription) ->addArgument('providerName', InputArgument::OPTIONAL, 'The provider') ->addArgument('context', InputArgument::OPTIONAL, 'The context'); diff --git a/src/Command/RemoveThumbsCommand.php b/src/Command/RemoveThumbsCommand.php index 2e484ed51..aa294a4fc 100644 --- a/src/Command/RemoveThumbsCommand.php +++ b/src/Command/RemoveThumbsCommand.php @@ -17,6 +17,7 @@ use Sonata\MediaBundle\Model\MediaManagerInterface; use Sonata\MediaBundle\Provider\MediaProviderInterface; use Sonata\MediaBundle\Provider\Pool; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Input\InputArgument; @@ -30,8 +31,10 @@ * * Useful if you have existing media content and added new formats. */ +#[AsCommand(name: 'sonata:media:remove-thumbnails', description: 'Remove uploaded image thumbs')] final class RemoveThumbsCommand extends Command { + // TODO: Remove static properties when support for Symfony < 6.0 is dropped. protected static $defaultName = 'sonata:media:remove-thumbnails'; protected static $defaultDescription = 'Remove uploaded image thumbs'; @@ -57,6 +60,7 @@ protected function configure(): void \assert(null !== static::$defaultDescription); $this + // TODO: Remove setDescription when support for Symfony < 5.4 is dropped. ->setDescription(static::$defaultDescription) ->addArgument('providerName', InputArgument::OPTIONAL, 'The provider') ->addArgument('context', InputArgument::OPTIONAL, 'The context') diff --git a/src/Command/SyncThumbsCommand.php b/src/Command/SyncThumbsCommand.php index bd1da548c..67d40d5ad 100644 --- a/src/Command/SyncThumbsCommand.php +++ b/src/Command/SyncThumbsCommand.php @@ -18,6 +18,7 @@ use Sonata\MediaBundle\Model\MediaManagerInterface; use Sonata\MediaBundle\Provider\MediaProviderInterface; use Sonata\MediaBundle\Provider\Pool; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -30,8 +31,10 @@ * * Useful if you have existing media content and added new formats. */ +#[AsCommand(name: 'sonata:media:sync-thumbnails', description: 'Sync uploaded image thumbs with new media formats')] final class SyncThumbsCommand extends Command { + // TODO: Remove static properties when support for Symfony < 6.0 is dropped. protected static $defaultName = 'sonata:media:sync-thumbnails'; protected static $defaultDescription = 'Sync uploaded image thumbs with new media formats'; @@ -57,6 +60,7 @@ protected function configure(): void \assert(null !== static::$defaultDescription); $this + // TODO: Remove setDescription when support for Symfony < 5.4 is dropped. ->setDescription(static::$defaultDescription) ->addArgument('providerName', InputArgument::OPTIONAL, 'The provider') ->addArgument('context', InputArgument::OPTIONAL, 'The context') diff --git a/src/Command/UpdateCdnStatusCommand.php b/src/Command/UpdateCdnStatusCommand.php index 49659c445..6a5e91917 100644 --- a/src/Command/UpdateCdnStatusCommand.php +++ b/src/Command/UpdateCdnStatusCommand.php @@ -17,6 +17,7 @@ use Sonata\MediaBundle\Model\MediaManagerInterface; use Sonata\MediaBundle\Provider\MediaProviderInterface; use Sonata\MediaBundle\Provider\Pool; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -29,8 +30,10 @@ * * @author Javier Spagnoletti */ +#[AsCommand(name: 'sonata:media:update-cdn-status', description: 'Updates model media with the current CDN status')] final class UpdateCdnStatusCommand extends Command { + // TODO: Remove static properties when support for Symfony < 6.0 is dropped. protected static $defaultName = 'sonata:media:update-cdn-status'; protected static $defaultDescription = 'Updates model media with the current CDN status'; @@ -56,6 +59,7 @@ protected function configure(): void \assert(null !== static::$defaultDescription); $this + // TODO: Remove setDescription when support for Symfony < 5.4 is dropped. ->setDescription(static::$defaultDescription) ->addArgument('providerName', InputArgument::OPTIONAL, 'The provider') ->addArgument('context', InputArgument::OPTIONAL, 'The context') diff --git a/tests/App/AppKernel.php b/tests/App/AppKernel.php index 99e264231..b3526969e 100644 --- a/tests/App/AppKernel.php +++ b/tests/App/AppKernel.php @@ -17,6 +17,7 @@ use Doctrine\Bundle\DoctrineBundle\DoctrineBundle; use Knp\Bundle\MenuBundle\KnpMenuBundle; use Sonata\AdminBundle\SonataAdminBundle; +use Sonata\BlockBundle\Cache\HttpCacheHandler; use Sonata\BlockBundle\SonataBlockBundle; use Sonata\Doctrine\Bridge\Symfony\SonataDoctrineBundle; use Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle; @@ -91,6 +92,9 @@ protected function configureRoutes($routes): void $routes->import(__DIR__.'/Resources/config/routing/routes.yaml'); } + /** + * @psalm-suppress DeprecatedClass + */ protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void { $loader->load(__DIR__.'/Resources/config/config.yaml'); @@ -101,6 +105,10 @@ protected function configureContainer(ContainerBuilder $container, LoaderInterfa $loader->load(__DIR__.'/Resources/config/config_symfony_v4.yaml'); } + if (class_exists(HttpCacheHandler::class)) { + $loader->load(__DIR__.'/Resources/config/config_sonata_block_v4.yaml'); + } + $loader->load(__DIR__.'/Resources/config/services.php'); $container->setParameter('app.base_dir', $this->getBaseDir()); } diff --git a/tests/App/Resources/config/config.yaml b/tests/App/Resources/config/config.yaml index e92adfa98..68d8167ea 100644 --- a/tests/App/Resources/config/config.yaml +++ b/tests/App/Resources/config/config.yaml @@ -9,6 +9,7 @@ framework: enable_annotations: false router: utf8: true + http_method_override: false security: role_hierarchy: null diff --git a/tests/App/Resources/config/config_sonata_block_v4.yaml b/tests/App/Resources/config/config_sonata_block_v4.yaml new file mode 100644 index 000000000..b83465ccb --- /dev/null +++ b/tests/App/Resources/config/config_sonata_block_v4.yaml @@ -0,0 +1,2 @@ +sonata_block: + http_cache: false