Update to FOSUserBundle 3.1

Also remove some deprecation from Symfony.
Use `LegacyEventDispatcherProxy` to handle Symfony 4 dispatch from FOSUser
This commit is contained in:
Jeremy Benoist 2022-12-13 13:39:24 +01:00
parent 141d289ec0
commit 33267f0736
No known key found for this signature in database
GPG Key ID: 7168D5DD29F38552
30 changed files with 90 additions and 92 deletions

View File

@ -22,15 +22,10 @@ updates:
- j0k3r
- tcitworld
- Kdecherf
labels:
- Ready for review
ignore:
- dependency-name: doctrine/doctrine-migrations-bundle
versions:
- "> 1.3.2"
- dependency-name: friendsofsymfony/user-bundle
versions:
- "> 2.0.2"
- package-ecosystem: github-actions
directory: "/"
schedule:

View File

@ -179,8 +179,10 @@ fos_user:
confirmation:
enabled: "%fosuser_confirmation%"
from_email:
address: "%from_email%"
sender_name: wallabag
address: "%from_email%"
sender_name: wallabag
service:
mailer: fos_user.mailer.twig_swift
fos_oauth_server:
db_driver: orm

View File

@ -34,12 +34,10 @@ security:
provider: fos_userbundle
login_firewall:
logout_on_user_change: true
pattern: ^/login$
anonymous: ~
secured_area:
logout_on_user_change: true
pattern: ^/
form_login:
provider: fos_userbundle

View File

@ -69,7 +69,7 @@
"friendsofsymfony/jsrouting-bundle": "^2.2",
"friendsofsymfony/oauth-server-bundle": "^1.5",
"friendsofsymfony/rest-bundle": "~2.1",
"friendsofsymfony/user-bundle": "2.1.*",
"friendsofsymfony/user-bundle": "^3.1",
"guzzlehttp/guzzle": "^5.3.1",
"guzzlehttp/psr7": "^1.8",
"html2text/html2text": "^4.1",

