Skip to content

Commit

Permalink
feat: Moved Log entity to a different namespace to handle with a di…
Browse files Browse the repository at this point in the history
…fferent entity-manager and avoid flushing Log in the same transaction with other entities

BREAKING CHANGE: Log namespace changed to `RZ\Roadiz\CoreBundle\Logger\Entity\Log`

Make sure you update `config/packages/doctrine.yaml` with:

```yaml
    orm:
        auto_generate_proxy_classes: true
        default_entity_manager: default
        entity_managers:
            # Put `logger` entity manager first to select it as default for Log entity
            logger:
                naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
                mappings:
                    ## Just sharding EM to avoid having Logs in default EM
                    ## and flushing bad entities when storing log entries.
                    RoadizCoreLogger:
                        is_bundle: false
                        type: attribute
                        dir: '%kernel.project_dir%/vendor/roadiz/core-bundle/src/Logger/Entity'
                        prefix: 'RZ\Roadiz\CoreBundle\Logger\Entity'
                        alias: RoadizCoreLogger
            default:
                dql:
                    string_functions:
                        JSON_CONTAINS: Scienta\DoctrineJsonFunctions\Query\AST\Functions\Mysql\JsonContains
                naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
                auto_mapping: true
                mappings:
                    ## Keep RoadizCoreLogger to avoid creating different migrations since we are using
                    ## the same database for both entity managers. Just sharding EM to avoid
                    ## having Logs in default EM and flushing bad entities when storing log entries.
                    RoadizCoreLogger:
                        is_bundle: false
                        type: attribute
                        dir: '%kernel.project_dir%/vendor/roadiz/core-bundle/src/Logger/Entity'
                        prefix: 'RZ\Roadiz\CoreBundle\Logger\Entity'
                        alias: RoadizCoreLogger
                    App:
                        is_bundle: false
                        type: attribute
                        dir: '%kernel.project_dir%/src/Entity'
                        prefix: 'App\Entity'
                        alias: App
	            # ...
```
  • Loading branch information
ambroisemaupate committed Jul 12, 2023
1 parent bed7bb4 commit 6d2583c
Show file tree
Hide file tree
Showing 67 changed files with 226 additions and 508 deletions.
118 changes: 70 additions & 48 deletions config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,55 +6,77 @@ doctrine:
# either here or in the DATABASE_URL env var (see .env file)
#server_version: '13'
orm:
dql:
string_functions:
JSON_CONTAINS: Scienta\DoctrineJsonFunctions\Query\AST\Functions\Mysql\JsonContains
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
RoadizCoreBundle:
is_bundle: true
type: attribute
dir: 'src/Entity'
prefix: 'RZ\Roadiz\CoreBundle\Entity'
alias: RoadizCoreBundle
RoadizFontBundle:
is_bundle: true
type: attribute
dir: 'src/Entity'
prefix: 'RZ\Roadiz\FontBundle\Entity'
alias: RoadizFontBundle
RoadizUserBundle:
is_bundle: true
type: attribute
dir: 'src/Entity'
prefix: 'RZ\Roadiz\UserBundle\Entity'
alias: RoadizUserBundle
RZ\Roadiz\Core:
is_bundle: false
type: attribute
dir: '%kernel.project_dir%/lib/Models/src/Core/AbstractEntities'
prefix: 'RZ\Roadiz\Core\AbstractEntities'
alias: AbstractEntities
App\GeneratedEntity:
is_bundle: false
type: attribute
dir: '%kernel.project_dir%/src/GeneratedEntity'
prefix: 'App\GeneratedEntity'
alias: App\GeneratedEntity
App:
is_bundle: false
type: attribute
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
gedmo_loggable:
type: attribute
prefix: Gedmo\Loggable\Entity\MappedSuperclass
dir: "%kernel.project_dir%/vendor/gedmo/doctrine-extensions/src/Loggable/Entity/MappedSuperclass"
alias: GedmoLoggableMappedSuperclass
is_bundle: false
default_entity_manager: default
entity_managers:
# Put `logger` entity manager first to select it as default for Log entity
logger:
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
mappings:
RoadizCoreLogger:
is_bundle: false
type: attribute
dir: '%kernel.project_dir%/lib/RoadizCoreBundle/src/Logger/Entity'
prefix: 'RZ\Roadiz\CoreBundle\Logger\Entity'
alias: RoadizCoreLogger
default:
dql:
string_functions:
JSON_CONTAINS: Scienta\DoctrineJsonFunctions\Query\AST\Functions\Mysql\JsonContains
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
## Keep RoadizCoreLogger to avoid migrations overlap since we are using
## the same database for both entity managers. Just sharding EM to avoid
## having Logs in default EM and flushing bad entities when storing log entries.
RoadizCoreLogger:
is_bundle: false
type: attribute
dir: '%kernel.project_dir%/lib/RoadizCoreBundle/src/Logger/Entity'
prefix: 'RZ\Roadiz\CoreBundle\Logger\Entity'
alias: RoadizCoreLogger
RoadizCoreBundle:
is_bundle: true
type: attribute
dir: 'src/Entity'
prefix: 'RZ\Roadiz\CoreBundle\Entity'
alias: RoadizCoreBundle
RoadizFontBundle:
is_bundle: true
type: attribute
dir: 'src/Entity'
prefix: 'RZ\Roadiz\FontBundle\Entity'
alias: RoadizFontBundle
RoadizUserBundle:
is_bundle: true
type: attribute
dir: 'src/Entity'
prefix: 'RZ\Roadiz\UserBundle\Entity'
alias: RoadizUserBundle
RZ\Roadiz\Core:
is_bundle: false
type: attribute
dir: '%kernel.project_dir%/lib/Models/src/Core/AbstractEntities'
prefix: 'RZ\Roadiz\Core\AbstractEntities'
alias: AbstractEntities
App\GeneratedEntity:
is_bundle: false
type: attribute
dir: '%kernel.project_dir%/src/GeneratedEntity'
prefix: 'App\GeneratedEntity'
alias: App\GeneratedEntity
App:
is_bundle: false
type: attribute
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
gedmo_loggable:
type: attribute
prefix: Gedmo\Loggable\Entity\MappedSuperclass
dir: "%kernel.project_dir%/vendor/gedmo/doctrine-extensions/src/Loggable/Entity/MappedSuperclass"
alias: GedmoLoggableMappedSuperclass
is_bundle: false

