-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fixed Loggable behaviour, removed relationship between UserLogEn…
…try and User for future entity-manager separation. Add missing Doctrine mapping: ``` 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 ```
- Loading branch information
1 parent
0f29cc7
commit 96d180b
Showing
11 changed files
with
210 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RZ\Roadiz\Migrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
/** | ||
* Auto-generated Migration: Please modify to your needs! | ||
*/ | ||
final class Version20230712163432 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'Remove relation between UserLogEntry and User (to separate entity managers)'; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
// this up() migration is auto-generated, please modify it to your needs | ||
$this->addSql('ALTER TABLE user_log_entries DROP FOREIGN KEY FK_BC2E42C7A76ED395'); | ||
$this->addSql('DROP INDEX IDX_BC2E42C7A76ED395 ON user_log_entries'); | ||
$this->addSql('ALTER TABLE user_log_entries DROP user_id'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
// this down() migration is auto-generated, please modify it to your needs | ||
$this->addSql('ALTER TABLE user_log_entries ADD user_id INT DEFAULT NULL'); | ||
$this->addSql('ALTER TABLE user_log_entries ADD CONSTRAINT FK_BC2E42C7A76ED395 FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE NO ACTION ON DELETE SET NULL'); | ||
$this->addSql('CREATE INDEX IDX_BC2E42C7A76ED395 ON user_log_entries (user_id)'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 0 additions & 57 deletions
57
lib/RoadizCoreBundle/src/Doctrine/Loggable/UserLoggableListener.php
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
lib/RoadizCoreBundle/src/EventSubscriber/LoggableSubscriber.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RZ\Roadiz\CoreBundle\EventSubscriber; | ||
|
||
use Gedmo\Loggable\LoggableListener; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Symfony\Component\HttpKernel\Event\RequestEvent; | ||
use Symfony\Component\HttpKernel\HttpKernelInterface; | ||
use Symfony\Component\HttpKernel\KernelEvents; | ||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; | ||
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; | ||
|
||
final class LoggableSubscriber implements EventSubscriberInterface | ||
{ | ||
private LoggableListener $loggableListener; | ||
private ?TokenStorageInterface $tokenStorage; | ||
private ?AuthorizationCheckerInterface $authorizationChecker; | ||
|
||
public function __construct( | ||
LoggableListener $loggableListener, | ||
TokenStorageInterface $tokenStorage = null, | ||
AuthorizationCheckerInterface $authorizationChecker = null | ||
) { | ||
$this->loggableListener = $loggableListener; | ||
$this->tokenStorage = $tokenStorage; | ||
$this->authorizationChecker = $authorizationChecker; | ||
} | ||
|
||
public function onKernelRequest(RequestEvent $event): void | ||
{ | ||
if (HttpKernelInterface::MAIN_REQUEST !== $event->getRequestType()) { | ||
return; | ||
} | ||
|
||
if (null === $this->tokenStorage || null === $this->authorizationChecker) { | ||
return; | ||
} | ||
|
||
$token = $this->tokenStorage->getToken(); | ||
|
||
if (null !== $token && $this->authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED')) { | ||
$this->loggableListener->setUsername($token); | ||
} | ||
} | ||
|
||
public static function getSubscribedEvents(): array | ||
{ | ||
return array( | ||
KernelEvents::REQUEST => 'onKernelRequest', | ||
); | ||
} | ||
} |
Oops, something went wrong.