From 57d57f0fd0d656f3469fca358c53bd4644d997f6 Mon Sep 17 00:00:00 2001 From: Florian ALEXANDRE Date: Fri, 20 Sep 2019 18:52:49 +0200 Subject: [PATCH 1/2] feat: example implementation of a siteaccess aware entity manager --- app/config/config.yml | 23 ++++++++-- app/config/services.yml | 11 +++++ src/AppBundle/ORM/EntityManagerFactory.php | 49 ++++++++++++++++++++++ 3 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 src/AppBundle/ORM/EntityManagerFactory.php diff --git a/app/config/config.yml b/app/config/config.yml index 4765c683f8..598d44020c 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -17,7 +17,15 @@ parameters: doctrine: dbal: connections: - default: + connection1: + driver: '%database_driver%' + host: '%database_host%' + port: '%database_port%' + dbname: '%database_name%' + user: '%database_user%' + password: '%database_password%' + charset: '%database_charset%' + connection2: driver: '%database_driver%' host: '%database_host%' port: '%database_port%' @@ -27,8 +35,17 @@ doctrine: charset: '%database_charset%' orm: auto_generate_proxy_classes: '%kernel.debug%' - naming_strategy: doctrine.orm.naming_strategy.underscore - auto_mapping: true + default_entity_manager: siteaccessaware + entity_managers: + connection1: + connection: connection1 + mappings: + AppBundle: ~ + connection2: + connection: connection2 + mappings: + AppBundle: ~ + # If you are not using MySQL, you can comment-out this section ez_doctrine_schema: diff --git a/app/config/services.yml b/app/config/services.yml index 63dc7a1580..78cf2d7e0d 100644 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -13,3 +13,14 @@ services: # this means you cannot fetch services directly from the container via $container->get() # if you need to do this, you can override this setting on individual services public: false + + AppBundle\ORM\EntityManagerFactory: + arguments: + - '@ezpublish.api.repository_configuration_provider' + - '@doctrine' + + doctrine.orm.siteaccessaware_entity_manager: + class: '%doctrine.orm.entity_manager.class%' + factory: ['@AppBundle\ORM\EntityManagerFactory', getEntityManager] + lazy: true + public: true diff --git a/src/AppBundle/ORM/EntityManagerFactory.php b/src/AppBundle/ORM/EntityManagerFactory.php new file mode 100644 index 0000000000..1c13e920f3 --- /dev/null +++ b/src/AppBundle/ORM/EntityManagerFactory.php @@ -0,0 +1,49 @@ +repositoryConfigurationProvider = $repositoryConfigurationProvider; + $this->doctrineRegistry = $doctrineRegistry; + } + + public function getEntityManager(): EntityManagerInterface + { + $repositoryConfig = $this->repositoryConfigurationProvider->getRepositoryConfig(); + + if ( isset( $repositoryConfig['storage']['connection'] ) ) + { + return $this->doctrineRegistry->getManager($repositoryConfig['storage']['connection'] ); + } + + throw new InvalidArgumentException( + "Invalid Doctrine entity manager '{$repositoryConfig['storage']['connection']}' for repository '{$repositoryConfig['alias']}'." + ); + } +} From c91cbf13c4627c961b6f6c0b09b4e233234b3e9e Mon Sep 17 00:00:00 2001 From: Florian ALEXANDRE Date: Mon, 2 Dec 2019 10:16:02 +0100 Subject: [PATCH 2/2] feat: example implementation of a siteaccess aware entity manager --- app/config/cache_pool/cache.memcached.yml | 14 +++++++ app/config/cache_pool/cache.redis.yml | 18 +++++++++ .../cache_pool/cache.tagaware.filesystem.yml | 16 ++++++++ app/config/config.yml | 34 ++++++++++------- app/config/ezplatform.yml | 37 +++++++++++++++---- 5 files changed, 98 insertions(+), 21 deletions(-) diff --git a/app/config/cache_pool/cache.memcached.yml b/app/config/cache_pool/cache.memcached.yml index b0439a4252..04cde988d8 100644 --- a/app/config/cache_pool/cache.memcached.yml +++ b/app/config/cache_pool/cache.memcached.yml @@ -18,3 +18,17 @@ services: # If you prefer default behaviour set this to null or comment out, and consider for instance: # https://symfony.com/doc/current/reference/configuration/framework.html#prefix-seed namespace: '%cache_namespace%' + cache.memcached_1: + parent: cache.adapter.memcached + tags: + - name: cache.pool + clearer: cache.app_clearer + provider: 'memcached://%cache_dsn%' + namespace: '%cache_namespace%_1' + cache.memcached_2: + parent: cache.adapter.memcached + tags: + - name: cache.pool + clearer: cache.app_clearer + provider: 'memcached://%cache_dsn%' + namespace: '%cache_namespace%_2' diff --git a/app/config/cache_pool/cache.redis.yml b/app/config/cache_pool/cache.redis.yml index e47d416d52..f1c6d069f5 100644 --- a/app/config/cache_pool/cache.redis.yml +++ b/app/config/cache_pool/cache.redis.yml @@ -25,3 +25,21 @@ services: # If you prefer default behaviour set this to null or comment out, and consider for instance: # https://symfony.com/doc/current/reference/configuration/framework.html#prefix-seed namespace: '%cache_namespace%' + + cache.redis_1: + class: Symfony\Component\Cache\Adapter\TagAware\RedisTagAwareAdapter + parent: cache.adapter.redis + tags: + - name: cache.pool + clearer: cache.app_clearer + provider: 'redis://%cache_dsn%' + namespace: '%cache_namespace%_1' + + cache.redis_2: + class: Symfony\Component\Cache\Adapter\TagAware\RedisTagAwareAdapter + parent: cache.adapter.redis + tags: + - name: cache.pool + clearer: cache.app_clearer + provider: 'redis://%cache_dsn%' + namespace: '%cache_namespace%_2' diff --git a/app/config/cache_pool/cache.tagaware.filesystem.yml b/app/config/cache_pool/cache.tagaware.filesystem.yml index 3893f9f4bf..1fbba7620b 100644 --- a/app/config/cache_pool/cache.tagaware.filesystem.yml +++ b/app/config/cache_pool/cache.tagaware.filesystem.yml @@ -16,3 +16,19 @@ services: # If you prefer default behaviour set this to null or comment out, and consider for instance: # https://symfony.com/doc/current/reference/configuration/framework.html#prefix-seed namespace: '%cache_namespace%' + + cache.tagaware.filesystem_1: + class: Symfony\Component\Cache\Adapter\TagAware\FilesystemTagAwareAdapter + parent: cache.adapter.filesystem + tags: + - name: cache.pool + clearer: cache.app_clearer + namespace: '%cache_namespace%_1' + + cache.tagaware.filesystem_2: + class: Symfony\Component\Cache\Adapter\TagAware\FilesystemTagAwareAdapter + parent: cache.adapter.filesystem + tags: + - name: cache.pool + clearer: cache.app_clearer + namespace: '%cache_namespace%_2' diff --git a/app/config/config.yml b/app/config/config.yml index 598d44020c..86f432f6e3 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -17,19 +17,19 @@ parameters: doctrine: dbal: connections: - connection1: + connection_1: driver: '%database_driver%' host: '%database_host%' port: '%database_port%' - dbname: '%database_name%' + dbname: '%database_name%_1' user: '%database_user%' password: '%database_password%' charset: '%database_charset%' - connection2: + connection_2: driver: '%database_driver%' host: '%database_host%' port: '%database_port%' - dbname: '%database_name%' + dbname: '%database_name%_2' user: '%database_user%' password: '%database_password%' charset: '%database_charset%' @@ -37,12 +37,12 @@ doctrine: auto_generate_proxy_classes: '%kernel.debug%' default_entity_manager: siteaccessaware entity_managers: - connection1: - connection: connection1 + connection_1: + connection: connection_1 mappings: AppBundle: ~ - connection2: - connection: connection2 + connection_2: + connection: connection_2 mappings: AppBundle: ~ @@ -58,15 +58,23 @@ ez_doctrine_schema: # Can have several connections used by each eZ Repositories in ezplatform.yml ez_search_engine_solr: endpoints: - endpoint0: + endpoint_1: dsn: '%solr_dsn%' - core: '%solr_core%' + core: '%solr_core%_1' + endpoint_2: + dsn: '%solr_dsn%' + core: '%solr_core%_2' connections: - default: + connection_1: + entry_endpoints: + - endpoint_1 + mapping: + default: endpoint_1 + connection_2: entry_endpoints: - - endpoint0 + - endpoint_2 mapping: - default: endpoint0 + default: endpoint_2 framework: esi: ~ diff --git a/app/config/ezplatform.yml b/app/config/ezplatform.yml index 5e369637cd..7645facbde 100644 --- a/app/config/ezplatform.yml +++ b/app/config/ezplatform.yml @@ -5,23 +5,34 @@ ezpublish: # Repositories configuration, setup default repository to support solr if enabled repositories: - default: - storage: ~ + repository_1: + storage: + engine: legacy + connection: connection_1 + search: + engine: '%search_engine%' + connection: connection_1 + repository_2: + storage: + engine: legacy + connection: connection_2 search: engine: '%search_engine%' - connection: default + connection: connection_2 # Siteaccess configuration, with one siteaccess per default siteaccess: - list: [site, admin] + list: [site1, admin1, site2, admin2] groups: - site_group: [site] + site_group: [site1, site2] + site1_group: [site1, admin1] + site2_group: [site2, admin2] # WARNING: Do not remove or rename this group. # It's used to distinguish common siteaccesses from admin ones. # In case of multisite with multiple admin panels, remember to add any additional admin siteaccess to this group. - admin_group: [admin] - default_siteaccess: site + admin_group: [admin1, admin2] + default_siteaccess: site1 match: URIElement: 1 @@ -48,6 +59,14 @@ ezpublish: #site_group: # design: main + site1_group: + cache_service_name: '%cache_pool%_1' + var_dir: var/site1 + + site2_group: + cache_service_name: '%cache_pool%_2' + var_dir: var/site2 + admin_group: # System languages. Note that by default, content, content types, and other data are in eng-GB locale, # so removing eng-GB from this list may lead to errors or content not being shown, unless you change @@ -64,7 +83,9 @@ ezpublish: content: /1/2/ media: /1/43/ - site: + site2: + languages: [eng-GB] + site1: languages: [eng-GB] url_alias: