Merge branch 'sf5.1-migration'

This commit is contained in:
Jan Böhmer 2020-05-31 20:12:09 +02:00
commit aa95f130db
22 changed files with 912 additions and 515 deletions

View file

@ -4,6 +4,7 @@
use App\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\ErrorHandler\Debug;
if (!in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
@ -14,8 +15,8 @@ set_time_limit(0);
require dirname(__DIR__).'/vendor/autoload.php';
if (!class_exists(Application::class)) {
throw new LogicException('You need to add "symfony/framework-bundle" as a Composer dependency.');
if (!class_exists(Application::class) || !class_exists(Dotenv::class)) {
throw new LogicException('You need to add "symfony/framework-bundle" and "symfony/dotenv" as Composer dependencies.');
}
$input = new ArgvInput();
@ -27,7 +28,7 @@ if ($input->hasParameterOption('--no-debug', true)) {
putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0');
}
require dirname(__DIR__).'/config/bootstrap.php';
(new Dotenv())->bootEnv(dirname(__DIR__).'/.env');
if ($_SERVER['APP_DEBUG']) {
umask(0000);

View file

@ -31,27 +31,27 @@
"sensiolabs/security-checker": "^6.0",
"shivas/versioning-bundle": "^3.1",
"symfony/apache-pack": "^1.0",
"symfony/asset": "5.0.*",
"symfony/console": "5.0.*",
"symfony/dotenv": "5.0.*",
"symfony/expression-language": "5.0.*",
"symfony/asset": "5.1.*",
"symfony/console": "5.1.*",
"symfony/dotenv": "5.1.*",
"symfony/expression-language": "5.1.*",
"symfony/flex": "^1.1",
"symfony/form": "5.0.*",
"symfony/framework-bundle": "5.0.*",
"symfony/http-client": "5.0.*",
"symfony/http-kernel": "5.0.*",
"symfony/mailer": "5.0.*",
"symfony/form": "5.1.*",
"symfony/framework-bundle": "5.1.*",
"symfony/http-client": "5.1.*",
"symfony/http-kernel": "5.1.*",
"symfony/mailer": "5.1.*",
"symfony/monolog-bundle": "^3.1",
"symfony/orm-pack": "*",
"symfony/process": "5.0.*",
"symfony/security-bundle": "5.0.*",
"symfony/process": "5.1.*",
"symfony/security-bundle": "5.1.*",
"symfony/serializer-pack": "*",
"symfony/translation": "5.0.*",
"symfony/twig-bundle": "5.0.*",
"symfony/validator": "5.0.*",
"symfony/web-link": "5.0.*",
"symfony/translation": "5.1.*",
"symfony/twig-bundle": "5.1.*",
"symfony/validator": "5.1.*",
"symfony/web-link": "5.1.*",
"symfony/webpack-encore-bundle": "^1.1",
"symfony/yaml": "5.0.*",
"symfony/yaml": "5.1.*",
"tecnickcom/tc-lib-barcode": "^1.15",
"twig/cssinliner-extra": "^3.0",
"twig/extra-bundle": "^3.0",
@ -122,7 +122,7 @@
"extra": {
"symfony": {
"allow-contrib": false,
"require": "5.0.*"
"require": "5.1.*"
}
}
}

1156
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,8 @@
# As of Symfony 5.1, deprecations are logged in the dedicated "deprecation" channel when it exists
#monolog:
# channels: [deprecation]
# handlers:
# deprecation:
# type: stream
# channels: [deprecation]
# path: "%kernel.logs_dir%/%kernel.environment%.deprecations.log"

View file

@ -14,13 +14,3 @@ monolog:
type: console
process_psr_3_messages: false
channels: ["!event", "!doctrine"]
# Uncomment to log deprecations
#deprecation:
# type: stream
# path: "%kernel.logs_dir%/%kernel.environment%.deprecations.log"
#deprecation_filter:
# type: filter
# handler: deprecation
# max_level: info
# channels: ["php"]

View file

@ -1,3 +1,7 @@
framework:
router:
utf8: true
# Configure how to generate URLs in non-HTTP contexts, such as CLI commands.
# See https://symfony.com/doc/current/routing.html#generating-urls-in-commands
#default_uri: http://localhost

View file

@ -16,7 +16,8 @@ security:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
anonymous: lazy
anonymous: true
lazy: true
user_checker: App\Security\UserChecker
two_factor:
@ -40,7 +41,6 @@ security:
logout:
path: logout
target: homepage
handlers: [App\EventSubscriber\LogSystem\LogoutLoggerHandler]
remember_me:
secret: '%kernel.secret%'

View file

@ -12,6 +12,6 @@ redirector:
path: /{url}
requirements:
url: ".*"
controller: App\Controller\RedirectController:addLocalePart
controller: App\Controller\RedirectController::addLocalePart
# Dont match localized routes (no redirection loop, if no root with that name exists)
condition: "not (request.getPathInfo() matches '/^\\\\/[a-z]{2}(_[A-Z]{2})?\\\\//')"

View file

@ -78,6 +78,12 @@ services:
$allow_attachments_downloads: '%partdb.attachments.allow_downloads%'
$mimeTypes: '@mime_types'
App\EventSubscriber\LogSystem\LogoutLoggerListener:
tags:
- name: 'kernel.event_listener'
event: 'Symfony\Component\Security\Http\Event\LogoutEvent'
dispatcher: security.event_dispatcher.main
####################################################################################################################
# Attachment system
####################################################################################################################

View file

@ -1,10 +1,13 @@
<?php
use App\Kernel;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\ErrorHandler\Debug;
use Symfony\Component\HttpFoundation\Request;
require dirname(__DIR__).'/config/bootstrap.php';
require dirname(__DIR__).'/vendor/autoload.php';
(new Dotenv())->bootEnv(dirname(__DIR__).'/.env');
if ($_SERVER['APP_DEBUG']) {
umask(0000);

View file

@ -455,7 +455,7 @@ abstract class Attachment extends AbstractNamedDBElement
*
* @return bool True if the string is a valid URL. False, if the string is not an URL or invalid.
*/
public static function isURL(string $string, bool $path_required = true, bool $only_http = true): bool
public static function isValidURL(string $string, bool $path_required = true, bool $only_http = true): bool
{
if ($only_http) { //Check if scheme is HTTPS or HTTP
$scheme = parse_url($string, PHP_URL_SCHEME);

View file

@ -48,12 +48,13 @@ use App\Services\LogSystem\EventLogger;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Http\Event\LogoutEvent;
use Symfony\Component\Security\Http\Logout\LogoutHandlerInterface;
/**
* This handler logs to event log, if a user logs out.
*/
class LogoutLoggerHandler implements LogoutHandlerInterface
class LogoutLoggerListener
{
protected $logger;
protected $gpdr_compliance;
@ -64,8 +65,16 @@ class LogoutLoggerHandler implements LogoutHandlerInterface
$this->gpdr_compliance = $gpdr_compliance;
}
public function logout(Request $request, Response $response, TokenInterface $token): void
public function __invoke(LogoutEvent $event)
{
$request = $event->getRequest();
$token = $event->getToken();
if ($token === null) {
return;
}
$log = new UserLogoutLogEntry($request->getClientIp(), $this->gpdr_compliance);
$user = $token->getUser();
if ($user instanceof User) {

View file

@ -46,7 +46,7 @@ use App\Entity\LogSystem\UserLoginLogEntry;
use App\Entity\UserSystem\User;
use App\Services\LogSystem\EventLogger;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
use Symfony\Component\Security\Http\SecurityEvents;
use Symfony\Contracts\Translation\TranslatorInterface;
@ -61,10 +61,10 @@ final class LoginSuccessSubscriber implements EventSubscriberInterface
private $eventLogger;
private $gpdr_compliance;
public function __construct(TranslatorInterface $translator, FlashBagInterface $flashBag, EventLogger $eventLogger, bool $gpdr_compliance)
public function __construct(TranslatorInterface $translator, SessionInterface $session, EventLogger $eventLogger, bool $gpdr_compliance)
{
$this->translator = $translator;
$this->flashBag = $flashBag;
$this->flashBag = $session->getFlashBag();
$this->eventLogger = $eventLogger;
$this->gpdr_compliance = $gpdr_compliance;
}

View file

@ -45,6 +45,7 @@ namespace App\EventSubscriber\UserSystem;
use App\Entity\UserSystem\User;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Security\Core\Security;
@ -77,10 +78,10 @@ final class PasswordChangeNeededSubscriber implements EventSubscriberInterface
private $flashBag;
private $httpUtils;
public function __construct(Security $security, FlashBagInterface $flashBag, HttpUtils $httpUtils)
public function __construct(Security $security, SessionInterface $session, HttpUtils $httpUtils)
{
$this->security = $security;
$this->flashBag = $flashBag;
$this->flashBag = $session->getFlashBag();
$this->httpUtils = $httpUtils;
}

View file

@ -52,6 +52,7 @@ use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
@ -74,12 +75,12 @@ final class RegisterU2FSubscriber implements EventSubscriberInterface
*/
private $eventDispatcher;
public function __construct(UrlGeneratorInterface $router, EntityManagerInterface $entityManager, FlashBagInterface $flashBag, EventDispatcherInterface $eventDispatcher, bool $demo_mode)
public function __construct(UrlGeneratorInterface $router, EntityManagerInterface $entityManager, SessionInterface $session, EventDispatcherInterface $eventDispatcher, bool $demo_mode)
{
$this->router = $router;
$this->em = $entityManager;
$this->demo_mode = $demo_mode;
$this->flashBag = $flashBag;
$this->flashBag = $session->getFlashBag();
$this->eventDispatcher = $eventDispatcher;
}

View file

@ -53,7 +53,7 @@ class CollectionTypeExtension extends AbstractTypeExtension
public static function getExtendedTypes(): iterable
{
return [CollectionType::class];
return [CollectionType::class, WorkaroundCollectionType::class];
}
public function configureOptions(OptionsResolver $resolver): void

View file

@ -47,6 +47,7 @@ use App\Entity\Parts\Supplier;
use App\Entity\PriceInformations\Orderdetail;
use App\Entity\PriceInformations\Pricedetail;
use App\Form\Type\StructuralEntityType;
use App\Form\WorkaroundCollectionType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
@ -109,7 +110,7 @@ class OrderdetailType extends AbstractType
}
//Attachment section
$event->getForm()->add('pricedetails', CollectionType::class, [
$event->getForm()->add('pricedetails', WorkaroundCollectionType::class, [
'entry_type' => PricedetailType::class,
'allow_add' => $this->security->isGranted('@parts_prices.create'),
'allow_delete' => $this->security->isGranted('@parts_prices.delete'),

View file

@ -56,6 +56,7 @@ use App\Form\ParameterType;
use App\Form\Type\MasterPictureAttachmentType;
use App\Form\Type\SIUnitType;
use App\Form\Type\StructuralEntityType;
use App\Form\WorkaroundCollectionType;
use FOS\CKEditorBundle\Form\Type\CKEditorType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
@ -258,7 +259,7 @@ class PartBaseType extends AbstractType
]);
//Orderdetails section
$builder->add('orderdetails', CollectionType::class, [
$builder->add('orderdetails', WorkaroundCollectionType::class, [
'entry_type' => OrderdetailType::class,
'allow_add' => $this->security->isGranted('orderdetails.create', $part),
'allow_delete' => $this->security->isGranted('orderdetails.delete', $part),

View file

@ -0,0 +1,31 @@
<?php
namespace App\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
/**
* This a workaround for the issue #37024.
* @package App\Form
*/
class WorkaroundCollectionType extends CollectionType
{
/**
* Use the original implementation for finishView() instead of the one, the one that cause the bug.
* @param FormView $view
* @param FormInterface $form
* @param array $options
*/
public function finishView(FormView $view, FormInterface $form, array $options)
{
if ($view->vars['prototype']->vars['multipart']) {
$view->vars['multipart'] = true;
}
}
}

View file

@ -1,76 +1,31 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace App;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\RouteCollectionBuilder;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
class Kernel extends BaseKernel
{
use MicroKernelTrait;
private const CONFIG_EXTS = '.{php,xml,yaml,yml}';
public function registerBundles(): iterable
protected function configureContainer(ContainerConfigurator $container): void
{
$contents = require $this->getProjectDir().'/config/bundles.php';
foreach ($contents as $class => $envs) {
if ($envs[$this->environment] ?? $envs['all'] ?? false) {
yield new $class();
}
}
$container->import('../config/{packages}/*.yaml');
$container->import('../config/{packages}/'.$this->environment.'/*.yaml');
$container->import('../config/{services}.yaml');
$container->import('../config/{services}_'.$this->environment.'.yaml');
//Add parameter file
$container->import('../config/parameters.yaml');
}
public function getProjectDir(): string
protected function configureRoutes(RoutingConfigurator $routes): void
{
return \dirname(__DIR__);
}
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
{
$container->addResource(new FileResource($this->getProjectDir().'/config/bundles.php'));
$container->setParameter('container.dumper.inline_class_loader', \PHP_VERSION_ID < 70400 || $this->debug);
$container->setParameter('container.dumper.inline_factories', true);
$confDir = $this->getProjectDir().'/config';
$loader->load($confDir.'/parameters.yaml');
$loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob');
$loader->load($confDir.'/{packages}/'.$this->environment.'/*'.self::CONFIG_EXTS, 'glob');
$loader->load($confDir.'/{services}'.self::CONFIG_EXTS, 'glob');
$loader->load($confDir.'/{services}_'.$this->environment.self::CONFIG_EXTS, 'glob');
}
protected function configureRoutes(RouteCollectionBuilder $routes): void
{
$confDir = $this->getProjectDir().'/config';
$routes->import($confDir.'/{routes}/'.$this->environment.'/*'.self::CONFIG_EXTS, '/', 'glob');
$routes->import($confDir.'/{routes}/*'.self::CONFIG_EXTS, '/', 'glob');
$routes->import($confDir.'/{routes}'.self::CONFIG_EXTS, '/', 'glob');
$routes->import('../config/{routes}/'.$this->environment.'/*.yaml');
$routes->import('../config/{routes}/*.yaml');
$routes->import('../config/{routes}.yaml');
}
}

View file

@ -477,16 +477,15 @@
"version": "v4.2.3"
},
"symfony/console": {
"version": "4.4",
"version": "5.1",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "master",
"version": "4.4",
"ref": "ea8c0eda34fda57e7d5cd8cbd889e2a387e3472c"
"version": "5.1",
"ref": "c6d02bdfba9da13c22157520e32a602dbee8a75c"
},
"files": [
"./bin/console",
"./config/bootstrap.php"
"./bin/console"
]
},
"symfony/contracts": {
@ -513,6 +512,9 @@
"symfony/dependency-injection": {
"version": "v4.2.3"
},
"symfony/deprecation-contracts": {
"version": "v2.1.2"
},
"symfony/doctrine-bridge": {
"version": "v4.2.3"
},
@ -556,15 +558,14 @@
"version": "v4.2.3"
},
"symfony/framework-bundle": {
"version": "4.4",
"version": "5.1",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "master",
"version": "4.4",
"ref": "36d3075b2b8e0c4de0e82356a86e4c4a4eb6681b"
"version": "5.1",
"ref": "37b4ec59eda3eb89705f21a0da7231862495ce0a"
},
"files": [
"./config/bootstrap.php",
"./config/packages/cache.yaml",
"./config/packages/framework.yaml",
"./config/packages/test/framework.yaml",
@ -626,10 +627,11 @@
"repo": "github.com/symfony/recipes",
"branch": "master",
"version": "3.3",
"ref": "a89f4cd8a232563707418eea6c2da36acd36a917"
"ref": "d7249f7d560f6736115eee1851d02a65826f0a56"
},
"files": [
"./config/packages/dev/monolog.yaml",
"./config/packages/prod/deprecations.yaml",
"./config/packages/prod/monolog.yaml",
"./config/packages/test/monolog.yaml"
]
@ -658,12 +660,18 @@
"symfony/polyfill-ctype": {
"version": "v1.14.0"
},
"symfony/polyfill-intl-grapheme": {
"version": "v1.17.0"
},
"symfony/polyfill-intl-icu": {
"version": "v1.10.0"
},
"symfony/polyfill-intl-idn": {
"version": "v1.10.0"
},
"symfony/polyfill-intl-normalizer": {
"version": "v1.17.0"
},
"symfony/polyfill-mbstring": {
"version": "v1.10.0"
},
@ -676,6 +684,9 @@
"symfony/polyfill-php73": {
"version": "v1.11.0"
},
"symfony/polyfill-php80": {
"version": "v1.17.0"
},
"symfony/process": {
"version": "v4.2.3"
},
@ -689,12 +700,12 @@
"version": "v4.2.3"
},
"symfony/routing": {
"version": "4.2",
"version": "5.1",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "master",
"version": "4.2",
"ref": "683dcb08707ba8d41b7e34adb0344bfd68d248a7"
"version": "5.1",
"ref": "b4f3e7c95e38b606eef467e8a42a8408fc460c43"
},
"files": [
"./config/packages/prod/routing.yaml",
@ -738,6 +749,9 @@
"symfony/stopwatch": {
"version": "v4.2.3"
},
"symfony/string": {
"version": "v5.1.0"
},
"symfony/templating": {
"version": "v4.3.4"
},

View file

@ -285,14 +285,14 @@ class AttachmentTest extends TestCase
public function testIsURL(): void
{
$url = '%MEDIA%/test.txt';
$this->assertFalse(Attachment::isURL($url));
$this->assertFalse(Attachment::isValidURL($url));
$url = 'https://google.de';
$this->assertFalse(Attachment::isURL($url));
$this->assertFalse(Attachment::isValidURL($url));
$url = 'ftp://google.de';
$this->assertTrue(Attachment::isURL($url, false, false));
$this->assertFalse(Attachment::isURL($url, false, true));
$this->assertTrue(Attachment::isValidURL($url, false, false));
$this->assertFalse(Attachment::isValidURL($url, false, true));
}
/**