76
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "56b46a7637ad10cb3e659d390f684c01",
"content-hash": "baee037be9102a34e52539f8bafb370d",
"packages": [
{
"name": "babdev/pagerfanta-bundle",
@ -2621,46 +2621,56 @@
},
{
"name": "friendsofsymfony/user-bundle",
"version": "v2.1.2",
"version": "v3.1.0",
"source": {
"type": "git",
"url": "https://github.com/FriendsOfSymfony/FOSUserBundle.git",
"reference": "1049935edd24ec305cc6cfde1875372fa9600446"
"reference": "89c18b6944adb12541f5b3b1ab39287b5336b375"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/FriendsOfSymfony/FOSUserBundle/zipball/1049935edd24ec305cc6cfde1875372fa9600446",
"reference": "1049935edd24ec305cc6cfde1875372fa9600446",
"url": "https://api.github.com/repos/FriendsOfSymfony/FOSUserBundle/zipball/89c18b6944adb12541f5b3b1ab39287b5336b375",
"reference": "89c18b6944adb12541f5b3b1ab39287b5336b375",
"shasum": ""
},
"require": {
"paragonie/random_compat": "^1 || ^2",
"php": "^5.5.9 || ^7.0",
"symfony/form": "^2.8 || ^3.0 || ^4.0",
"symfony/framework-bundle": "^2.8 || ^3.0 || ^4.0",
"symfony/security-bundle": "^2.8 || ^3.0 || ^4.0",
"symfony/templating": "^2.8 || ^3.0 || ^4.0",
"symfony/twig-bundle": "^2.8 || ^3.0 || ^4.0",
"symfony/validator": "^2.8 || ^3.0 || ^4.0",
"twig/twig": "^1.28 || ^2.0"
"ext-dom": "*",
"ext-json": "*",
"php": "^7.4 || ^8.0",
"symfony/config": "^4.4 || ^5.0 || ^6.0",
"symfony/dependency-injection": "^4.4 || ^5.0 || ^6.0",
"symfony/event-dispatcher": "^4.4 || ^5.0 || ^6.0",
"symfony/event-dispatcher-contracts": "^1.1 || ^2.0 || ^3.0",
"symfony/form": "^4.4 || ^5.0 || ^6.0",
"symfony/framework-bundle": "^4.4 || ^5.0 || ^6.0",
"symfony/http-foundation": "^4.4 || ^5.0 || ^6.0",
"symfony/http-kernel": "^4.4 || ^5.0 || ^6.0",
"symfony/options-resolver": "^4.4 || ^5.0 || ^6.0",
"symfony/routing": "^4.4 || ^5.0 || ^6.0",
"symfony/security-bundle": "^4.4 || ^5.0 || ^6.0",
"symfony/security-core": "^4.4 || ^5.0 || ^6.0",
"symfony/translation": "^4.4 || ^5.0 || ^6.0",
"symfony/twig-bundle": "^4.4 || ^5.0 || ^6.0",
"symfony/validator": "^4.4 || ^5.0 || ^6.0",
"twig/twig": "^1.34 || ^2.4 || ^3.0"
},
"conflict": {
"doctrine/doctrine-bundle": "<1.3",
"symfony/doctrine-bridge": "<2.7"
"doctrine/persistence": "<1.3",
"symfony/doctrine-bridge": "<4.4"
},
"require-dev": {
"doctrine/doctrine-bundle": "^1.3",
"friendsofphp/php-cs-fixer": "^2.2",
"phpunit/phpunit": "^4.8.35|^5.7.11|^6.5",
"doctrine/doctrine-bundle": "^1.3 || ^2",
"friendsofphp/php-cs-fixer": "^3.0.2, !=3.5.0",
"swiftmailer/swiftmailer": "^4.3 || ^5.0 || ^6.0",
"symfony/console": "^2.8 || ^3.0 || ^4.0",
"symfony/phpunit-bridge": "^2.8 || ^3.0 || ^4.0",
"symfony/yaml": "^2.8 || ^3.0 || ^4.0"
"symfony/console": "^4.4 || ^5.0 || ^6.0",
"symfony/phpunit-bridge": "^6.1",
"symfony/yaml": "^4.4 || ^5.0 || ^6.0"
},
"type": "symfony-bundle",
"extra": {
"branch-alias": {
"dev-master": "2.1.x-dev"
"dev-master": "3.x-dev"
}
},
"autoload": {
@ -2681,11 +2691,11 @@
"email": "stof@notk.org"
},
{
"name": "FriendsOfSymfony Community",
"homepage": "https://github.com/friendsofsymfony/FOSUserBundle/contributors"
"name": "Thibault Duplessis"
},
{
"name": "Thibault Duplessis"
"name": "FriendsOfSymfony Community",
"homepage": "https://github.com/friendsofsymfony/FOSUserBundle/contributors"
}
],
"description": "Symfony FOSUserBundle",
@ -2696,9 +2706,9 @@
"support": {
"docs": "https://symfony.com/doc/master/bundles/FOSUserBundle/index.html",
"issues": "https://github.com/FriendsOfSymfony/FOSUserBundle/issues",
"source": "https://github.com/FriendsOfSymfony/FOSUserBundle/tree/v2.1.2"
"source": "https://github.com/FriendsOfSymfony/FOSUserBundle/tree/v3.1.0"
},
"time": "2018-03-08T08:59:27+00:00"
"time": "2022-10-26T09:10:52+00:00"
},
{
"name": "gedmo/doctrine-extensions",
@ -4577,16 +4587,16 @@
},
{
"name": "j0k3r/graby-site-config",
"version": "1.0.159",
"version": "1.0.160",
"source": {
"type": "git",
"url": "https://github.com/j0k3r/graby-site-config.git",
"reference": "e5bfb9d608f0ce6390d6791ede196c769216ee84"
"reference": "17994c315b292e3ff7bcbd0e982a2df849792a55"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/j0k3r/graby-site-config/zipball/e5bfb9d608f0ce6390d6791ede196c769216ee84",
"reference": "e5bfb9d608f0ce6390d6791ede196c769216ee84",
"url": "https://api.github.com/repos/j0k3r/graby-site-config/zipball/17994c315b292e3ff7bcbd0e982a2df849792a55",
"reference": "17994c315b292e3ff7bcbd0e982a2df849792a55",
"shasum": ""
},
"require": {
@ -4615,9 +4625,9 @@
"description": "Graby site config files",
"support": {
"issues": "https://github.com/j0k3r/graby-site-config/issues",
"source": "https://github.com/j0k3r/graby-site-config/tree/1.0.159"
"source": "https://github.com/j0k3r/graby-site-config/tree/1.0.160"
},
"time": "2022-11-01T02:53:54+00:00"
"time": "2022-12-01T02:33:16+00:00"
},
{
"name": "j0k3r/httplug-ssrf-plugin",

View File

@ -30,11 +30,6 @@ parameters:
count: 1
path: src/Wallabag/CoreBundle/Controller/StaticController.php
-
message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeDefinition\\:\\:children\\(\\)\\.$#"
count: 1
path: src/Wallabag/CoreBundle/DependencyInjection/Configuration.php
-
message: "#^Call to an undefined method Lexik\\\\Bundle\\\\FormFilterBundle\\\\Filter\\\\Query\\\\QueryInterface\\:\\:getExpressionBuilder\\(\\)\\.$#"
count: 1
@ -70,11 +65,6 @@ parameters:
count: 1
path: src/Wallabag/ImportBundle/Controller/WallabagController.php
-
message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeDefinition\\:\\:children\\(\\)\\.$#"
count: 1
path: src/Wallabag/ImportBundle/DependencyInjection/Configuration.php
-
message: "#^Call to an undefined method Scheb\\\\TwoFactorBundle\\\\Model\\\\Email\\\\TwoFactorInterface\\:\\:getName\\(\\)\\.$#"
count: 2
@ -94,3 +84,18 @@ parameters:
message: "#^Property Tests\\\\Wallabag\\\\CoreBundle\\\\Helper\\\\RedirectTest\\:\\:\\$routerMock has unknown class PHPUnit_Framework_MockObject_MockObject as its type\\.$#"
count: 1
path: tests/Wallabag/CoreBundle/Helper/RedirectTest.php
-
message: "#^Method Symfony\\\\Contracts\\\\EventDispatcher\\\\EventDispatcherInterface\\:\\:dispatch()#"
count: 1
path: src/Wallabag/ApiBundle/Controller/UserRestController.php
-
message: "#^Method Symfony\\\\Contracts\\\\EventDispatcher\\\\EventDispatcherInterface\\:\\:dispatch()#"
count: 1
path: src/Wallabag/CoreBundle/Command/InstallCommand.php
-
message: "#^Method Symfony\\\\Contracts\\\\EventDispatcher\\\\EventDispatcherInterface\\:\\:dispatch()#"
count: 1
path: src/Wallabag/UserBundle/Controller/ManageController.php

View File

@ -12,9 +12,6 @@ class Configuration implements ConfigurationInterface
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('wallabag_annotation');
return $treeBuilder;
return new TreeBuilder('wallabag_annotation');
}
}

