Skip to content

Commit

Permalink
Merge 4.x into 5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
SonataCI committed Jun 26, 2022
2 parents b5a1912 + f121156 commit bd2879e
Show file tree
Hide file tree
Showing 63 changed files with 247 additions and 119 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ docs export-ignore
Makefile export-ignore
phpunit.xml.dist export-ignore
bin/console export-ignore
rector.php export-ignore
phpstan.neon.dist export-ignore
phpstan-baseline.neon export-ignore
phpstan-console-application.php export-ignore
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/qa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,29 @@ jobs:

- name: Psalm
run: vendor/bin/psalm --no-progress --show-info=false --stats --output-format=github --threads=$(nproc) --shepherd --php-version=8.1

rector:
name: Rector

runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
coverage: none
tools: composer:v2
extensions: mongodb, gd

- name: Install Composer dependencies (highest)
uses: ramsey/composer-install@v2
with:
dependency-versions: highest
composer-options: --prefer-dist --prefer-stable

- name: Rector
run: vendor/bin/rector --no-progress-bar --dry-run
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [4.3.0](https://github.com/sonata-project/SonataMediaBundle/compare/4.2.0...4.3.0) - 2022-06-25
### Changed
- [[#2313](https://github.com/sonata-project/SonataMediaBundle/pull/2313)] `MediaType` form type will now allow you to pass your own `data_class` instead of relying on the provided `$this->class`. ([@esserj](https://github.com/esserj))

### Removed
- [[#2314](https://github.com/sonata-project/SonataMediaBundle/pull/2314)] Avoid deprecations for console commands on Symfony 6.1. ([@jordisala1991](https://github.com/jordisala1991))

## [4.2.0](https://github.com/sonata-project/SonataMediaBundle/compare/4.1.5...4.2.0) - 2022-06-12
### Changed
- [[#2310](https://github.com/sonata-project/SonataMediaBundle/pull/2310)] Bump `imagine/imagine` to ^1.3. ([@jordisala1991](https://github.com/jordisala1991))
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,7 @@ phpstan:
psalm:
vendor/bin/psalm --php-version=8.1
.PHONY: psalm

rector:
vendor/bin/rector
.PHONY: rector
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@
"phpstan/phpstan-strict-rules": "^1.0",
"phpstan/phpstan-symfony": "^1.0",
"phpunit/phpunit": "^9.5",
"psalm/plugin-phpunit": "^0.16",
"psalm/plugin-phpunit": "^0.17",
"psalm/plugin-symfony": "^3.0",
"rector/rector": "^0.13",
"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",
Expand All @@ -100,7 +101,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"
},
Expand Down
41 changes: 41 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

/*
* DO NOT EDIT THIS FILE!
*
* It's auto-generated by sonata-project/dev-kit package.
*/

use Rector\Config\RectorConfig;
use Rector\Php70\Rector\FunctionLike\ExceptionHandlerTypehintRector;
use Rector\Php71\Rector\FuncCall\CountOnNullRector;
use Rector\Set\ValueObject\LevelSetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__.'/src',
__DIR__.'/tests',
]);

$rectorConfig->sets([
LevelSetList::UP_TO_PHP_74,
]);

$rectorConfig->importNames();
$rectorConfig->disableImportShortClasses();
$rectorConfig->skip([
CountOnNullRector::class,
ExceptionHandlerTypehintRector::class,
]);
};
5 changes: 3 additions & 2 deletions src/Admin/BaseMediaAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
use Sonata\ClassificationBundle\Model\CategoryManagerInterface;
use Sonata\ClassificationBundle\Model\ContextManagerInterface;
use Sonata\MediaBundle\Form\DataTransformer\ProviderDataTransformer;
use Sonata\MediaBundle\Model\MediaInterface;
use Sonata\MediaBundle\Provider\MediaProviderInterface;
use Sonata\MediaBundle\Provider\Pool;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;

/**
* @phpstan-extends AbstractAdmin<\Sonata\MediaBundle\Model\MediaInterface>
* @phpstan-extends AbstractAdmin<MediaInterface>
*/
abstract class BaseMediaAdmin extends AbstractAdmin
{
Expand All @@ -46,7 +47,7 @@ abstract class BaseMediaAdmin extends AbstractAdmin
* @param CategoryManagerInterface|string|null $categoryManager
* @param ContextManagerInterface|string|null $contextManager
*
* @phpstan-param CategoryManagerInterface|class-string<\Sonata\MediaBundle\Model\MediaInterface>|null $categoryManager
* @phpstan-param CategoryManagerInterface|class-string<MediaInterface>|null $categoryManager
*/
public function __construct(
$pool,
Expand Down
4 changes: 3 additions & 1 deletion src/Admin/GalleryAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\Form\Type\CollectionType;
use Sonata\MediaBundle\Model\GalleryInterface;
use Sonata\MediaBundle\Model\GalleryItemInterface;
use Sonata\MediaBundle\Provider\Pool;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;

/**
* @phpstan-extends AbstractAdmin<\Sonata\MediaBundle\Model\GalleryInterface<\Sonata\MediaBundle\Model\GalleryItemInterface>>
* @phpstan-extends AbstractAdmin<GalleryInterface<GalleryItemInterface>>
*/
final class GalleryAdmin extends AbstractAdmin
{
Expand Down
3 changes: 2 additions & 1 deletion src/Admin/GalleryItemAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Form\Type\ModelListType;
use Sonata\MediaBundle\Model\GalleryItemInterface;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;

/**
* @phpstan-extends AbstractAdmin<\Sonata\MediaBundle\Model\GalleryItemInterface>
* @phpstan-extends AbstractAdmin<GalleryItemInterface>
*/
final class GalleryItemAdmin extends AbstractAdmin
{
Expand Down
7 changes: 4 additions & 3 deletions src/CDN/CloudFrontVersion3.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ public function flushPaths(array $paths): string
}
// Normalizes paths due possible typos since all the CloudFront's
// objects starts with a leading slash
$normalizedPaths = array_map(static function (string $path): string {
return '/'.ltrim($path, '/');
}, $paths);
$normalizedPaths = array_map(
static fn (string $path): string => '/'.ltrim($path, '/'),
$paths
);

try {
$result = $this->client->createInvalidation([
Expand Down
6 changes: 5 additions & 1 deletion src/Command/AddMassMediaCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 < 5.4 is dropped.
protected static $defaultName = 'sonata:media:add-multiple';
protected static $defaultDescription = 'Add medias in mass into the database';

Expand All @@ -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)', ',')
Expand Down Expand Up @@ -130,7 +134,7 @@ private function insertMedia(array $data, OutputInterface $output): void
$this->mediaManager->save($media);
$output->writeln(sprintf(' > %s - %s', $media->getId() ?? '', $media->getName() ?? ''));
} catch (\Exception $e) {
$output->writeln(sprintf('<error>%s</error> : %s', $e->getMessage(), json_encode($data)));
$output->writeln(sprintf('<error>%s</error> : %s', $e->getMessage(), json_encode($data, \JSON_THROW_ON_ERROR)));
}
}
}
4 changes: 4 additions & 0 deletions src/Command/AddMediaCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 < 5.4 is dropped.
protected static $defaultName = 'sonata:media:add';
protected static $defaultDescription = 'Add a media into the database';

Expand All @@ -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')
Expand Down
4 changes: 4 additions & 0 deletions src/Command/CleanMediaCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 < 5.4 is dropped.
protected static $defaultName = 'sonata:media:clean-uploads';
protected static $defaultDescription = 'Find orphaned files in media upload directory';

Expand Down Expand Up @@ -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');
}
Expand Down
4 changes: 4 additions & 0 deletions src/Command/FixMediaContextCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 < 5.4 is dropped.
protected static $defaultName = 'sonata:media:fix-media-context';
protected static $defaultDescription = 'Generate the default category for each media context';

Expand All @@ -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);
}

Expand Down
4 changes: 4 additions & 0 deletions src/Command/RefreshMetadataCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 < 5.4 is dropped.
protected static $defaultName = 'sonata:media:refresh-metadata';
protected static $defaultDescription = 'Refresh meta information';

Expand All @@ -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');
Expand Down
4 changes: 4 additions & 0 deletions src/Command/RemoveThumbsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 < 5.4 is dropped.
protected static $defaultName = 'sonata:media:remove-thumbnails';
protected static $defaultDescription = 'Remove uploaded image thumbs';

Expand All @@ -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')
Expand Down
4 changes: 4 additions & 0 deletions src/Command/SyncThumbsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 < 5.4 is dropped.
protected static $defaultName = 'sonata:media:sync-thumbnails';
protected static $defaultDescription = 'Sync uploaded image thumbs with new media formats';

Expand All @@ -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')
Expand Down

0 comments on commit bd2879e

Please sign in to comment.