mxgross / EasyBackupBundle

Kimai 2 Plugin for easier backups
MIT License
24 stars 6 forks source link

Settings can be saved, but Controller always gets default value instead of current value #12

Closed mxgross closed 4 years ago

mxgross commented 4 years ago

When changing the setting mysqldump path it is saved and correctly loaded in the settings page. But in the EasybackupController the requested setting always returns its default value.

kevinpapst commented 4 years ago

Try to avoid direct configuration access in the controller.

Please try to move this line https://github.com/mxgross/EasyBackupBundle/blob/master/Controller/EasyBackupController.php#L65 to its own getBackupDIrectory() method inside the controller.

kevinpapst commented 4 years ago

Try to avoid direct configuration access in the controller.

That was a mistake: I meant "in the controllers __construct()". Try to access the configuration when you need it. So instead of caching the config value, store a reference to the ConfigurationObject and then access it when needed.

mxgross commented 4 years ago

I still have issues in prod environment with the current implementation how to get the configuration inside the controller methods. Could you please take a look?

prod.log says

[2020-01-09 20:50:42] request.INFO: Matched route "create_backup". {"route":"create_backup","route_parameters":{"_route":"create_backup","_controller":"KimaiPlugin\\EasyBackupBundle\\Controller\\EasyBackupController::createBackupAction","_locale":"en"},"request_uri":"http://192.168.2.121/index.php/en/admin/easy-backup/create_backup","method":"GET"} []
[2020-01-09 20:50:42] security.DEBUG: Read existing security token from the session. {"key":"_security_secured_area","token_class":"Symfony\\Component\\Security\\Core\\Authentication\\Token\\UsernamePasswordToken"} []
[2020-01-09 20:50:42] php.INFO: User Deprecated: Checking for the AdvancedUserInterface in "Symfony\Component\Security\Core\Authentication\Token\AbstractToken::hasUserChanged()" is deprecated since Symfony 4.1 and support for it will be removed in 5.0. Implement the Symfony\Component\Security\Core\User\EquatableInterface to check if the user has been changed, {"exception":"[object] (ErrorException(code: 0): User Deprecated: Checking for the AdvancedUserInterface in \"Symfony\\Component\\Security\\Core\\Authentication\\Token\\AbstractToken::hasUserChanged()\" is deprecated since Symfony 4.1 and support for it will be removed in 5.0. Implement the Symfony\\Component\\Security\\Core\\User\\EquatableInterface to check if the user has been changed, at /var/www/html/kimai2/vendor/symfony/security-core/Authentication/Token/AbstractToken.php:325)"} []
[2020-01-09 20:50:42] php.INFO: User Deprecated: Checking for the AdvancedUserInterface in "Symfony\Component\Security\Core\Authentication\Token\AbstractToken::hasUserChanged()" is deprecated since Symfony 4.1 and support for it will be removed in 5.0. Implement the Symfony\Component\Security\Core\User\EquatableInterface to check if the user has been changed, {"exception":"[object] (ErrorException(code: 0): User Deprecated: Checking for the AdvancedUserInterface in \"Symfony\\Component\\Security\\Core\\Authentication\\Token\\AbstractToken::hasUserChanged()\" is deprecated since Symfony 4.1 and support for it will be removed in 5.0. Implement the Symfony\\Component\\Security\\Core\\User\\EquatableInterface to check if the user has been changed, at /var/www/html/kimai2/vendor/symfony/security-core/Authentication/Token/AbstractToken.php:325)"} []
[2020-01-09 20:50:42] security.DEBUG: User was reloaded from a user provider. {"provider":"Symfony\\Component\\Security\\Core\\User\\ChainUserProvider","username":"maximilian"} []
[2020-01-09 20:50:42] security.DEBUG: Checking for guard authentication credentials. {"firewall_key":"secured_area","authenticators":1} []
[2020-01-09 20:50:42] security.DEBUG: Checking support on guard authenticator. {"firewall_key":"secured_area","authenticator":"App\\Security\\TokenAuthenticator"} []
[2020-01-09 20:50:42] security.DEBUG: Guard authenticator does not support the request. {"firewall_key":"secured_area","authenticator":"App\\Security\\TokenAuthenticator"} []
[2020-01-09 20:50:42] request.CRITICAL: Uncaught PHP Exception RuntimeException: "Controller "KimaiPlugin\EasyBackupBundle\Controller\EasyBackupController::createBackupAction()" requires that you provide a value for the "$configuration" argument. Either the argument is nullable and no null value has been provided, no default value has been provided or because there is a non optional argument after this one." at /var/www/html/kimai2/vendor/symfony/http-kernel/Controller/ArgumentResolver.php line 78 {"exception":"[object] (RuntimeException(code: 0): Controller \"KimaiPlugin\\EasyBackupBundle\\Controller\\EasyBackupController::createBackupAction()\" requires that you provide a value for the \"$configuration\" argument. Either the argument is nullable and no null value has been provided, no default value has been provided or because there is a non optional argument after this one. at /var/www/html/kimai2/vendor/symfony/http-kernel/Controller/ArgumentResolver.php:78)"} []
[2020-01-09 20:50:42] security.DEBUG: Stored the security token in the session. {"key":"_security_secured_area"} []
kevinpapst commented 4 years ago

I think the definition is wrong, compare: https://github.com/mxgross/EasyBackupBundle/blob/master/Configuration/EasyBackupConfiguration.php#L21 https://github.com/mxgross/EasyBackupBundle/blob/master/DependencyInjection/Configuration.php#L23 https://github.com/mxgross/EasyBackupBundle/blob/master/EventSubscriber/SystemConfigurationSubscriber.php#L34

You are using easy_backup and easybackup. Add a dump here: https://github.com/mxgross/EasyBackupBundle/blob/master/DependencyInjection/EasyBackupExtension.php#L29 and see what it spits out (the dump will only be shown when refreshing the cache).

kevinpapst commented 4 years ago

Check #16 - works for me. And you can forget my comment above, I tested it and it doesn't matter (unless someone wants to configure the settings via yaml).

mxgross commented 4 years ago

Works perfectly. Thanks :)