I am using APCu caching for doctine's query and metadata caches.
I know that one can wrap a cache into a TraceableAdapter such that its statistics are shown in the web profiler.
How can I define doctrine's caches to be a TracableAdapter?
Meanwhile the doctrine cache package has been deprecated. The recommended way to use a cache is to define a pool, together with an corresponding doctrine adapter service which can then be used in doctrine's config, see below. By that, the pool automatically shows up nicely in the debug tool bar / profiler.
framework:
cache:
default_redis_provider: 'redis://%env(REDIS_HOST)%/%env(REDIS_DB)%'
pools:
doctrine.metadata_cache_pool:
adapter: cache.adapter.redis
default_lifetime: 0
services:
doctrine.metadata_cache_provider:
class: Symfony\Component\Cache\DoctrineProvider
public: false
arguments:
- '#doctrine.metadata_cache_pool'
doctrine:
orm:
metadata_cache_driver:
type: service
id: doctrine.metadata_cache_provider
Related
Api-Platform: v2.5.6, Symfony: v4.4.11
I am building an API with multiple DataSource. For now, one from Postgres, another from ElasticSearch.
For example, I have an Organization entity from postgres and a Stats entity from ElasticSearch.
If ElasticSearch service isn't reachable, I would like the /organizations route to be ok because they don't need ElasticSearch to work.
For now I get "No alive nodes found in your cluster" because it tries to communicate with the "/_cat/indices/organization" route of ElasticSearch.
This dives me to a questions, if it tries everytime to communicate to both ElasticSearch and Postgres, whatever the entity.
How to prevent this, for example can I say that an entity is mapped with a DataSource and not another ?
Or maybe at least set a priority ?
My app/config/packages/api_platform.yaml
api_platform:
allow_plain_identifiers: true
title: HeyAPI Documentation
version: 2.0.0
formats:
jsonld: ['application/ld+json']
json: ['application/json']
graphql: ['application/graphql'] #https://graphql.org/learn/serving-over-http/#post-request
mapping:
paths:
- '%kernel.project_dir%/config/api_platform'
patch_formats:
json: ['application/merge-patch+json']
elasticsearch:
hosts: ['%env(ELASTICSEARCH_URL)%']
swagger:
versions: [3]
api_keys:
Bearer:
name: Authorization
type: header
Do you have an example configuration to send logs by email with the Mailer component of Symfony 5.1.
In the Symfony blog we announce this feature, but I can't put the right config in monolog.yaml
https://symfony.com/blog/new-in-symfony-5-1-misc-improvements-part-3 :
That's why in Symfony 5.1 we added a new Monolog log handler which uses the Mailer component to send the logs via email.
Unfortunately this addition only covers the actuall MailerHandler class in the monolog-bridge. This does not cover the possibility to configure it in the monolog-bundle (that's the drawback if those components are distributed over multiple packages).
The PR for the change in the monolog-bundle is still open, and can be found here: Add Symfony Mailer support #354.
If you don't want to wait for the change in the monolog-bundle you could already use it by defining the handler as a service and then using it with the service type in the monolog configuration.
So define your service:
services:
# this configures the "mail" as a prototype, so you can
# define the sender and recipient mail addresses here
symfony_mailer_service_template:
class: Symfony\Component\Mime\Email
calls:
- ['from', ['webapp#example.com']]
- ['to', ['ops#example.com']]
- ['subject', ['Logs']]
symfony_mailer_service:
class: Symfony\Bridge\Monolog\Handler\MailerHandler
arguments:
- '#mailer.mailer'
- '#symfony_mailer_service_template'
- !php/const Monolog\Logger::DEBUG # log level
- true # bubble
And then in your mailer configuration you could use it like this:
monolog:
handlers:
main:
type: fingers_crossed
handler: deduplicated
deduplicated:
type: deduplication
handler: symfony_mailer
symfony_mailer:
type: service
id: symfony_mailer_service
I plan to move my web site to a cloud one. I've been told there is some micro-interruptions in some services.
Therefore I'd like to configure a connection retry for the redis cache set up.
I'm using Symfony 4.2 with this configuration
framework:
cache:
app: cache.adapter.redis
default_redis_provider: '%env(REDIS_URL)%'
Is there any way to configure the retry_interval option of redis in Symfony ?
EDIT : including precisions of #simon.ro
Redis has an option retry_interval which you can specify at connect-time. You should check the documentation of the redis connecting library you are using.
The default_redis_provider is a DSN that will be parsed with parse_url function
So you can add parameters into query string like this :
default_redis_provider: 'redis://u:pass#localhost/2:6379?retry_interval=300&timeout=10&read_timeout=30&tcp_keepalive=10'
path of url /2 is the dbindex of redis
I am trying to implement paypal-rest payment with the payum bundle in symfony (3.1.4).
I need to get PayPal Plus running in my Symfony App.
Therefore I read this article
https://github.com/Payum/Payum/blob/master/docs/paypal/rest/get-it-started.md
Now - I can't figure out what the 'config_path' parameter is ment to be set to and what exactly has to be provides at this config_path.
Symfony states
'The config_path fields are required.'
My payum config looks like this atm
payum:
security:
token_storage:
AppBundle\Entity\PaymentToken: { doctrine: orm }
storages:
AppBundle\Entity\Payment: { doctrine: orm }
gateways:
paypal_express_payment:
factory: paypal_express_checkout
username: "%ppe_uname%"
password: "%ppe_pw%"
signature: "%ppe_signature%"
sandbox: false
paypal_rest_payment:
factory: paypal_rest
client_id: "%ppr_cid%"
client_secret: "%ppr_sec%"
sandbox: true
The paypal_express_payment part works fine.
If I add just a random config-path like 'my_config.txt' Symfony states
Request GetHumanStatus{model: ArrayObject} is not supported. Make sure the gateway supports the requests and there is an action which supports this request (The method returns true). There may be a bug, so look for a related issue on the issue tracker.
So - where and what is the config_path ment to be?
Any help or hints for more documentation that can lead into the right direction is very welcome.
It's meant to be sdk_config.ini from PayPal-PHP-SDK
gateways:
paypal_rest:
factory: paypal_rest
client_id: '%paypal_rest.client_id%'
client_secret: '%paypal_rest.client_secret%'
config_path: '%kernel.root_dir%/config/sdk_config.ini'
UPDATE: I don't think that Doctrine ORM storage is supported by Payum PaypalRest plugin.
PaypalRest\Action\CaptureAction requires the model (Payment) to be inherited from PayPal\Api\Payment and then it uses its create and execute methods for payment capture. I don't think it's a good idea to extend from PayPal\Api\Payment in the Doctrine entity.
I was able to eliminate this error by using Payum\Paypal\Rest\Model\PaymentDetails as a payment and filesystem as a storage:
payum:
storages:
Payum\Paypal\Rest\Model\PaymentDetails:
filesystem:
storage_dir: %kernel.root_dir%/Resources/payments
id_property: idStorage
Try to set it to default value like this:
paypal_rest_payment:
factory: paypal_rest
client_id: "%ppr_cid%"
client_secret: "%ppr_sec%"
sandbox: true
config_path: ~
I am trying to define a Bundle that helps to index some data (from an Entity) within a sqlite fts table, in order to do some full-text search.
I know I can define alternate connection and Entity Manager using the app config file (like shown in the cookbook), but I was wondering if it was possible to do so within the bundle configuration - by defining, for example, a service with the doctrine service injected, so that it can instantiate a new connection.
Sqlite is not mandatory, it can be any database type (supported by doctrine).
Thanks in advance for your help.
I would suggest looking at FOSUserBundle for how they handle multiple persistence layers (ORM, Couch, MongoDB). You would essentially be doing the same thing. It's just a matter of loading different configurations depending on the driver specified in app/config/config.yml.
As far as i know it it not possible. Also database connections should be managed centralized in app/config.yml.
I would suggest to define the connection there and add a configuration option to you bundle where you can specify wich connection to use for the indexing stuff.
# app/config.yml
doctrine:
dbal:
default_connection: default
connections:
default:
dbname: database
host: localhost
user: user
password: secret
driver: pdo_mysql
my_data_index:
dbname: database
driver: pdo_sqlite
# configuration option of you bundle
acme_indexer:
connection: my_data_index
Then in your bundle you can read this config option and obtain the connection/entity manager and inject it into your indexing service.
Edit:
You can for sure create a custom connection programaticly in your bundle
$params = array(
'driver' =>'pdo_sqlite',
....
);
$factory = $container->get('doctrine.dbal.connection_factory')
$connection = $factory->createConnection($params);
But as i said before it is bad practice because you would evade the symfony standart way of defining database connections.