View File

@ -11,6 +11,7 @@ use JMS\Serializer\SerializerInterface;
use Nelmio\ApiDocBundle\Annotation\Operation;
use Swagger\Annotations as SWG;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
@ -159,7 +160,7 @@ class UserRestController extends WallabagRestController
// dispatch a created event so the associated config will be created
$event = new UserEvent($user, $request);
$this->get(EventDispatcherInterface::class)->dispatch(FOSUserEvents::USER_CREATED, $event);
LegacyEventDispatcherProxy::decorate($this->get(EventDispatcherInterface::class))->dispatch($event, FOSUserEvents::USER_CREATED);
return $this->sendUser($user, 'user_api_with_client', JsonResponse::HTTP_CREATED);
}

View File

@ -17,9 +17,6 @@ class Configuration implements ConfigurationInterface
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('wallabag_api');
return $treeBuilder;
return new TreeBuilder('wallabag_api');
}
}

View File

@ -18,6 +18,7 @@ use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
use Wallabag\CoreBundle\Entity\IgnoreOriginInstanceRule;
use Wallabag\CoreBundle\Entity\InternalSetting;
use Wallabag\UserBundle\Entity\User;
@ -281,7 +282,7 @@ class InstallCommand extends ContainerAwareCommand
// dispatch a created event so the associated config will be created
$event = new UserEvent($user);
$this->getContainer()->get(EventDispatcherInterface::class)->dispatch(FOSUserEvents::USER_CREATED, $event);
LegacyEventDispatcherProxy::decorate($this->getContainer()->get(EventDispatcherInterface::class))->dispatch($event, FOSUserEvents::USER_CREATED);
$this->io->text('<info>Administration successfully setup.</info>');

View File

@ -9,8 +9,8 @@ class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('wallabag_core');
$treeBuilder = new TreeBuilder('wallabag_core');
$rootNode = $treeBuilder->getRootNode();
$rootNode
->children()

View File