resolve_target_entities:
Symfony\Component\Security\Core\User\UserInterface: RZ\Roadiz\CoreBundle\Entity\User
Expand Down
2 changes: 1 addition & 1 deletion lib/RoadizCompatBundle/src/Aliases.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static function getAliases(): array
\RZ\Roadiz\CoreBundle\Entity\Folder::class => \RZ\Roadiz\Core\Entities\Folder::class,
\RZ\Roadiz\CoreBundle\Entity\FolderTranslation::class => \RZ\Roadiz\Core\Entities\FolderTranslation::class,
\RZ\Roadiz\CoreBundle\Entity\Group::class => \RZ\Roadiz\Core\Entities\Group::class,
\RZ\Roadiz\CoreBundle\Entity\Log::class => \RZ\Roadiz\Core\Entities\Log::class,
\RZ\Roadiz\CoreBundle\Logger\Entity\Log::class => \RZ\Roadiz\Core\Entities\Log::class,
\RZ\Roadiz\CoreBundle\Entity\Node::class => \RZ\Roadiz\Core\Entities\Node::class,
\RZ\Roadiz\CoreBundle\Entity\NodeType::class => \RZ\Roadiz\Core\Entities\NodeType::class,
\RZ\Roadiz\CoreBundle\Entity\NodeTypeField::class => \RZ\Roadiz\Core\Entities\NodeTypeField::class,
Expand Down
96 changes: 60 additions & 36 deletions lib/RoadizCoreBundle/config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,67 @@ doctrine:
# either here or in the DATABASE_URL env var (see .env file)
#server_version: '13'
orm:
dql:
string_functions:
JSON_CONTAINS: Scienta\DoctrineJsonFunctions\Query\AST\Functions\Mysql\JsonContains
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
is_bundle: false
type: attribute
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
RoadizCoreBundle:
is_bundle: true
type: attribute
dir: 'src/Entity'
prefix: 'RZ\Roadiz\CoreBundle\Entity'
alias: RoadizCoreBundle
RZ\Roadiz\Core:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/vendor/roadiz/models/src/Core/AbstractEntities'
prefix: 'RZ\Roadiz\Core\AbstractEntities'
alias: AbstractEntities
App\GeneratedEntity:
is_bundle: false
type: attribute
dir: '%kernel.project_dir%/src/GeneratedEntity'
prefix: 'App\GeneratedEntity'
alias: App\GeneratedEntity
gedmo_loggable:
type: attribute
prefix: Gedmo\Loggable\Entity\MappedSuperclass
dir: "%kernel.project_dir%/vendor/gedmo/doctrine-extensions/src/Loggable/Entity/MappedSuperclass"
alias: GedmoLoggableMappedSuperclass
is_bundle: false
default_entity_manager: default
entity_managers:
# Put `logger` entity manager first to select it as default for Log entity
logger:
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
mappings:
## Just sharding EM to avoid having Logs in default EM
## and flushing bad entities when storing log entries.
RoadizCoreLogger:
is_bundle: false
type: attribute
dir: '%kernel.project_dir%/vendor/roadiz/core-bundle/src/Logger/Entity'
prefix: 'RZ\Roadiz\CoreBundle\Logger\Entity'
alias: RoadizCoreLogger
default:
dql:
string_functions:
JSON_CONTAINS: Scienta\DoctrineJsonFunctions\Query\AST\Functions\Mysql\JsonContains
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
## Keep RoadizCoreLogger to avoid creating different migrations since we are using
## the same database for both entity managers. Just sharding EM to avoid
## having Logs in default EM and flushing bad entities when storing log entries.
RoadizCoreLogger:
is_bundle: false
type: attribute
dir: '%kernel.project_dir%/vendor/roadiz/core-bundle/src/Logger/Entity'
prefix: 'RZ\Roadiz\CoreBundle\Logger\Entity'
alias: RoadizCoreLogger
App:
is_bundle: false
type: attribute
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
RoadizCoreBundle:
is_bundle: true
type: attribute
dir: 'src/Entity'
prefix: 'RZ\Roadiz\CoreBundle\Entity'
alias: RoadizCoreBundle
RZ\Roadiz\Core:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/vendor/roadiz/models/src/Core/AbstractEntities'
prefix: 'RZ\Roadiz\Core\AbstractEntities'
alias: AbstractEntities
App\GeneratedEntity:
is_bundle: false
type: attribute
dir: '%kernel.project_dir%/src/GeneratedEntity'
prefix: 'App\GeneratedEntity'
alias: App\GeneratedEntity
gedmo_loggable:
type: attribute
prefix: Gedmo\Loggable\Entity\MappedSuperclass
dir: "%kernel.project_dir%/vendor/gedmo/doctrine-extensions/src/Loggable/Entity/MappedSuperclass"
alias: GedmoLoggableMappedSuperclass
is_bundle: false

