Skip to content
Merged
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
3 changes: 0 additions & 3 deletions app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ public function registerBundles(): array
new \ForkCMS\Bundle\InstallerBundle\ForkCMSInstallerBundle(),
new \ForkCMS\Bundle\CoreBundle\ForkCMSCoreBundle(),
new \Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new \SimpleBus\SymfonyBridge\SimpleBusCommandBusBundle(),
new \SimpleBus\SymfonyBridge\DoctrineOrmBridgeBundle(),
new \SimpleBus\SymfonyBridge\SimpleBusEventBusBundle(),
new \Backend\Modules\MediaLibrary\MediaLibrary(),
new \Backend\Modules\Mailmotor\Mailmotor(),
new \MailMotor\Bundle\MailMotorBundle\MailMotorMailMotorBundle(),
Expand Down
4 changes: 1 addition & 3 deletions app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@ services:
logger.public:
alias: logger
public: true
command_bus.public:
alias: command_bus
public: true
liip_imagine.cache.manager.public:
alias: liip_imagine.cache.manager
public: true
Expand All @@ -160,6 +157,7 @@ services:
# and caused some queries to break.
- [ execute, [ 'SET sql_mode = REPLACE(@@SESSION.sql_mode, "ONLY_FULL_GROUP_BY", "")'] ]
- [ setDebug, [ "%kernel.debug%" ]]
SpoonDatabase: '@database'
cache.filesystem.adapter:
class: League\Flysystem\Adapter\Local
arguments:
Expand Down
4 changes: 0 additions & 4 deletions app/config/doctrine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ doctrine:
alias: Common
prefix: Common\Doctrine\Entity

doctrine_orm_bridge:
entity_manager: default
connection: default

services:
fork.entity.create_schema:
class: Common\Doctrine\Entity\CreateSchema
Expand Down
2 changes: 0 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
"pimple/pimple": "^3.2",
"ramsey/uuid": "^4.0",
"ramsey/uuid-doctrine": "^2.0",
"simple-bus/doctrine-orm-bridge": "6.2.*",
"simple-bus/symfony-bridge": "~6.2",
"spoon/library": "^4.0",
"symfony/monolog-bundle": "^3.1",
"symfony/console": "^5.4",
Expand Down
5 changes: 4 additions & 1 deletion src/Backend/Core/Ajax/UpdateSequence.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Backend\Core\Engine\Base\AjaxAction as BackendBaseAJAXAction;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Messenger\MessageBusInterface;

class UpdateSequence extends BackendBaseAJAXAction
{
Expand All @@ -27,7 +28,9 @@ public function execute(): void
$ids = (array) explode(',', rtrim($newIdSequence, ','));

// Handle the Categories ReSequence
$this->get('command_bus')->handle(new $this->handlerClass($ids));
/** @var MessageBusInterface $messageBus */
$messageBus = $this->get('messenger.default_bus');
$messageBus->dispatch(new $this->handlerClass($ids));

// success output
$this->output(Response::HTTP_OK, null, 'sequence updated');
Expand Down
5 changes: 4 additions & 1 deletion src/Backend/Modules/ContentBlocks/Actions/Add.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Backend\Modules\ContentBlocks\Domain\ContentBlock\ContentBlockType;
use Backend\Modules\ContentBlocks\Domain\ContentBlock\Event\ContentBlockCreated;
use Symfony\Component\Form\Form;
use Symfony\Component\Messenger\MessageBusInterface;

/**
* This is the add-action, it will display a form to create a new item
Expand Down Expand Up @@ -52,7 +53,9 @@ private function createContentBlock(Form $form): CreateContentBlock
$createContentBlock->userId = Authentication::getUser()->getUserId();

// The command bus will handle the saving of the content block in the database.
$this->get('command_bus')->handle($createContentBlock);
/** @var MessageBusInterface $messageBus */
$messageBus = $this->get('messenger.default_bus');
$messageBus->dispatch($createContentBlock);

return $createContentBlock;
}
Expand Down
5 changes: 4 additions & 1 deletion src/Backend/Modules/ContentBlocks/Actions/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Backend\Modules\ContentBlocks\Domain\ContentBlock\ContentBlock;
use Backend\Modules\ContentBlocks\Domain\ContentBlock\Event\ContentBlockDeleted;
use Backend\Modules\ContentBlocks\Domain\ContentBlock\Exception\ContentBlockNotFound;
use Symfony\Component\Messenger\MessageBusInterface;

/**
* This is the delete-action, it will delete an item.
Expand All @@ -30,7 +31,9 @@ public function execute(): void
$contentBlock = $this->getContentBlock((int) $deleteFormData['id']);

// The command bus will handle the saving of the content block in the database.
$this->get('command_bus')->handle(new DeleteContentBlock($contentBlock));
/** @var MessageBusInterface $messageBus */
$messageBus = $this->get('messenger.default_bus');
$messageBus->dispatch(new DeleteContentBlock($contentBlock));

$this->get('event_dispatcher')->dispatch(
new ContentBlockDeleted($contentBlock)
Expand Down
5 changes: 4 additions & 1 deletion src/Backend/Modules/ContentBlocks/Actions/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Backend\Modules\ContentBlocks\Domain\ContentBlock\Event\ContentBlockUpdated;
use Backend\Modules\ContentBlocks\Domain\ContentBlock\Exception\ContentBlockNotFound;
use Symfony\Component\Form\Form;
use Symfony\Component\Messenger\MessageBusInterface;

/**
* This is the edit-action, it will display a form to edit an existing item
Expand Down Expand Up @@ -126,7 +127,9 @@ private function updateContentBlock(Form $form): UpdateContentBlock
$updateContentBlock->userId = Authentication::getUser()->getUserId();

// The command bus will handle the saving of the content block in the database.
$this->get('command_bus')->handle($updateContentBlock);
/** @var MessageBusInterface $messageBus */
$messageBus = $this->get('messenger.default_bus');
$messageBus->dispatch($updateContentBlock);

return $updateContentBlock;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,13 @@

final class CopyContentBlocksToOtherLocale
{
/** @var Locale */
public $fromLocale;
/** This is used to be able to convert the old ids to the new ones if used in other places */
public array $extraIdMap = [];

/** @var array this is used to be able to convert the old ids to the new ones if used in other places */
public $extraIdMap;

public function __construct(public Locale $toLocale, ?Locale $fromLocale = null)
public function __construct(public Locale $toLocale, public ?Locale $fromLocale = null)
{
if ($fromLocale === null) {
$fromLocale = Locale::workingLocale();
if ($this->fromLocale === null) {
$this->fromLocale = Locale::workingLocale();
}
$this->fromLocale = $fromLocale;
$this->extraIdMap = [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@
use Backend\Modules\ContentBlocks\Domain\ContentBlock\ContentBlockRepository;
use Backend\Modules\ContentBlocks\Domain\ContentBlock\Status;
use Common\ModuleExtraType;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;

#[AsMessageHandler]
final readonly class CopyContentBlocksToOtherLocaleHandler
{
public function __construct(private ContentBlockRepository $contentBlockRepository)
{
public function __construct(
private ContentBlockRepository $contentBlockRepository,
private EntityManagerInterface $entityManager,
) {
}

public function handle(CopyContentBlocksToOtherLocale $copyContentBlocksToOtherLocale): void
public function __invoke(CopyContentBlocksToOtherLocale $copyContentBlocksToOtherLocale): void
{
$contentBlocksToCopy = $this->getContentBlocksToCopy($copyContentBlocksToOtherLocale->fromLocale);
$id = $this->contentBlockRepository->getNextIdForLanguage($copyContentBlocksToOtherLocale->toLocale);
Expand All @@ -36,6 +41,8 @@ function (ContentBlock $contentBlock) use ($copyContentBlocksToOtherLocale, &$id
},
$contentBlocksToCopy
);

$this->entityManager->flush();
}

private function getContentBlocksToCopy(Locale $locale): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@
use Backend\Modules\ContentBlocks\Domain\ContentBlock\ContentBlock;
use Backend\Modules\ContentBlocks\Domain\ContentBlock\ContentBlockRepository;
use Common\ModuleExtraType;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;

#[AsMessageHandler]
final readonly class CreateContentBlockHandler
{
public function __construct(private ContentBlockRepository $contentBlockRepository)
{
public function __construct(
private ContentBlockRepository $contentBlockRepository,
private EntityManagerInterface $entityManager,
) {
}

public function handle(CreateContentBlock $createContentBlock): void
public function __invoke(CreateContentBlock $createContentBlock): void
{
$createContentBlock->extraId = $this->getNewExtraId();
$createContentBlock->id = $this->contentBlockRepository->getNextIdForLanguage($createContentBlock->locale);
Expand All @@ -22,6 +27,8 @@ public function handle(CreateContentBlock $createContentBlock): void
$this->contentBlockRepository->add($contentBlock);

$createContentBlock->setContentBlockEntity($contentBlock);

$this->entityManager->flush();
}

private function getNewExtraId(): int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,28 @@
namespace Backend\Modules\ContentBlocks\Domain\ContentBlock\Command;

use Backend\Core\Engine\Model;
use Backend\Modules\ContentBlocks\Domain\ContentBlock\ContentBlock;
use Backend\Modules\ContentBlocks\Domain\ContentBlock\ContentBlockRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;

#[AsMessageHandler]
final readonly class DeleteContentBlockHandler
{
public function __construct(private ContentBlockRepository $contentBlockRepository)
{
public function __construct(
private ContentBlockRepository $contentBlockRepository,
private EntityManagerInterface $entityManager,
) {
}

public function handle(DeleteContentBlock $deleteContentBlock): void
public function __invoke(DeleteContentBlock $deleteContentBlock): void
{
$this->contentBlockRepository->removeByIdAndLocale(
$deleteContentBlock->contentBlock->getId(),
$deleteContentBlock->contentBlock->getLocale()
);

Model::deleteExtraById($deleteContentBlock->contentBlock->getExtraId());

$this->entityManager->flush();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,25 @@

use Backend\Modules\ContentBlocks\Domain\ContentBlock\ContentBlock;
use Backend\Modules\ContentBlocks\Domain\ContentBlock\ContentBlockRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;

#[AsMessageHandler]
final readonly class UpdateContentBlockHandler
{
public function __construct(private ContentBlockRepository $contentBlockRepository)
{
public function __construct(
private ContentBlockRepository $contentBlockRepository,
private EntityManagerInterface $entityManager,
) {
}

public function handle(UpdateContentBlock $updateContentBlock): void
public function __invoke(UpdateContentBlock $updateContentBlock): void
{
$contentBlock = ContentBlock::fromDataTransferObject($updateContentBlock);
$this->contentBlockRepository->add($contentBlock);

$updateContentBlock->setContentBlockEntity($contentBlock);

$this->entityManager->flush();
}
}
35 changes: 7 additions & 28 deletions src/Backend/Modules/ContentBlocks/Resources/config/commands.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,11 @@
services:
content_blocks.handler.create_content_block:
class: Backend\Modules\ContentBlocks\Domain\ContentBlock\Command\CreateContentBlockHandler
_defaults:
autowire: true
autoconfigure: true
public: true
arguments:
- "@content_blocks.repository.content_block"
tags:
- { name: command_handler, handles: Backend\Modules\ContentBlocks\Domain\ContentBlock\Command\CreateContentBlock }

content_blocks.handler.update_content_block:
class: Backend\Modules\ContentBlocks\Domain\ContentBlock\Command\UpdateContentBlockHandler
public: true
arguments:
- "@content_blocks.repository.content_block"
tags:
- { name: command_handler, handles: Backend\Modules\ContentBlocks\Domain\ContentBlock\Command\UpdateContentBlock }

content_blocks.handler.delete_content_block:
class: Backend\Modules\ContentBlocks\Domain\ContentBlock\Command\DeleteContentBlockHandler
public: true
arguments:
- "@content_blocks.repository.content_block"
tags:
- { name: command_handler, handles: Backend\Modules\ContentBlocks\Domain\ContentBlock\Command\DeleteContentBlock }
Backend\Modules\ContentBlocks\Domain\ContentBlock\Command\CreateContentBlockHandler:
Backend\Modules\ContentBlocks\Domain\ContentBlock\Command\UpdateContentBlockHandler:
Backend\Modules\ContentBlocks\Domain\ContentBlock\Command\DeleteContentBlockHandler:

content_blocks.handler.copy_content_blocks_to_other_locale:
class: Backend\Modules\ContentBlocks\Domain\ContentBlock\Command\CopyContentBlocksToOtherLocaleHandler
public: true
arguments:
- "@content_blocks.repository.content_block"
tags:
- { name: command_handler, handles: Backend\Modules\ContentBlocks\Domain\ContentBlock\Command\CopyContentBlocksToOtherLocale }
Backend\Modules\ContentBlocks\Domain\ContentBlock\Command\CopyContentBlocksToOtherLocaleHandler:
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ services:
factory: ["@doctrine.orm.entity_manager", getRepository]
arguments:
- Backend\Modules\ContentBlocks\Domain\ContentBlock\ContentBlock

Backend\Modules\ContentBlocks\Domain\ContentBlock\ContentBlockRepository: '@content_blocks.repository.content_block'
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,13 @@

final class CopyFormWidgetsToOtherLocale
{
/** @var Locale */
public $fromLocale;
/** This is used to be able to convert the old ids to the new ones if used in other places */
public array $extraIdMap = [];

/** @var array this is used to be able to convert the old ids to the new ones if used in other places */
public $extraIdMap;

public function __construct(public Locale $toLocale, ?Locale $fromLocale = null)
public function __construct(public Locale $toLocale, public ?Locale $fromLocale = null)
{
if ($fromLocale === null) {
$fromLocale = Locale::workingLocale();
if ($this->fromLocale === null) {
$this->fromLocale = Locale::workingLocale();
}
$this->fromLocale = $fromLocale;
$this->extraIdMap = [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
use Backend\Core\Engine\Model as BackendModel;
use Common\ModuleExtraType;
use SpoonDatabase;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;

#[AsMessageHandler]
final readonly class CopyFormWidgetsToOtherLocaleHandler
{
public function __construct(private SpoonDatabase $database)
{
}

public function handle(CopyFormWidgetsToOtherLocale $command): void
public function __invoke(CopyFormWidgetsToOtherLocale $command): void
{
$currentWidgets = (array) $this->database->getRecords(
'SELECT * FROM modules_extras WHERE module = ? AND type = ? AND action = ?',
Expand Down
11 changes: 5 additions & 6 deletions src/Backend/Modules/FormBuilder/Resources/config/commands.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
services:
form.handler.copy_widgets_to_other_locale:
class: Backend\Modules\FormBuilder\Command\CopyFormWidgetsToOtherLocaleHandler
_defaults:
autowire: true
autoconfigure: true
public: true
arguments:
- "@database"
tags:
- { name: command_handler, handles: Backend\Modules\FormBuilder\Command\CopyFormWidgetsToOtherLocale }

Backend\Modules\FormBuilder\Command\CopyFormWidgetsToOtherLocaleHandler:
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@

final class CopyLocationWidgetsToOtherLocale
{
/** @var array this is used to be able to convert the old ids to the new ones if used in other places */
/** This is used to be able to convert the old ids to the new ones if used in other places */
public array $extraIdMap = [];

public function __construct(public Locale $toLocale, public ?Locale $fromLocale = null)
{
if ($fromLocale === null) {
$fromLocale = Locale::workingLocale();
if ($this->fromLocale === null) {
$this->fromLocale = Locale::workingLocale();
}
$this->fromLocale = $fromLocale;
}
}
Loading
Loading