Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: example implementation of a siteaccess aware entity manager #457

Draft
wants to merge 2 commits into
base: 2.5
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions app/config/cache_pool/cache.memcached.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
18 changes: 18 additions & 0 deletions app/config/cache_pool/cache.redis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
16 changes: 16 additions & 0 deletions app/config/cache_pool/cache.tagaware.filesystem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
43 changes: 34 additions & 9 deletions app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,35 @@ parameters:
doctrine:
dbal:
connections:
default:
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%'
connection_2:
driver: '%database_driver%'
host: '%database_host%'
port: '%database_port%'
dbname: '%database_name%_2'
user: '%database_user%'
password: '%database_password%'
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:
connection_1:
connection: connection_1
mappings:
AppBundle: ~
connection_2:
connection: connection_2
mappings:
AppBundle: ~


# If you are not using MySQL, you can comment-out this section
ez_doctrine_schema:
Expand All @@ -41,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%_1'
endpoint_2:
dsn: '%solr_dsn%'
core: '%solr_core%'
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: ~
Expand Down
37 changes: 29 additions & 8 deletions app/config/ezplatform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -64,7 +83,9 @@ ezpublish:
content: /1/2/
media: /1/43/

site:
site2:
languages: [eng-GB]
site1:
languages: [eng-GB]

url_alias:
Expand Down
11 changes: 11 additions & 0 deletions app/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
49 changes: 49 additions & 0 deletions src/AppBundle/ORM/EntityManagerFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
declare( strict_types=1 );

namespace AppBundle\ORM;

use Doctrine\Bundle\DoctrineBundle\Registry;
use Doctrine\ORM\EntityManagerInterface;
use eZ\Bundle\EzPublishCoreBundle\ApiLoader\RepositoryConfigurationProvider;
use InvalidArgumentException;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;

class EntityManagerFactory
{

use ContainerAwareTrait;

/**
* @var \eZ\Bundle\EzPublishCoreBundle\ApiLoader\RepositoryConfigurationProvider
*/
protected $repositoryConfigurationProvider;

/** @var \Doctrine\Bundle\DoctrineBundle\Registry */
protected $doctrineRegistry;

/**
* EntityManagerFactory constructor.
* @param RepositoryConfigurationProvider $repositoryConfigurationProvider
* @param \Doctrine\Bundle\DoctrineBundle\Registry $doctrineRegistry
*/
public function __construct( RepositoryConfigurationProvider $repositoryConfigurationProvider, Registry $doctrineRegistry )
{
$this->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']}'."
);
}
}