@ -2,10 +2,10 @@
namespace Wallabag\CoreBundle\Event\Subscriber;
use Doctrine\Bundle\DoctrineBundle\Registry;
use Doctrine\Common\EventSubscriber;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\Persistence\ManagerRegistry;
use Wallabag\CoreBundle\Entity\Entry;
/**
@ -19,7 +19,7 @@ class SQLiteCascadeDeleteSubscriber implements EventSubscriber
{
private $doctrine;
public function __construct(Registry $doctrine)
public function __construct(ManagerRegistry $doctrine)
{
$this->doctrine = $doctrine;
}

View File

@ -4,7 +4,7 @@ namespace Wallabag\CoreBundle\Helper;
use Graby\Graby;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeExtensionGuesser;
use Symfony\Component\Mime\MimeTypes;
use Symfony\Component\Validator\Constraints\Locale as LocaleConstraint;
use Symfony\Component\Validator\Constraints\Url as UrlConstraint;
use Symfony\Component\Validator\Validator\ValidatorInterface;
@ -22,7 +22,7 @@ class ContentProxy
protected $ignoreOriginProcessor;
protected $validator;
protected $logger;
protected $mimeGuesser;
protected $mimeTypes;
protected $fetchingErrorMessage;
protected $eventDispatcher;
protected $storeArticleHeaders;
@ -34,7 +34,7 @@ class ContentProxy
$this->ignoreOriginProcessor = $ignoreOriginProcessor;
$this->validator = $validator;
$this->logger = $logger;
$this->mimeGuesser = new MimeTypeExtensionGuesser();
$this->mimeTypes = new MimeTypes();
$this->fetchingErrorMessage = $fetchingErrorMessage;
$this->storeArticleHeaders = $storeArticleHeaders;
}
@ -296,7 +296,7 @@ class ContentProxy
}
// if content is an image, define it as a preview too
if (!empty($content['headers']['content-type']) && \in_array($this->mimeGuesser->guess($content['headers']['content-type']), ['jpeg', 'jpg', 'gif', 'png'], true)) {
if (!empty($content['headers']['content-type']) && \in_array(current($this->mimeTypes->getExtensions($content['headers']['content-type'])), ['jpeg', 'jpg', 'gif', 'png'], true)) {
$previewPictureUrl = $content['url'];
} elseif (empty($previewPictureUrl)) {
$this->logger->debug('Extracting images from content to provide a default preview picture');

View File

@ -15,7 +15,7 @@ use Psr\Http\Message\ResponseInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\DomCrawler\Crawler;
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeExtensionGuesser;
use Symfony\Component\Mime\MimeTypes;
class DownloadImages
{
@ -24,7 +24,7 @@ class DownloadImages
private $client;
private $baseFolder;
private $logger;
private $mimeGuesser;
private $mimeTypes;
private $wallabagUrl;
public function __construct(HttpClient $client, $baseFolder, $wallabagUrl, LoggerInterface $logger, MessageFactory $messageFactory = null)
@ -33,7 +33,7 @@ class DownloadImages
$this->baseFolder = $baseFolder;
$this->wallabagUrl = rtrim($wallabagUrl, '/');
$this->logger = $logger;
$this->mimeGuesser = new MimeTypeExtensionGuesser();
$this->mimeTypes = new MimeTypes();
$this->setFolder();
}
@ -355,7 +355,7 @@ class DownloadImages
*/
private function getExtensionFromResponse(ResponseInterface $res, $imagePath)
{
$ext = $this->mimeGuesser->guess(current($res->getHeader('content-type')));
$ext = current($this->mimeTypes->getExtensions(current($res->getHeader('content-type'))));
$this->logger->debug('DownloadImages: Checking extension', ['ext' => $ext, 'header' => $res->getHeader('content-type')]);
// ok header doesn't have the extension, try a different way

View File

@ -2,7 +2,7 @@
namespace Wallabag\CoreBundle\ParamConverter;
use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\Persistence\ManagerRegistry;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\ParamConverterInterface;
use Symfony\Component\HttpFoundation\Request;

View File

@ -9,8 +9,8 @@ class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('wallabag_import');
$treeBuilder = new TreeBuilder('wallabag_import');
$rootNode = $treeBuilder->getRootNode();
$rootNode
->children()

View File

@ -11,6 +11,7 @@ use Pagerfanta\Pagerfanta;
use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\Google\GoogleAuthenticatorInterface;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
use Symfony\Component\Form\Form;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@ -49,7 +50,7 @@ class ManageController extends Controller
// dispatch a created event so the associated config will be created
$event = new UserEvent($user, $request);
$this->get(EventDispatcherInterface::class)->dispatch(FOSUserEvents::USER_CREATED, $event);
LegacyEventDispatcherProxy::decorate($this->get(EventDispatcherInterface::class))->dispatch($event, FOSUserEvents::USER_CREATED);
$this->get(SessionInterface::class)->getFlashBag()->add(
'notice',

View File

@ -9,9 +9,6 @@ class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('wallabag_user');
return $treeBuilder;
return new TreeBuilder('wallabag_user');
}
}

View File

@ -12,7 +12,6 @@ use Scheb\TwoFactorBundle\Model\BackupCodeInterface;
use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface as EmailTwoFactorInterface;
use Scheb\TwoFactorBundle\Model\Google\TwoFactorInterface as GoogleTwoFactorInterface;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\UserInterface;
use Wallabag\ApiBundle\Entity\Client;
use Wallabag\CoreBundle\Entity\Config;
use Wallabag\CoreBundle\Entity\Entry;
@ -205,11 +204,6 @@ class User extends BaseUser implements EmailTwoFactorInterface, GoogleTwoFactorI
return $this->entries;
}
public function isEqualTo(UserInterface $user)
{
return $this->username === $user->getUsername();
}
/**
* Set config.
*

View File

@ -2,9 +2,9 @@
namespace Tests\Wallabag\CoreBundle\ParamConverter;
use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\Persistence\ObjectManager;
use PHPUnit\Framework\TestCase;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Component\HttpFoundation\Request;