Listener "SoftDeleteableListener" was not added to the EventManager. Soft delete works but i can't register softdeleteable filter - doctrine

I'm having issues with soft delete from "stof/doctrine-extensions-bundle" package. I'm running Symfony 5.4.
SoftDelete functionality actually works fine, but I can't set up the softdeleteable filter.
This is my config/packages/doctrine.yaml file:
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL)%'
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
is_bundle: false
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
filters:
softdeleteable:
class: Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter
enabled: true
This is my config/packages/stof_doctrine_extensions.yaml file:
stof_doctrine_extensions:
default_locale: en_US
orm:
default:
softdeleteable: true
And, this is part of my config/services.yaml file:
services:
gedmo.listener.softdeleteable:
class: Gedmo\SoftDeleteable\SoftDeleteableListener
tags:
- { name: doctrine.event_subscriber, connection: default }
calls:
- [ setAnnotationReader, [ "#annotation_reader" ] ]
When I try to delete some entity, it works fine, it updates deletedAt field. But, I want to add softdeleteable filter, and that's when the things stop working. I added gedmo.listener.softdeleteable service to services.yaml and filters part to doctrine.yaml, and i get this error:
Listener "SoftDeleteableListener" was not added to the EventManager!
I can't figure out where I'm making a mistake, and there's not a lot of help in docs.

See: https://github.com/doctrine-extensions/DoctrineExtensions/issues/2535
Looks like caused by symfony/doctrine bridge package. Try upgrade to latest 5.4 version.

Related

Symfony 5.2 Multiple Entity Managers strange behaviour

I'm trying to use multiple entity managers as described here.
Example code in controller where $shop variable holds the name of the manager:
$rp = new RemoteProduct();
$rp->setProducts(array(2000,2001,2002));
$em = $this->getDoctrine()->getManager($shop);
$em->persist($rp);
$em->flush();
$repo = $em->getRepository(RemoteProduct::class, $shop);
$repo->findAll();
Generates queries to both managers. Flush as a transaction in the correct DB, but select queries are executed in the default DB instead. Any ideas?
doctrine:
dbal:
default_connection: shop1
connections:
shop1:
url: '%env(resolve:DATABASE_URL)%'
mapping_types:
enum: string
store2:
url: '%env(resolve:DATABASE_URL_STORE)%'
mapping_types:
enum: string
orm:
auto_generate_proxy_classes: true
default_entity_manager: shop1
entity_managers:
shop1:
connection: shop1
mappings:
shop1:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: shop1
store2:
connection: store2
mappings:
store2:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: store2
It happens that big fat warning at the end of the documentation was ignored by me.
Do not extend repository class from ServiceEntityRepository
In order to fix this situation, extend EntityRepository instead and no longer rely on autowiring:

Call service from existing api gateway using base path mappings

Our API has the following endpoints:
POST /users - create a user
GET /users/{userId} - get a particular user
GET /posts/{postId} - get a particular post
GET /posts/{postId}/users - get the users who contributed to this post
I have defined two services: users-service and posts-service. In these two services I define the lambdas like so. I'm using the serverless-domain-manager plugin to create base path mappings:
/users-service/serverless.yaml:
service: users-service
provider:
name: aws
runtime: nodejs10.x
stage: dev
plugins:
- serverless-domain-manager
custom:
customDomain:
domainName: 'serverlesstesting.example.com'
basePath: 'users'
stage: ${self:provider.stage}
createRoute53Record: true
functions:
create:
name: userCreate
handler: src/create.handler
events:
- http:
path: /
method: post
get:
name: userGet
handler: src/get.handler
events:
- http:
path: /{userId}
method: get
/rooms-service/serverless.yaml:
service: posts-service
provider:
name: aws
runtime: nodejs10.x
stage: dev
plugins:
- serverless-domain-manager
custom:
customDomain:
domainName: 'serverlesstesting.example.com'
basePath: 'posts'
stage: ${self:provider.stage}
createRoute53Record: true
functions:
get:
name: postsGet
handler: src/get.handler
events:
- http:
path: /{postId}
method: get
getUsersForPost:
handler: userGet ?
events: ??
The problem is that the GET /posts/{postId}/users actually calls the same userGet lambda from the users-service. But the source for that lambda lives in the users-service, not the posts-service.
So my question becomes:
How do I reference a service from another service using base path mappings? In other words, is it possible for the posts service to actually make a call to the parent custom domain and into the users base path mapping and its service?
Consider or refer below approach
https://serverless-stack.com/chapters/share-an-api-endpoint-between-services.html

Codeception: DB is not rolling back in API testing