resolve_target_entities:
Symfony\Component\Security\Core\User\UserInterface: RZ\Roadiz\CoreBundle\Entity\User
Expand Down
2 changes: 1 addition & 1 deletion lib/RoadizCoreBundle/src/Console/LogsCleanupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Doctrine\ORM\NoResultException;
use Doctrine\Persistence\ManagerRegistry;
use RZ\Roadiz\CoreBundle\Entity\Log;
use RZ\Roadiz\CoreBundle\Logger\Entity\Log;
use RZ\Roadiz\CoreBundle\Repository\LogRepository;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Exception\InvalidArgumentException;
Expand Down
2 changes: 1 addition & 1 deletion lib/RoadizCoreBundle/src/Logger/DoctrineHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
use Monolog\Handler\AbstractProcessingHandler;
use Monolog\Logger;
use RZ\Roadiz\Core\AbstractEntities\PersistableInterface;
use RZ\Roadiz\CoreBundle\Entity\Log;
use RZ\Roadiz\CoreBundle\Entity\Node;
use RZ\Roadiz\CoreBundle\Entity\NodesSources;
use RZ\Roadiz\CoreBundle\Entity\User;
use RZ\Roadiz\CoreBundle\Logger\Entity\Log;
use RZ\Roadiz\Documents\Models\DocumentInterface;
use RZ\Roadiz\Documents\UrlGenerators\DocumentUrlGeneratorInterface;
use Symfony\Component\HttpFoundation\Request;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

declare(strict_types=1);

namespace RZ\Roadiz\CoreBundle\Entity;
namespace RZ\Roadiz\CoreBundle\Logger\Entity;

