Got warning: 'WARNING [cache] Failed to save key' after update doctrine configuration - symfony

I got a warning: 'WARNING [cache] Failed to save key', after trying to update the doctrine configuration. this error appears when i run bin/console.
I tried updating the doctrine configuration to get rid of the deprecation warning I got.
Previously my doctrine configuration was like this:
orm:
entity_managers:
default:
metadata_cache_driver: apcu
with this configuration there are no errors or warnings that I get. there is only a deprecation notice.
then I try to update the configuration to be like this:
orm:
entity_managers:
default:
metadata_cache_driver:
type: pool
pool: doctrine.apcu_cache_pool
framework:
cache:
pools:
doctrine.apcu_cache_pool:
adapter: cache.adapter.apcu
and i got 'WARNING [cache] Failed to save key' when try run bin/console.
I know the problem is because I haven't enabled apc.enabled_cli in my php.ini.
but what I'm asking is why in my initial configuration the warning didn't appear even though apc.enabled_cli = 0
Thank you !

Related

Doctrine query_cache auto expire

I'm using symfony 3.4 + doctrine + redis by using the composer bundle sncRedisBundle
In my config.yml I enabled doctrine query cache:
orm:
default_entity_manager: default
entity_managers:
default:
connection: default
auto_mapping: false
metadata_cache_driver: redis
query_cache_driver: redis
result_cache_driver: redis # !!!
snc_redis:
clients:
doctrine:
type: predis
alias: doctrine_redis
dsn: "%redis_dsn_doctrine%"
logging: false
options:
connection_persistent: true
doctrine:
query_cache: #!!!!!!!!
#it caches the translation from Doctrine's DQL into SQL.
client: doctrine_redis
namespace: shop_doctrine_query
entity_manager: [default, legacy]
The keys set by doctrine for it's result_cache never expire:
How can I call automatically \Doctrine\ORM\Query::setQueryCacheLifetime or make that cache expire. (Note I don't have access to set redis eviction policies on this server).
I think that Doctrine query cache lifetime aren't configured in the doctrine package nor in the redis package, but in the framework package, where you set your pool of cache.
You should have a look on this issue where a user is asking how to configure RedisCluster with Doctrine Cache. B-Galati answers with a configuration example where it defines lifetime for doctrine result cache.
Could you try something like:
framework:
cache:
pools:
cache.doctrine.orm.default.query: ## I'm not sure of this name
adapter: cache.app
default_lifetime: 25200 # 1 week
Or
framework:
cache:
pools:
doctrine.query_cache_pool:
adapter: cache.app
default_lifetime: 25200 # 1 week
The symfony console cache:pool:list command could help you to identify your pools and the symfony console cache:pool:prune could help you to see if out of date queries are well deleted.

Symfony: The class XYZ was not found in the chain configured namespaces

Existing questions did not help.
I am still learning Symfony and setting up an existing project. Trying to run doctrine fixtures from my application directory.
./app/console doctrine:fixtures:load --env test
And running this gives me following errors
Error thrown while running command "doctrine:fixtures:load --env test --em default". Message: "The class 'ClientPortal\GenericBundle\Document\Accountant' was not found in the chain configured namespaces _XyzProjectName\CalendarContext\Domain\Model, Integration\GetFeedbackBundle\Model, _XyzProjectName\AccountingProcessContext\Domain\Model, _XyzProjectName\CaseContext\Domain" {"exception":"[object] (Doctrine\Common\Persistence\Mapping\MappingException(code: 0): The class 'ClientPortal\GenericBundle\Document\Accountant' was not found in the chain configured namespaces _XyzProjectName\CalendarContext\Domain\Model, Integration\GetFeedbackBundle\Model, _XyzProjectName\AccountingProcessContext\Domain\Model, _XyzProjectName\CaseContext\Domain at /usr/local/var/www/1800-api/vendor/doctrine/persistence/lib/Doctrine/Common/Persistence/Mapping/MappingException.php:22)
And this exception is being thrown when trying to persist object of class
'ClientPortal\GenericBundle\Document\Accountant'
and here is my doctrine in config.yml
doctrine:
dbal:
driver: pdo_pgsql
host: '%database_host%'
dbname: '%database_name%'
user: '%database_user%'
password: '%database_password%'
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
mappings:
CalendarBundle:
prefix: '_XyzProjectName\CalendarContext\Domain\Model'
IntegrationGetFeedbackBundle:
prefix: 'Integration\GetFeedbackBundle\Model'
AccountingProcessBundle:
prefix: '_XyzProjectName\AccountingProcessContext\Domain\Model'
CaseBundle:
prefix: '_XyzProjectName\CaseContext\Domain'
GenericBundle:
type: "annotation"
prefix: 'ClientPortal\GenericBundle\Document'
dir: 'src'
is_bundle: false
The snippet which is raising this exception
$account = new ClientPortal\GenericBundle\Document\Accountant();//full namespace added for clarity - also this file lies in the same directory structure.
$account->setSfAccountantId($accountantId);
$account->setUsername($username);
$manager = new ObjectManager;
$manager->persist( $account ); //This throws the above mentioned exception
My thought is, the file ClientPortal\GenericBundle\Document\Accountant.php is being autoloaded as there is no exception thrown at the time of instantion of its object. But, there is something missing with configuration or mapping because of which doctrine does not know how to persist its object.
[Source code][1] Accountant class
GenericBundle(s) registered under AppKernel
new Website\GenericBundle\WebsiteGenericBundle(),
new Admin\GenericBundle\AdminGenericBundle(),
new ClientPortal\GenericBundle\ClientPortalGenericBundle(),
new TaxApp\GenericBundle\TaxAppGenericBundle(),
So, as I suggested in comments - try to add ClientPortal\GenericBundle\Document\ namespace to mappings in your doctrine config file, like that:
#...
orm:
auto_generate_proxy_classes: "%kernel.debug%"
mappings:
# ...
ClientPortalGenericBundle:
type: annotation
prefix: 'ClientPortal\GenericBundle\Document\'
dir: '%kernel.root_dir%/src/ClientPortal/GenericBundle/Document/'
#is_bundle: false
auto_mapping: true
Had the same issue with Symfony 4 while using multiple database connections. This one https://stackoverflow.com/a/55361742/2540699 helped me to solved my problem.
I bumped into this kind of message in my Symfony 6.1 project, using multiple entity managers, with one of the entity managers specified as default in doctrine.yaml:
doctrine:
orm:
default_entity_manager: general
entity_managers:
general:
# config for general
other_entity_manager:
# config for other entity manager
Everything was fine on my dev environment, but on production I got the error
Uncaught PHP Exception Doctrine\Persistence\Mapping\MappingException: "The class XXX was not found in the chain configured namespaces " at /opt/approot/current/vendor/doctrine/persistence/src/Persistence/Mapping/MappingException.php
Problem seemed to be that I have a when#prod: section in my doctrine.config.yml. It seems I had to repeat the default_entity_manager over there:
when#prod:
doctrine:
orm:
default_entity_manager: general
# other prod-specific configuration
This fixed it for me.
Update: This is probably related to this issue: https://github.com/symfony/symfony/issues/27769

Unrecognized options "scheme, cluster, url" under "lopi_pusher"

I'm using LopiPusherBundle for Getting following error while clearing the cache in symfony 2.7.26
[Symfony\Component\Config\Definition\Exception\InvalidConfigurationException]
Unrecognized options "scheme, cluster, url" under "lopi_pusher"
# app/config/config.yml
lopi_pusher:
scheme: http
host: api.pusherapp.com
port: 80
cluster: ap2
timeout: 30
debug: false
app_id: <app_id>
key: <key>
secret: <secret>
url: <scheme>://<key>:<secret>#<host>[:<port>]/apps/<app-id>
auth_service_id: my_channel_authenticator
Your installed version is smaller than 1.3 and these options are not available.
You can see this here https://github.com/laupiFrpar/LopiPusherBundle/blob/1.2.9/DependencyInjection/Configuration.php
Check your composer.json and make sure the correct version is there
You can just use
"laupifrpar/pusher-bundle": "*"
Dont forget to update your dependency after modifying composer.json using
composer update "laupifrpar/pusher-bundle"

Unrecognized option "driver" under "sylius_money"

I have installed SyliusCartBundle following the docs and when I run "php app/console doctrine:schema:update --force" I get the following error:
[Symfony\Component\Config\Definition\Exception\InvalidConfigurationException]
Unrecognized option "driver" under "sylius_money"
My config.yml looks like in here http://sylius.readthedocs.org/en/latest/bundles/SyliusCartBundle/installation.html
#\app\config\config.yml
sylius_cart:
resolver: app.cart_item_resolver # The id of our newly created service.
classes: ~ # This key can be empty but it must be present in the configuration.
sylius_order:
driver: doctrine/orm
sylius_money:
driver: doctrine/orm
I've submitted a PR to update the docs for the Sylius CartBundle.
The configuration should be at its most simplistic:
sylius_money: ~
This equates to the default options, which are:
sylius_money:
currency: EUR
locale: en
However in Symfony, I'd recommend this setting:
sylius_money:
locale: %locale%
Where %locale% is the value taking from app/config/parameters.yml.

Symfony2 configure DB storage sessions

UPDATE: problem solved, see the comments (many issues, the versions differences was but one of them).
I'm trying to configure sessions in Symfony2 in config.yml file. I have the following configuration:
session:
default_locale: %locale%
lifetime: 7200
auto_start: true
storage_id: session.storage.pdo
parameters:
pdo.db_options:
db_table: session
db_id_col: session_id
db_data_col: session_value
db_time_col: session_time
services:
pdo:
class: PDO
arguments:
- "mysql:dbname=%database_name%"
- %database_user%
- %database_password%
session.storage.pdo:
class: Symfony\Component\HttpFoundation\SessionStorage\PdoSessionStorage
arguments: [#pdo, %session.storage.options%, %pdo.db_options%]
It's based on Symfony2's cookbook http://symfony.com/doc/2.0/cookbook/configuration/pdo_session_storage.html
I've created exactly the same table as in the given link.
However, it doesn't work. I get some "blank" error (no error message, but "PDO Exception" and "Error Exception"). I admit I have no much knowledge on configuring the Symfony2 or any info (that's why I'm using cookbook). I lost a lot of time and see no much documentation about it in the internet, not mentioning the fact that internet is quite silent about this case (having session storaged to DB table in Symfony2).
My NetBeans is "shouting" sth about the last line:
arguments: [#pdo, %session.storage.options%, %pdo.db_options%]
"ScannerException while scanning for the next token we had this found character #(64) that cannot start any token".
UPDATE:
Hmm now I'm not sure if it's about the configuration. I can see that Symfony2's cookbook (use... ) example doesn't match actually the file structure in the Symfony2's bundle. In a word, there is no such file-path, but after putting the real one it still doesn't work.
I had the same problem as you with Symfony 2.5. Turns out my solution was to disable session.auto_start in php.ini. The PdoSessionStorage will not take over if the session is being started before PDO has the opportunity to take control of it. I had overlooked this at first because I was modifying the wrong one (I had two copies of php.ini). To check if this is the problem on yours, run this command:
echo ini_get('session.auto_start');
If that returns a '1' or a 'true', then be sure to set this in your php.ini:
session.auto_start = 0
So for reference, here is my setup with Symfony 2.5 to make this work:
config.yml
framework:
session:
handler_id: session.handler.pdo
parameters:
pdo.db_options:
db_table: session
db_id_col: session_id
db_data_col: session_value
db_time_col: session_time
services:
session.handler.pdo:
class: Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler
arguments: ["#pdo", "%pdo.db_options%"]
pdo:
class: PDO
arguments:
dsn: "mysql:host=%database_host%;port=%database_port%;dbname=%database_name%"
user: "%database_user%"
password: "%database_password%"
calls:
- [setAttribute, [3, 2]] # \PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION

Resources