I am testing some certain parts of my API and have noticed that a specific table the DB is not rolling back when my test fail.
Here is my api.suite.yml file:
class_name: ApiTester
modules:
enabled:
- REST:
depends: Laravel5
- \Helper\Api
- Db
And this is my code in codeception.yml:
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
settings:
bootstrap: _bootstrap.php
colors: true
memory_limit: 1024M
extensions:
enabled:
- Codeception\Extension\RunFailed
modules:
config:
Db:
dsn: 'mysql:host=127.0.0.1;dbname=test_records'
user: 'root'
password: ''
dump: 'tests/_data/dump.sql'
populate: true
cleanup: true
reconnect: true
Any pointers would be highly appreciated.

how to generate swagger document with tags using serverless-aws-documentation plugin for serverless

I am using serverless-aws-documentation plugin to auto-generate swagger-doc. Followed all the steps provided at : https://github.com/9cookies/serverless-aws-documentation. Under documentation key I am defining tags but it is not getting generated in the output swagger doc. Following is the sample handler :
functions:
get_tickets:
handler: handler.ticket_handler.get_tickets
events:
- http:
path: tickets
method: get
cors: true
documentation:
tags:
- private
- admin
summary: "Get list of ticket"
description: "This ticket will provide you list of tickets"
I want to segrigate APIs depending on the tags, but not able to achieve it. Thanks in advance for the help.
Try to add the serverless-aws-documentation plugin in the serverless.yml
plugins:
- serverless-aws-documentation
Add the infor and models documentation in the custom section:
custom:
myStage: ${opt:stage, self:provider.stage}
profiles:
dev: road-we-go
prod: road-we-
documentation:
info:
version: "1.0.0"
name: "Example API"
description: "Example API description"
termsOfService: "https://example.com/terms-of-service"
contact:
name: "Example API"
url: "https://example.com"
email: "dev#example.com"
licence:
name: "Licensing"
url: "https://example.com/licensing"
models:
-
name: "StoreAudioSuccess"
description: "Model for store audio"
contentType: "application/json"
schema: ${file(swagger/audios/storeResponse.
Add the function documentation:
If you want to add the custom models like RequestStore and StoreAudioSuccess check the serverless-aws-documentation documentation and the json-schema docs
functions:
Update:
handler: src/functions/update.handler
timeout: 30
memory: 128
events:
- http:
method: put
private: true
cors: true
path: api/v1/update
documentation:
summary: "Update "
description: "Update a record"
tags:
- "Users"
requestModels:
"application/json": "RequestStore"
methodResponses:
-
statusCode: "200"
responseModels:
"application/json": "StoreUserSuccess"
To download the swagger documentation you need to run this command:
First you need to deploy you project
sls downloadDocumentation --outputFileName=swagger.json
Which version are you using?
According to their latest documentation https://github.com/9cookies/serverless-aws-documentation, you need to provide tags as follows i.e. within double quotes.
documentation:
tags:
- "private"
- "admin"

JHipster test: NoCacheRegionFactoryAvailableException when second level cache is disabled

When I use jhipster generate an app, I disabled the second level cache. However, when I run either "gradle test" or "run as junit test" to test the app, it is failed because the "NoCacheRegionFactoryAvailableException". I have checked the application.yml in directory "src/test/resources/config", and be sure that the second cache is disabled. I do not know why the app is still looking for second-cache. Is there any clue how this happen? or how to disable second level cache completely?
Except the test failure, everything else works well, the app can run successfully.
application.yml in src/test/resources/config
spring:
application:
name: EMS
datasource:
url: jdbc:h2:mem:EMS;DB_CLOSE_DELAY=-1
name:
username:
password:
jpa:
database-platform: com.espion.ems.domain.util.FixedH2Dialect
database: H2
open-in-view: false
show_sql: true
hibernate:
ddl-auto: none
naming-strategy: org.springframework.boot.orm.jpa.hibernate.SpringNamingStrategy
properties:
hibernate.cache.use_second_level_cache: false
hibernate.cache.use_query_cache: false
hibernate.generate_statistics: true
hibernate.hbm2ddl.auto: validate
data:
elasticsearch:
cluster-name:
cluster-nodes:
properties:
path:
logs: target/elasticsearch/log
data: target/elasticsearch/data
mail:
host: localhost
mvc:
favicon:
enabled: false
thymeleaf:
mode: XHTML
liquibase:
contexts: test
security:
basic:
enabled: false
server:
port: 10344
address: localhost
jhipster:
async:
corePoolSize: 2
maxPoolSize: 50
queueCapacity: 10000
security:
rememberMe:
# security key (this key should be unique for your application, and kept secret)
key: jhfasdhflasdhfasdkfhasdjkf
metrics: # DropWizard Metrics configuration, used by MetricsConfiguration
jmx.enabled: true
swagger:
title: EMS API
description: EMS API documentation
version: 0.0.1
termsOfServiceUrl:
contactName:
contactUrl:
contactEmail:
license:
licenseUrl:
enabled: false
Move src/test/resources/config/application.yml to src/test/resources directory.
You can find that solution from https://github.com/jhipster/generator-jhipster/issues/3730

Resources