use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
use Monolog\Logger;
use RZ\Roadiz\Core\AbstractEntities\AbstractEntity;
use JMS\Serializer\Annotation as Serializer;
use RZ\Roadiz\CoreBundle\Entity\NodesSources;
use RZ\Roadiz\CoreBundle\Entity\User;
use RZ\Roadiz\CoreBundle\Repository\LogRepository;
use Symfony\Component\Serializer\Annotation as SymfonySerializer;
use Symfony\Component\Validator\Constraints as Assert;
Expand Down
2 changes: 1 addition & 1 deletion lib/RoadizCoreBundle/src/Repository/LogRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
use Doctrine\ORM\QueryBuilder;
use Doctrine\ORM\Tools\Pagination\Paginator;
use Doctrine\Persistence\ManagerRegistry;
use RZ\Roadiz\CoreBundle\Entity\Log;
use RZ\Roadiz\CoreBundle\Entity\Node;
use RZ\Roadiz\CoreBundle\Entity\NodesSources;
use RZ\Roadiz\CoreBundle\Logger\Entity\Log;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
use RZ\Roadiz\CoreBundle\Doctrine\Event\QueryBuilder\QueryBuilderNodesSourcesBuildEvent;
use RZ\Roadiz\CoreBundle\Doctrine\Event\QueryNodesSourcesEvent;
use RZ\Roadiz\CoreBundle\Doctrine\ORM\SimpleQueryBuilder;
use RZ\Roadiz\CoreBundle\Entity\Log;
use RZ\Roadiz\CoreBundle\Entity\Node;
use RZ\Roadiz\CoreBundle\Entity\NodesSources;
use RZ\Roadiz\CoreBundle\Exception\SolrServerNotAvailableException;
use RZ\Roadiz\CoreBundle\Logger\Entity\Log;
use RZ\Roadiz\CoreBundle\Preview\PreviewResolverInterface;
use RZ\Roadiz\CoreBundle\SearchEngine\NodeSourceSearchHandlerInterface;
use RZ\Roadiz\CoreBundle\SearchEngine\SearchResultsInterface;
Expand Down
3 changes: 1 addition & 2 deletions lib/RoadizCoreBundle/src/TwigExtension/LogExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
namespace RZ\Roadiz\CoreBundle\TwigExtension;

use RZ\Roadiz\CoreBundle\Entity\CustomForm;
use RZ\Roadiz\CoreBundle\Entity\CustomFormField;
use RZ\Roadiz\CoreBundle\Entity\Document;
use RZ\Roadiz\CoreBundle\Entity\Log;
use RZ\Roadiz\CoreBundle\Entity\Node;
use RZ\Roadiz\CoreBundle\Entity\NodesSources;
use RZ\Roadiz\CoreBundle\Entity\Setting;
use RZ\Roadiz\CoreBundle\Entity\Tag;
use RZ\Roadiz\CoreBundle\Entity\Translation;
use RZ\Roadiz\CoreBundle\Entity\User;
use RZ\Roadiz\CoreBundle\Logger\Entity\Log;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Security;
use Twig\Extension\AbstractExtension;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Themes\Rozier\Forms\NodeTagsType;
use Themes\Rozier\RozierApp;
use Themes\Rozier\Traits\NodesTrait;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

/**
* @package Themes\Rozier\AjaxControllers
*/
abstract class AjaxAbstractFieldsController extends AbstractAjaxController
{
private HandlerFactoryInterface $handlerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

/**
* @package Themes\Rozier\AjaxControllers
*/
class AjaxCustomFormFieldsController extends AjaxAbstractFieldsController
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Themes\Rozier\Models\CustomFormModel;

/**
* @package Themes\Rozier\AjaxControllers
*/
class AjaxCustomFormsExplorerController extends AbstractAjaxController
{
private UrlGeneratorInterface $urlGenerator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Themes\Rozier\Models\DocumentModel;

/**
* @package Themes\Rozier\AjaxControllers
*/
class AjaxDocumentsExplorerController extends AbstractAjaxController
{
private RendererInterface $renderer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
use Themes\Rozier\Explorer\SettingExplorerItem;
use Themes\Rozier\Explorer\UserExplorerItem;

/**
* @package Themes\Rozier\AjaxControllers
*/
class AjaxEntitiesExplorerController extends AbstractAjaxController
{
private RendererInterface $renderer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Exception\InvalidParameterException;

/**
* @package Themes\Rozier\AjaxControllers
*/
class AjaxExplorerProviderController extends AbstractAjaxController
{
private ContainerInterface $psrContainer;
Expand Down
3 changes: 0 additions & 3 deletions lib/Rozier/src/AjaxControllers/AjaxFolderTreeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
use Themes\Rozier\Widgets\FolderTreeWidget;
use Themes\Rozier\Widgets\TreeWidgetFactory;

/**
* @package Themes\Rozier\AjaxControllers
*/
class AjaxFolderTreeController extends AbstractAjaxController
{
private TreeWidgetFactory $treeWidgetFactory;
Expand Down
Loading

0 comments on commit 6d2583c

Please sign in to comment.